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