1 | <?php |
||
24 | trait HostnameInfoTrait |
||
25 | { |
||
26 | /** |
||
27 | * Pdp Parser |
||
28 | * |
||
29 | * @var Parser |
||
30 | */ |
||
31 | protected static $pdpParser; |
||
32 | |||
33 | /** |
||
34 | * Hostname public info |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $hostnameInfo = [ |
||
39 | 'isPublicSuffixValid' => false, |
||
40 | 'publicSuffix' => null, |
||
41 | 'registerableDomain' => null, |
||
42 | 'subdomain' => null, |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * is the Hostname Info loaded |
||
47 | * |
||
48 | * @var bool |
||
49 | */ |
||
50 | protected $hostnameInfoLoaded = false; |
||
51 | |||
52 | /** |
||
53 | * Return the host public suffix |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | 21 | public function getPublicSuffix() |
|
58 | { |
||
59 | 21 | return $this->getHostnameInfo('publicSuffix'); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Return the host registrable domain |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | 24 | public function getRegisterableDomain() |
|
68 | { |
||
69 | 24 | return $this->getHostnameInfo('registerableDomain'); |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Return the hostname subdomain |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | 21 | public function getSubdomain() |
|
78 | { |
||
79 | 21 | return $this->getHostnameInfo('subdomain'); |
|
80 | } |
||
81 | |||
82 | /** |
||
83 | * Tell whether the current public suffix is valid |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | 21 | public function isPublicSuffixValid() |
|
88 | { |
||
89 | 21 | return $this->getHostnameInfo('isPublicSuffixValid'); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Load the hostname info |
||
94 | * |
||
95 | * @param string $key hostname info key |
||
96 | * |
||
97 | * @return mixed |
||
98 | */ |
||
99 | 24 | protected function getHostnameInfo($key) |
|
104 | |||
105 | /** |
||
106 | * parse and save the Hostname information from the Parser |
||
107 | */ |
||
108 | 24 | protected function loadHostnameInfo() |
|
127 | |||
128 | /** |
||
129 | * Returns the instance string representation; If the |
||
130 | * instance is not defined an empty string is returned |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | abstract public function __toString(); |
||
135 | |||
136 | /** |
||
137 | * Returns whether or not the host is an IP address |
||
138 | * |
||
139 | * @return bool |
||
140 | */ |
||
141 | abstract public function isIp(); |
||
142 | |||
143 | /** |
||
144 | * Returns whether or not the host is a full qualified domain name |
||
145 | * |
||
146 | * @return bool |
||
147 | */ |
||
148 | abstract public function isAbsolute(); |
||
149 | |||
150 | /** |
||
151 | * Initialize and access the Parser object |
||
152 | * |
||
153 | * @return Parser |
||
154 | */ |
||
155 | 18 | protected function getPdpParser() |
|
163 | } |
||
164 |