diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7e6459 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +composer.lock +/vendor +/.buildpath +/.project +/.settings diff --git a/README.md b/README.md index 247e288..72e25b4 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,27 @@ if ($domain->isAvailable()) { echo "Domain is registered\n"; } -``` \ No newline at end of file +``` + +A more complete example: + +```php + +getMessage()."\n"); +} + +if ($domain->isAvailable()) { + echo "Domain is available\n"; +} else { + echo "Domain is registered\n"; +} + +``` diff --git a/examples/usage-example2.php b/examples/usage-example2.php new file mode 100644 index 0000000..b1c3256 --- /dev/null +++ b/examples/usage-example2.php @@ -0,0 +1,16 @@ +getMessage()."\n"); +} + +if ($domain->isAvailable()) { + echo "Domain is available\n"; +} else { + echo "Domain is registered\n"; +} diff --git a/src/Phois/Whois/Whois.php b/src/Phois/Whois/Whois.php index 2740c4f..ae9db26 100644 --- a/src/Phois/Whois/Whois.php +++ b/src/Phois/Whois/Whois.php @@ -11,6 +11,8 @@ class Whois private $subDomain; private $servers; + + private $whoisInfo; /** * @param string $domain full domain name (without trailing dot) @@ -29,10 +31,19 @@ public function __construct($domain) throw new \InvalidArgumentException("Invalid $domain syntax"); // setup whois servers array from json file $this->servers = json_decode(file_get_contents( __DIR__.'/whois.servers.json' ), true); + + if (!$this->isValid()) + throw new \InvalidArgumentException("Domain name isn't valid!"); } - + + /** + * @param string, domain whois information + */ public function info() { + if ($this->whoisInfo != '') + return $this->whoisInfo; + if ($this->isValid()) { $whois_server = $this->servers[$this->TLDs][0]; @@ -116,12 +127,13 @@ public function info() $string_encoding = mb_detect_encoding($string, "UTF-8, ISO-8859-1, ISO-8859-15", true); $string_utf8 = mb_convert_encoding($string, "UTF-8", $string_encoding); - return htmlspecialchars($string_utf8, ENT_COMPAT, "UTF-8", true); + $this->whoisInfo = htmlspecialchars($string_utf8, ENT_COMPAT, "UTF-8", true); + return $this->whoisInfo; } else { return "No whois server for this tld in list!"; } } else { - return "Domainname isn't valid!"; + return "Domain name isn't valid!"; } } @@ -153,10 +165,16 @@ public function getSubDomain() { return $this->subDomain; } - + + /** + * @return boolean, true for domain avaliable, false for domain registered + */ public function isAvailable() { - $whois_string = $this->info(); + if ($this->whoisInfo == '') + $whois_string = $this->info(); + else + $whois_string = $this->whoisInfo; $not_found_string = ''; if (isset($this->servers[$this->TLDs][1])) { $not_found_string = $this->servers[$this->TLDs][1]; diff --git a/src/Phois/Whois/whois.servers.json b/src/Phois/Whois/whois.servers.json index 50a42a4..987502c 100644 --- a/src/Phois/Whois/whois.servers.json +++ b/src/Phois/Whois/whois.servers.json @@ -1491,6 +1491,34 @@ "whois.nic.ir", "no entries found" ], + "co.ir": [ + "whois.nic.ir", + "no entries found" + ], + "ac.ir": [ + "whois.nic.ir", + "no entries found" + ], + "sch.ir": [ + "whois.nic.ir", + "no entries found" + ], + "id.ir": [ + "whois.nic.ir", + "no entries found" + ], + "gov.ir": [ + "whois.nic.ir", + "no entries found" + ], + "org.ir": [ + "whois.nic.ir", + "no entries found" + ], + "net.ir": [ + "whois.nic.ir", + "no entries found" + ], "ru": [ "whois.ripn.net", "No entries found"