@@ -37,42 +37,42 @@ discard block |
||
37 | 37 | const TYPE_PHONE = 'phone'; |
38 | 38 | const TYPE_URL = 'url'; |
39 | 39 | |
40 | - /** |
|
41 | - * The original URL that was passed to the constructor. |
|
42 | - * @var string |
|
43 | - */ |
|
40 | + /** |
|
41 | + * The original URL that was passed to the constructor. |
|
42 | + * @var string |
|
43 | + */ |
|
44 | 44 | protected $rawURL; |
45 | 45 | |
46 | - /** |
|
47 | - * @var array |
|
48 | - */ |
|
46 | + /** |
|
47 | + * @var array |
|
48 | + */ |
|
49 | 49 | protected $info; |
50 | 50 | |
51 | - /** |
|
52 | - * @var string[] |
|
53 | - */ |
|
51 | + /** |
|
52 | + * @var string[] |
|
53 | + */ |
|
54 | 54 | protected $excludedParams = array(); |
55 | 55 | |
56 | - /** |
|
57 | - * @var bool |
|
58 | - * @see URLInfo::setParamExclusion() |
|
59 | - */ |
|
56 | + /** |
|
57 | + * @var bool |
|
58 | + * @see URLInfo::setParamExclusion() |
|
59 | + */ |
|
60 | 60 | protected $paramExclusion = false; |
61 | 61 | |
62 | - /** |
|
63 | - * @var array |
|
64 | - * @see URLInfo::getTypeLabel() |
|
65 | - */ |
|
62 | + /** |
|
63 | + * @var array |
|
64 | + * @see URLInfo::getTypeLabel() |
|
65 | + */ |
|
66 | 66 | protected static $typeLabels; |
67 | 67 | |
68 | - /** |
|
69 | - * @var bool |
|
70 | - */ |
|
68 | + /** |
|
69 | + * @var bool |
|
70 | + */ |
|
71 | 71 | protected $highlightExcluded = false; |
72 | 72 | |
73 | - /** |
|
74 | - * @var array |
|
75 | - */ |
|
73 | + /** |
|
74 | + * @var array |
|
75 | + */ |
|
76 | 76 | protected $infoKeys = array( |
77 | 77 | 'scheme', |
78 | 78 | 'host', |
@@ -84,19 +84,19 @@ discard block |
||
84 | 84 | 'fragment' |
85 | 85 | ); |
86 | 86 | |
87 | - /** |
|
88 | - * @var string |
|
89 | - */ |
|
87 | + /** |
|
88 | + * @var string |
|
89 | + */ |
|
90 | 90 | protected $url; |
91 | 91 | |
92 | - /** |
|
93 | - * @var URLInfo_Parser |
|
94 | - */ |
|
92 | + /** |
|
93 | + * @var URLInfo_Parser |
|
94 | + */ |
|
95 | 95 | protected $parser; |
96 | 96 | |
97 | - /** |
|
98 | - * @var URLInfo_Normalizer |
|
99 | - */ |
|
97 | + /** |
|
98 | + * @var URLInfo_Normalizer |
|
99 | + */ |
|
100 | 100 | protected $normalizer; |
101 | 101 | |
102 | 102 | public function __construct(string $url) |
@@ -108,13 +108,13 @@ discard block |
||
108 | 108 | $this->info = $this->parser->getInfo(); |
109 | 109 | } |
110 | 110 | |
111 | - /** |
|
112 | - * Filters an URL: removes control characters and the |
|
113 | - * like to have a clean URL to work with. |
|
114 | - * |
|
115 | - * @param string $url |
|
116 | - * @return string |
|
117 | - */ |
|
111 | + /** |
|
112 | + * Filters an URL: removes control characters and the |
|
113 | + * like to have a clean URL to work with. |
|
114 | + * |
|
115 | + * @param string $url |
|
116 | + * @return string |
|
117 | + */ |
|
118 | 118 | public static function filterURL(string $url) |
119 | 119 | { |
120 | 120 | return URLInfo_Filter::filter($url); |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | return $this->info['type'] === self::TYPE_PHONE; |
145 | 145 | } |
146 | 146 | |
147 | - /** |
|
148 | - * Whether the URL is a regular URL, not one of the |
|
149 | - * other types like a phone number or email address. |
|
150 | - * |
|
151 | - * @return bool |
|
152 | - */ |
|
147 | + /** |
|
148 | + * Whether the URL is a regular URL, not one of the |
|
149 | + * other types like a phone number or email address. |
|
150 | + * |
|
151 | + * @return bool |
|
152 | + */ |
|
153 | 153 | public function isURL() : bool |
154 | 154 | { |
155 | 155 | $host = $this->getHost(); |
@@ -161,20 +161,20 @@ discard block |
||
161 | 161 | return $this->parser->isValid(); |
162 | 162 | } |
163 | 163 | |
164 | - /** |
|
165 | - * Retrieves the host name, or an empty string if none is present. |
|
166 | - * |
|
167 | - * @return string |
|
168 | - */ |
|
164 | + /** |
|
165 | + * Retrieves the host name, or an empty string if none is present. |
|
166 | + * |
|
167 | + * @return string |
|
168 | + */ |
|
169 | 169 | public function getHost() : string |
170 | 170 | { |
171 | 171 | return $this->getInfoKey('host'); |
172 | 172 | } |
173 | 173 | |
174 | - /** |
|
175 | - * Retrieves the path, or an empty string if none is present. |
|
176 | - * @return string |
|
177 | - */ |
|
174 | + /** |
|
175 | + * Retrieves the path, or an empty string if none is present. |
|
176 | + * @return string |
|
177 | + */ |
|
178 | 178 | public function getPath() : string |
179 | 179 | { |
180 | 180 | return $this->getInfoKey('path'); |
@@ -190,10 +190,10 @@ discard block |
||
190 | 190 | return $this->getInfoKey('scheme'); |
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
194 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
195 | - * @return int |
|
196 | - */ |
|
193 | + /** |
|
194 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
195 | + * @return int |
|
196 | + */ |
|
197 | 197 | public function getPort() : int |
198 | 198 | { |
199 | 199 | $port = $this->getInfoKey('port'); |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | return -1; |
206 | 206 | } |
207 | 207 | |
208 | - /** |
|
209 | - * Retrieves the raw query string, or an empty string if none is present. |
|
210 | - * |
|
211 | - * @return string |
|
212 | - * |
|
213 | - * @see URLInfo::getParams() |
|
214 | - */ |
|
208 | + /** |
|
209 | + * Retrieves the raw query string, or an empty string if none is present. |
|
210 | + * |
|
211 | + * @return string |
|
212 | + * |
|
213 | + * @see URLInfo::getParams() |
|
214 | + */ |
|
215 | 215 | public function getQuery() : string |
216 | 216 | { |
217 | 217 | return $this->getInfoKey('query'); |
@@ -227,20 +227,20 @@ discard block |
||
227 | 227 | return $this->getInfoKey('pass'); |
228 | 228 | } |
229 | 229 | |
230 | - /** |
|
231 | - * Whether the URL contains a port number. |
|
232 | - * @return bool |
|
233 | - */ |
|
230 | + /** |
|
231 | + * Whether the URL contains a port number. |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | 234 | public function hasPort() : bool |
235 | 235 | { |
236 | 236 | return $this->getPort() !== -1; |
237 | 237 | } |
238 | 238 | |
239 | - /** |
|
240 | - * Alias for the hasParams() method. |
|
241 | - * @return bool |
|
242 | - * @see URLInfo::hasParams() |
|
243 | - */ |
|
239 | + /** |
|
240 | + * Alias for the hasParams() method. |
|
241 | + * @return bool |
|
242 | + * @see URLInfo::hasParams() |
|
243 | + */ |
|
244 | 244 | public function hasQuery() : bool |
245 | 245 | { |
246 | 246 | return $this->hasParams(); |
@@ -298,25 +298,25 @@ discard block |
||
298 | 298 | return $this->normalizer->normalize(); |
299 | 299 | } |
300 | 300 | |
301 | - /** |
|
302 | - * Creates a hash of the URL, which can be used for comparisons. |
|
303 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
304 | - * the same links with a different parameter order will have the |
|
305 | - * same hash. |
|
306 | - * |
|
307 | - * @return string |
|
308 | - */ |
|
301 | + /** |
|
302 | + * Creates a hash of the URL, which can be used for comparisons. |
|
303 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
304 | + * the same links with a different parameter order will have the |
|
305 | + * same hash. |
|
306 | + * |
|
307 | + * @return string |
|
308 | + */ |
|
309 | 309 | public function getHash() |
310 | 310 | { |
311 | 311 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
312 | 312 | } |
313 | 313 | |
314 | - /** |
|
315 | - * Highlights the URL using HTML tags with specific highlighting |
|
316 | - * class names. |
|
317 | - * |
|
318 | - * @return string Will return an empty string if the URL is not valid. |
|
319 | - */ |
|
314 | + /** |
|
315 | + * Highlights the URL using HTML tags with specific highlighting |
|
316 | + * class names. |
|
317 | + * |
|
318 | + * @return string Will return an empty string if the URL is not valid. |
|
319 | + */ |
|
320 | 320 | public function getHighlighted() : string |
321 | 321 | { |
322 | 322 | if(!$this->isValid()) { |
@@ -350,15 +350,15 @@ discard block |
||
350 | 350 | return count($params); |
351 | 351 | } |
352 | 352 | |
353 | - /** |
|
354 | - * Retrieves all parameters specified in the url, |
|
355 | - * if any, as an associative array. |
|
356 | - * |
|
357 | - * NOTE: Ignores parameters that have been added |
|
358 | - * to the excluded parameters list. |
|
359 | - * |
|
360 | - * @return array |
|
361 | - */ |
|
353 | + /** |
|
354 | + * Retrieves all parameters specified in the url, |
|
355 | + * if any, as an associative array. |
|
356 | + * |
|
357 | + * NOTE: Ignores parameters that have been added |
|
358 | + * to the excluded parameters list. |
|
359 | + * |
|
360 | + * @return array |
|
361 | + */ |
|
362 | 362 | public function getParams() : array |
363 | 363 | { |
364 | 364 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -376,22 +376,22 @@ discard block |
||
376 | 376 | return $keep; |
377 | 377 | } |
378 | 378 | |
379 | - /** |
|
380 | - * Retrieves the names of all parameters present in the URL, if any. |
|
381 | - * @return string[] |
|
382 | - */ |
|
379 | + /** |
|
380 | + * Retrieves the names of all parameters present in the URL, if any. |
|
381 | + * @return string[] |
|
382 | + */ |
|
383 | 383 | public function getParamNames() : array |
384 | 384 | { |
385 | 385 | $params = $this->getParams(); |
386 | 386 | return array_keys($params); |
387 | 387 | } |
388 | 388 | |
389 | - /** |
|
390 | - * Retrieves a specific parameter value from the URL. |
|
391 | - * |
|
392 | - * @param string $name |
|
393 | - * @return string The parameter value, or an empty string if it does not exist. |
|
394 | - */ |
|
389 | + /** |
|
390 | + * Retrieves a specific parameter value from the URL. |
|
391 | + * |
|
392 | + * @param string $name |
|
393 | + * @return string The parameter value, or an empty string if it does not exist. |
|
394 | + */ |
|
395 | 395 | public function getParam(string $name) : string |
396 | 396 | { |
397 | 397 | if(isset($this->info['params'][$name])) { |
@@ -401,16 +401,16 @@ discard block |
||
401 | 401 | return ''; |
402 | 402 | } |
403 | 403 | |
404 | - /** |
|
405 | - * Excludes an URL parameter entirely if present: |
|
406 | - * the parser will act as if the parameter was not |
|
407 | - * even present in the source URL, effectively |
|
408 | - * stripping it. |
|
409 | - * |
|
410 | - * @param string $name |
|
411 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
412 | - * @return URLInfo |
|
413 | - */ |
|
404 | + /** |
|
405 | + * Excludes an URL parameter entirely if present: |
|
406 | + * the parser will act as if the parameter was not |
|
407 | + * even present in the source URL, effectively |
|
408 | + * stripping it. |
|
409 | + * |
|
410 | + * @param string $name |
|
411 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
412 | + * @return URLInfo |
|
413 | + */ |
|
414 | 414 | public function excludeParam(string $name, string $reason) : URLInfo |
415 | 415 | { |
416 | 416 | if(!isset($this->excludedParams[$name])) |
@@ -463,25 +463,25 @@ discard block |
||
463 | 463 | return self::$typeLabels[$this->getType()]; |
464 | 464 | } |
465 | 465 | |
466 | - /** |
|
467 | - * Whether excluded parameters should be highlighted in |
|
468 | - * a different color in the URL when using the |
|
469 | - * {@link URLInfo::getHighlighted()} method. |
|
470 | - * |
|
471 | - * @param bool $highlight |
|
472 | - * @return URLInfo |
|
473 | - */ |
|
466 | + /** |
|
467 | + * Whether excluded parameters should be highlighted in |
|
468 | + * a different color in the URL when using the |
|
469 | + * {@link URLInfo::getHighlighted()} method. |
|
470 | + * |
|
471 | + * @param bool $highlight |
|
472 | + * @return URLInfo |
|
473 | + */ |
|
474 | 474 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
475 | 475 | { |
476 | 476 | $this->highlightExcluded = $highlight; |
477 | 477 | return $this; |
478 | 478 | } |
479 | 479 | |
480 | - /** |
|
481 | - * Returns an array with all relevant URL information. |
|
482 | - * |
|
483 | - * @return array |
|
484 | - */ |
|
480 | + /** |
|
481 | + * Returns an array with all relevant URL information. |
|
482 | + * |
|
483 | + * @return array |
|
484 | + */ |
|
485 | 485 | public function toArray() : array |
486 | 486 | { |
487 | 487 | return array( |
@@ -525,24 +525,24 @@ discard block |
||
525 | 525 | return $this; |
526 | 526 | } |
527 | 527 | |
528 | - /** |
|
529 | - * Whether the parameter exclusion mode is enabled: |
|
530 | - * In this case, if any parameters have been added to the |
|
531 | - * exclusion list, all relevant methods will exclude these. |
|
532 | - * |
|
533 | - * @return bool |
|
534 | - */ |
|
528 | + /** |
|
529 | + * Whether the parameter exclusion mode is enabled: |
|
530 | + * In this case, if any parameters have been added to the |
|
531 | + * exclusion list, all relevant methods will exclude these. |
|
532 | + * |
|
533 | + * @return bool |
|
534 | + */ |
|
535 | 535 | public function isParamExclusionEnabled() : bool |
536 | 536 | { |
537 | 537 | return $this->paramExclusion; |
538 | 538 | } |
539 | 539 | |
540 | - /** |
|
541 | - * Checks whether the link contains any parameters that |
|
542 | - * are on the list of excluded parameters. |
|
543 | - * |
|
544 | - * @return bool |
|
545 | - */ |
|
540 | + /** |
|
541 | + * Checks whether the link contains any parameters that |
|
542 | + * are on the list of excluded parameters. |
|
543 | + * |
|
544 | + * @return bool |
|
545 | + */ |
|
546 | 546 | public function containsExcludedParams() : bool |
547 | 547 | { |
548 | 548 | if(empty($this->excludedParams)) { |