1
|
|
|
<?php |
2
|
|
|
namespace MallardDuck\Whois\WhoisServerList; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Whois Server List Locator Class |
6
|
|
|
* |
7
|
|
|
* This class loads a TLD whois list and allows for easy look up. |
8
|
|
|
* |
9
|
|
|
* @author mallardduck <[email protected]> |
10
|
|
|
* |
11
|
|
|
* @copyright lucidinternets.com 2018 |
12
|
|
|
* |
13
|
|
|
* @version 1.0.0 |
14
|
|
|
*/ |
15
|
|
|
abstract class AbstractLocator |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The status of loading the whois server list. |
20
|
|
|
* |
21
|
|
|
* @var bool |
22
|
|
|
*/ |
23
|
|
|
private $loadStatus = false; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The path where the tld json file exists. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $whoisListPath; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* A collection of the TLDs and whois server list. |
34
|
|
|
* |
35
|
|
|
* @var \Tightenco\Collect\Support\Collection |
36
|
|
|
*/ |
37
|
|
|
protected $whoisCollection; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The results of the last looked up domain. |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
protected $lastMatch; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Build the TLD Whois Server Locator class. |
48
|
|
|
*/ |
49
|
165 |
|
public function __construct() |
50
|
|
|
{ |
51
|
165 |
|
$fileData = file_get_contents($this->whoisListPath); |
52
|
165 |
|
$tldData = json_decode($fileData); |
53
|
165 |
|
if (null !== $tldData && json_last_error() === JSON_ERROR_NONE) { |
54
|
165 |
|
$this->loadStatus = true; |
55
|
|
|
} |
56
|
165 |
|
$this->whoisCollection = collect((array) $tldData); |
57
|
165 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns the TLD list load status. |
61
|
|
|
* |
62
|
|
|
* @return bool The class status of loading the list and decoding the json. |
63
|
|
|
*/ |
64
|
3 |
|
public function getLoadStatus() |
65
|
|
|
{ |
66
|
3 |
|
return $this->loadStatus; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Gets and returns the last match looked up. |
71
|
|
|
* |
72
|
|
|
* @return array The results of the last looked up domain. |
73
|
|
|
*/ |
74
|
3 |
|
public function getLastMatch() |
75
|
|
|
{ |
76
|
3 |
|
return $this->lastMatch; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Finds and returns the last match looked up. |
81
|
|
|
* |
82
|
|
|
* @param string $domain Either an ID or a username. |
83
|
|
|
* |
84
|
|
|
* @return self Returns the same instance for fluent usage. |
85
|
|
|
*/ |
86
|
|
|
abstract public function findWhoisServer($domain); |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the Whois server of the domain provided, or previously found domain. |
90
|
|
|
* |
91
|
|
|
* @param string $domain The domain being looked up via whois. |
92
|
|
|
* |
93
|
|
|
* @return string Returns the domain name of the whois server. |
94
|
|
|
*/ |
95
|
|
|
abstract public function getWhoisServer($domain = ''); |
96
|
|
|
} |
97
|
|
|
|