1 | <?php |
||
24 | class Host extends AbstractHierarchicalComponent implements HostInterface |
||
25 | { |
||
26 | use HostIpTrait; |
||
27 | |||
28 | use HostnameInfoTrait; |
||
29 | |||
30 | use HostnameTrait; |
||
31 | |||
32 | /** |
||
33 | * HierarchicalComponent delimiter |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected static $separator = '.'; |
||
38 | |||
39 | /** |
||
40 | * Host literal representation |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $host; |
||
45 | |||
46 | /** |
||
47 | * New instance |
||
48 | * |
||
49 | * @param null|string $host |
||
50 | */ |
||
51 | 654 | public function __construct($host = null) |
|
59 | |||
60 | /** |
||
61 | * Returns whether or not the host is an IDN |
||
62 | * |
||
63 | 538 | * @return bool |
|
64 | */ |
||
65 | 538 | public function isIdn() |
|
69 | |||
70 | /** |
||
71 | 14 | * Returns whether or not the host is an IP address |
|
72 | * |
||
73 | 14 | * @return bool |
|
74 | */ |
||
75 | public function isIp() |
||
79 | |||
80 | /** |
||
81 | * Returns whether or not the host is an IPv4 address |
||
82 | * |
||
83 | 576 | * @return bool |
|
84 | */ |
||
85 | 576 | public function isIpv4() |
|
89 | |||
90 | 518 | /** |
|
91 | * Returns whether or not the host is an IPv6 address |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | public function isIpv6() |
||
99 | 2 | ||
100 | /** |
||
101 | * Returns whether or not the host has a ZoneIdentifier |
||
102 | 2 | * |
|
103 | * @return bool |
||
104 | * |
||
105 | * @see http://tools.ietf.org/html/rfc6874#section-4 |
||
106 | */ |
||
107 | public function hasZoneIdentifier() |
||
111 | |||
112 | /** |
||
113 | * Host literal setter |
||
114 | */ |
||
115 | protected function setLiteral() |
||
119 | 136 | ||
120 | /** |
||
121 | * Returns the instance literal representation |
||
122 | 516 | * without encoding |
|
123 | 50 | * |
|
124 | * @return string |
||
125 | */ |
||
126 | 470 | public function getLiteral() |
|
130 | |||
131 | /** |
||
132 | 70 | * validate the submitted data |
|
133 | * |
||
134 | 70 | * @param string $str |
|
135 | 22 | * |
|
136 | * @return array |
||
137 | */ |
||
138 | 50 | protected function validate($str) |
|
147 | 50 | ||
148 | /** |
||
149 | 50 | * Retrieves a single host label. |
|
150 | 46 | * |
|
151 | * Retrieves a single host label. If the label offset has not been set, |
||
152 | * returns the default value provided. |
||
153 | 44 | * |
|
154 | * @param string $offset the label offset |
||
155 | * @param mixed $default Default value to return if the offset does not exist. |
||
156 | * |
||
157 | * @return mixed |
||
158 | */ |
||
159 | 496 | public function getLabel($offset, $default = null) |
|
160 | { |
||
161 | 496 | if (isset($this->data[$offset])) { |
|
162 | 488 | return $this->isIdn ? $this->data[$offset] : idn_to_ascii($this->data[$offset]); |
|
163 | 24 | } |
|
164 | |||
165 | return $default; |
||
166 | 472 | } |
|
167 | |||
168 | /** |
||
169 | * Returns an array representation of the host |
||
170 | * |
||
171 | * @return array |
||
172 | 12 | */ |
|
173 | public function toArray() |
||
177 | |||
178 | 6 | /** |
|
179 | * Returns the instance string representation; If the |
||
180 | * instance is not defined an empty string is returned |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | public function __toString() |
||
196 | |||
197 | /** |
||
198 | * Returns a host in his punycode encoded form |
||
199 | * |
||
200 | * This method MUST retain the state of the current instance, and return |
||
201 | * an instance with the host transcoded using to ascii the RFC 3492 rules |
||
202 | 508 | * |
|
203 | * @see http://tools.ietf.org/html/rfc3492 |
||
204 | 508 | * |
|
205 | 508 | * @return static |
|
206 | 28 | */ |
|
207 | 28 | public function toAscii() |
|
218 | 40 | ||
219 | 40 | /** |
|
220 | 40 | * Returns a host in his IDN form |
|
221 | 40 | * |
|
222 | * This method MUST retain the state of the current instance, and return |
||
223 | * an instance with the host in its IDN form using RFC 3492 rules |
||
224 | * |
||
225 | * @see http://tools.ietf.org/html/rfc3492 |
||
226 | * |
||
227 | * @return static |
||
228 | */ |
||
229 | public function toUnicode() |
||
237 | |||
238 | /** |
||
239 | * @inheritdoc |
||
240 | */ |
||
241 | protected static function formatComponentString($data, $type) |
||
250 | |||
251 | /** |
||
252 | * Return an host without its zone identifier according to RFC6874 |
||
253 | * |
||
254 | * This method MUST retain the state of the current instance, and return |
||
255 | * an instance without the host zone identifier according to RFC6874 |
||
256 | * |
||
257 | * @see http://tools.ietf.org/html/rfc6874#section-4 |
||
258 | * |
||
259 | * @return static |
||
260 | */ |
||
261 | public function withoutZoneIdentifier() |
||
269 | |||
270 | /** |
||
271 | * Validated the Host Label Count |
||
272 | * |
||
273 | * @param array $labels Host labels |
||
274 | * |
||
275 | * @throws InvalidArgumentException If the validation fails |
||
276 | */ |
||
277 | protected function assertLabelsCount(array $labels) |
||
283 | |||
284 | /** |
||
285 | * set the FQDN property |
||
286 | * |
||
287 | * @param string $str |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | protected function setIsAbsolute($str) |
||
301 | |||
302 | /** |
||
303 | * @inheritdoc |
||
304 | */ |
||
305 | public function append($component) |
||
312 | |||
313 | /** |
||
314 | * @inheritdoc |
||
315 | */ |
||
316 | public static function __set_state(array $properties) |
||
325 | } |
||
326 |