From c709e5767763c352e8774a36baafee830b78af83 Mon Sep 17 00:00:00 2001 From: NabiKAZ Date: Wed, 11 Mar 2015 01:45:59 +0330 Subject: [PATCH 1/3] Fixes #38: add *.ir ccSLD domains Signed-off-by: NabiKAZ --- src/Phois/Whois/whois.servers.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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" From 76a6f3733ce9fb78f247db8b64748a7bc77ae33f Mon Sep 17 00:00:00 2001 From: NabiKAZ Date: Wed, 11 Mar 2015 04:52:43 +0330 Subject: [PATCH 2/3] Fixes #32: method isAvailable() returns TRUE when extension doesn't exist Signed-off-by: NabiKAZ --- .gitignore | 5 +++++ README.md | 25 ++++++++++++++++++++++++- examples/usage-example2.php | 16 ++++++++++++++++ src/Phois/Whois/Whois.php | 15 ++++++++++++--- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 examples/usage-example2.php 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..a6ae1be 100644 --- a/src/Phois/Whois/Whois.php +++ b/src/Phois/Whois/Whois.php @@ -29,8 +29,14 @@ 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->isValid()) { @@ -121,7 +127,7 @@ public function info() return "No whois server for this tld in list!"; } } else { - return "Domainname isn't valid!"; + return "Domain name isn't valid!"; } } @@ -153,7 +159,10 @@ public function getSubDomain() { return $this->subDomain; } - + + /** + * @return boolean, true for domain avaliable, false for domain registered + */ public function isAvailable() { $whois_string = $this->info(); From cb2d89ffc531fc2e3fcad9b854cde40551ecae36 Mon Sep 17 00:00:00 2001 From: NabiKAZ Date: Wed, 11 Mar 2015 06:12:32 +0330 Subject: [PATCH 3/3] Fixes #28: Don't make two queries Signed-off-by: NabiKAZ --- src/Phois/Whois/Whois.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Phois/Whois/Whois.php b/src/Phois/Whois/Whois.php index a6ae1be..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) @@ -39,6 +41,9 @@ public function __construct($domain) */ public function info() { + if ($this->whoisInfo != '') + return $this->whoisInfo; + if ($this->isValid()) { $whois_server = $this->servers[$this->TLDs][0]; @@ -122,7 +127,8 @@ 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!"; } @@ -165,7 +171,10 @@ public function getSubDomain() */ 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];