@@ -44,42 +44,42 @@ discard block |
||
44 | 44 | public const TYPE_URL = 'url'; |
45 | 45 | public const TYPE_NONE = 'none'; |
46 | 46 | |
47 | - /** |
|
48 | - * The original URL that was passed to the constructor. |
|
49 | - * @var string |
|
50 | - */ |
|
47 | + /** |
|
48 | + * The original URL that was passed to the constructor. |
|
49 | + * @var string |
|
50 | + */ |
|
51 | 51 | protected string $rawURL; |
52 | 52 | |
53 | - /** |
|
54 | - * @var array<string,mixed> |
|
55 | - */ |
|
53 | + /** |
|
54 | + * @var array<string,mixed> |
|
55 | + */ |
|
56 | 56 | protected array $info; |
57 | 57 | |
58 | - /** |
|
59 | - * @var string[] |
|
60 | - */ |
|
58 | + /** |
|
59 | + * @var string[] |
|
60 | + */ |
|
61 | 61 | protected array $excludedParams = array(); |
62 | 62 | |
63 | - /** |
|
64 | - * @var bool |
|
65 | - * @see URLInfo::setParamExclusion() |
|
66 | - */ |
|
63 | + /** |
|
64 | + * @var bool |
|
65 | + * @see URLInfo::setParamExclusion() |
|
66 | + */ |
|
67 | 67 | protected bool $paramExclusion = false; |
68 | 68 | |
69 | - /** |
|
70 | - * @var array<string,string>|NULL |
|
71 | - * @see URLInfo::getTypeLabel() |
|
72 | - */ |
|
69 | + /** |
|
70 | + * @var array<string,string>|NULL |
|
71 | + * @see URLInfo::getTypeLabel() |
|
72 | + */ |
|
73 | 73 | protected static ?array $typeLabels = null; |
74 | 74 | |
75 | - /** |
|
76 | - * @var bool |
|
77 | - */ |
|
75 | + /** |
|
76 | + * @var bool |
|
77 | + */ |
|
78 | 78 | protected bool $highlightExcluded = false; |
79 | 79 | |
80 | - /** |
|
81 | - * @var string[] |
|
82 | - */ |
|
80 | + /** |
|
81 | + * @var string[] |
|
82 | + */ |
|
83 | 83 | protected array $infoKeys = array( |
84 | 84 | 'scheme', |
85 | 85 | 'host', |
@@ -91,24 +91,24 @@ discard block |
||
91 | 91 | 'fragment' |
92 | 92 | ); |
93 | 93 | |
94 | - /** |
|
95 | - * @var string |
|
96 | - */ |
|
94 | + /** |
|
95 | + * @var string |
|
96 | + */ |
|
97 | 97 | protected string $url; |
98 | 98 | |
99 | - /** |
|
100 | - * @var URIParser |
|
101 | - */ |
|
99 | + /** |
|
100 | + * @var URIParser |
|
101 | + */ |
|
102 | 102 | protected URIParser $parser; |
103 | 103 | |
104 | - /** |
|
105 | - * @var URINormalizer|NULL |
|
106 | - */ |
|
104 | + /** |
|
105 | + * @var URINormalizer|NULL |
|
106 | + */ |
|
107 | 107 | protected ?URINormalizer $normalizer = null; |
108 | 108 | |
109 | - /** |
|
110 | - * @var bool |
|
111 | - */ |
|
109 | + /** |
|
110 | + * @var bool |
|
111 | + */ |
|
112 | 112 | protected bool $encodeUTFChars = false; |
113 | 113 | |
114 | 114 | public function __construct(string $url) |
@@ -130,14 +130,14 @@ discard block |
||
130 | 130 | return $this->parser; |
131 | 131 | } |
132 | 132 | |
133 | - /** |
|
134 | - * Whether to URL encode any non-encoded UTF8 characters in the URL. |
|
135 | - * Default is to leave them as-is for better readability, since |
|
136 | - * browsers handle this well. |
|
137 | - * |
|
138 | - * @param bool $enabled |
|
139 | - * @return URLInfo |
|
140 | - */ |
|
133 | + /** |
|
134 | + * Whether to URL encode any non-encoded UTF8 characters in the URL. |
|
135 | + * Default is to leave them as-is for better readability, since |
|
136 | + * browsers handle this well. |
|
137 | + * |
|
138 | + * @param bool $enabled |
|
139 | + * @return URLInfo |
|
140 | + */ |
|
141 | 141 | public function setUTFEncoding(bool $enabled=true) : URLInfo |
142 | 142 | { |
143 | 143 | if($this->encodeUTFChars !== $enabled) |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | return $this->encodeUTFChars; |
155 | 155 | } |
156 | 156 | |
157 | - /** |
|
158 | - * Filters a URL: removes control characters and the |
|
159 | - * like to have a clean URL to work with. |
|
160 | - * |
|
161 | - * @param string $url |
|
162 | - * @return string |
|
163 | - */ |
|
157 | + /** |
|
158 | + * Filters a URL: removes control characters and the |
|
159 | + * like to have a clean URL to work with. |
|
160 | + * |
|
161 | + * @param string $url |
|
162 | + * @return string |
|
163 | + */ |
|
164 | 164 | public static function filterURL(string $url) : string |
165 | 165 | { |
166 | 166 | return URIFilter::filter($url); |
@@ -190,12 +190,12 @@ discard block |
||
190 | 190 | return $this->info['type'] === self::TYPE_PHONE; |
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
194 | - * Whether the URL is a regular URL, not one of the |
|
195 | - * other types like a phone number or email address. |
|
196 | - * |
|
197 | - * @return bool |
|
198 | - */ |
|
193 | + /** |
|
194 | + * Whether the URL is a regular URL, not one of the |
|
195 | + * other types like a phone number or email address. |
|
196 | + * |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | 199 | public function isURL() : bool |
200 | 200 | { |
201 | 201 | $host = $this->getHost(); |
@@ -207,20 +207,20 @@ discard block |
||
207 | 207 | return $this->parser->isValid(); |
208 | 208 | } |
209 | 209 | |
210 | - /** |
|
211 | - * Retrieves the host name, or an empty string if none is present. |
|
212 | - * |
|
213 | - * @return string |
|
214 | - */ |
|
210 | + /** |
|
211 | + * Retrieves the host name, or an empty string if none is present. |
|
212 | + * |
|
213 | + * @return string |
|
214 | + */ |
|
215 | 215 | public function getHost() : string |
216 | 216 | { |
217 | 217 | return $this->getInfoKey('host'); |
218 | 218 | } |
219 | 219 | |
220 | - /** |
|
221 | - * Retrieves the path, or an empty string if none is present. |
|
222 | - * @return string |
|
223 | - */ |
|
220 | + /** |
|
221 | + * Retrieves the path, or an empty string if none is present. |
|
222 | + * @return string |
|
223 | + */ |
|
224 | 224 | public function getPath() : string |
225 | 225 | { |
226 | 226 | return $this->getInfoKey('path'); |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | return $this->getInfoKey('scheme'); |
237 | 237 | } |
238 | 238 | |
239 | - /** |
|
240 | - * Retrieves the port specified in the URL, or -1 if none is present. |
|
241 | - * @return int |
|
242 | - */ |
|
239 | + /** |
|
240 | + * Retrieves the port specified in the URL, or -1 if none is present. |
|
241 | + * @return int |
|
242 | + */ |
|
243 | 243 | public function getPort() : int |
244 | 244 | { |
245 | 245 | $port = $this->getInfoKey('port'); |
@@ -251,13 +251,13 @@ discard block |
||
251 | 251 | return -1; |
252 | 252 | } |
253 | 253 | |
254 | - /** |
|
255 | - * Retrieves the raw query string, or an empty string if none is present. |
|
256 | - * |
|
257 | - * @return string |
|
258 | - * |
|
259 | - * @see URLInfo::getParams() |
|
260 | - */ |
|
254 | + /** |
|
255 | + * Retrieves the raw query string, or an empty string if none is present. |
|
256 | + * |
|
257 | + * @return string |
|
258 | + * |
|
259 | + * @see URLInfo::getParams() |
|
260 | + */ |
|
261 | 261 | public function getQuery() : string |
262 | 262 | { |
263 | 263 | return $this->getInfoKey('query'); |
@@ -273,20 +273,20 @@ discard block |
||
273 | 273 | return $this->getInfoKey('pass'); |
274 | 274 | } |
275 | 275 | |
276 | - /** |
|
277 | - * Whether the URL contains a port number. |
|
278 | - * @return bool |
|
279 | - */ |
|
276 | + /** |
|
277 | + * Whether the URL contains a port number. |
|
278 | + * @return bool |
|
279 | + */ |
|
280 | 280 | public function hasPort() : bool |
281 | 281 | { |
282 | 282 | return $this->getPort() !== -1; |
283 | 283 | } |
284 | 284 | |
285 | - /** |
|
286 | - * Alias for the hasParams() method. |
|
287 | - * @return bool |
|
288 | - * @see URLInfo::hasParams() |
|
289 | - */ |
|
285 | + /** |
|
286 | + * Alias for the hasParams() method. |
|
287 | + * @return bool |
|
288 | + * @see URLInfo::hasParams() |
|
289 | + */ |
|
290 | 290 | public function hasQuery() : bool |
291 | 291 | { |
292 | 292 | return $this->hasParams(); |
@@ -331,23 +331,23 @@ discard block |
||
331 | 331 | return ''; |
332 | 332 | } |
333 | 333 | |
334 | - /** |
|
335 | - * Retrieves a normalized URL: this ensures that all parameters |
|
336 | - * in the URL are always in the same order. |
|
337 | - * |
|
338 | - * @return string |
|
339 | - */ |
|
334 | + /** |
|
335 | + * Retrieves a normalized URL: this ensures that all parameters |
|
336 | + * in the URL are always in the same order. |
|
337 | + * |
|
338 | + * @return string |
|
339 | + */ |
|
340 | 340 | public function getNormalized() : string |
341 | 341 | { |
342 | 342 | return $this->normalize(); |
343 | 343 | } |
344 | 344 | |
345 | - /** |
|
346 | - * Like getNormalized(), but if a username and password are present |
|
347 | - * in the URL, returns the URL without them. |
|
348 | - * |
|
349 | - * @return string |
|
350 | - */ |
|
345 | + /** |
|
346 | + * Like getNormalized(), but if a username and password are present |
|
347 | + * in the URL, returns the URL without them. |
|
348 | + * |
|
349 | + * @return string |
|
350 | + */ |
|
351 | 351 | public function getNormalizedWithoutAuth() : string |
352 | 352 | { |
353 | 353 | return $this->normalize(false); |
@@ -368,25 +368,25 @@ discard block |
||
368 | 368 | return $this->normalizer->normalize(); |
369 | 369 | } |
370 | 370 | |
371 | - /** |
|
372 | - * Creates a hash of the URL, which can be used for comparisons. |
|
373 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
374 | - * the same links with a different parameter order will have the |
|
375 | - * same hash. |
|
376 | - * |
|
377 | - * @return string |
|
378 | - */ |
|
371 | + /** |
|
372 | + * Creates a hash of the URL, which can be used for comparisons. |
|
373 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
374 | + * the same links with a different parameter order will have the |
|
375 | + * same hash. |
|
376 | + * |
|
377 | + * @return string |
|
378 | + */ |
|
379 | 379 | public function getHash() : string |
380 | 380 | { |
381 | 381 | return ConvertHelper::string2shortHash($this->getNormalized()); |
382 | 382 | } |
383 | 383 | |
384 | - /** |
|
385 | - * Highlights the URL using HTML tags with specific highlighting |
|
386 | - * class names. |
|
387 | - * |
|
388 | - * @return string Will return an empty string if the URL is not valid. |
|
389 | - */ |
|
384 | + /** |
|
385 | + * Highlights the URL using HTML tags with specific highlighting |
|
386 | + * class names. |
|
387 | + * |
|
388 | + * @return string Will return an empty string if the URL is not valid. |
|
389 | + */ |
|
390 | 390 | public function getHighlighted() : string |
391 | 391 | { |
392 | 392 | if(!$this->isValid()) { |
@@ -418,15 +418,15 @@ discard block |
||
418 | 418 | return count($params); |
419 | 419 | } |
420 | 420 | |
421 | - /** |
|
422 | - * Retrieves all parameters specified in the url, |
|
423 | - * if any, as an associative array. |
|
424 | - * |
|
425 | - * NOTE: Ignores parameters that have been added |
|
426 | - * to the excluded parameters list. |
|
427 | - * |
|
428 | - * @return array<string,string> |
|
429 | - */ |
|
421 | + /** |
|
422 | + * Retrieves all parameters specified in the url, |
|
423 | + * if any, as an associative array. |
|
424 | + * |
|
425 | + * NOTE: Ignores parameters that have been added |
|
426 | + * to the excluded parameters list. |
|
427 | + * |
|
428 | + * @return array<string,string> |
|
429 | + */ |
|
430 | 430 | public function getParams() : array |
431 | 431 | { |
432 | 432 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -444,37 +444,37 @@ discard block |
||
444 | 444 | return $keep; |
445 | 445 | } |
446 | 446 | |
447 | - /** |
|
448 | - * Retrieves the names of all parameters present in the URL, if any. |
|
449 | - * @return string[] |
|
450 | - */ |
|
447 | + /** |
|
448 | + * Retrieves the names of all parameters present in the URL, if any. |
|
449 | + * @return string[] |
|
450 | + */ |
|
451 | 451 | public function getParamNames() : array |
452 | 452 | { |
453 | 453 | $params = $this->getParams(); |
454 | 454 | return array_keys($params); |
455 | 455 | } |
456 | 456 | |
457 | - /** |
|
458 | - * Retrieves a specific parameter value from the URL. |
|
459 | - * |
|
460 | - * @param string $name |
|
461 | - * @return string The parameter value, or an empty string if it does not exist. |
|
462 | - */ |
|
457 | + /** |
|
458 | + * Retrieves a specific parameter value from the URL. |
|
459 | + * |
|
460 | + * @param string $name |
|
461 | + * @return string The parameter value, or an empty string if it does not exist. |
|
462 | + */ |
|
463 | 463 | public function getParam(string $name) : string |
464 | 464 | { |
465 | 465 | return $this->info['params'][$name] ?? ''; |
466 | 466 | } |
467 | 467 | |
468 | - /** |
|
469 | - * Excludes a URL parameter entirely if present: |
|
470 | - * the parser will act as if the parameter was not |
|
471 | - * even present in the source URL, effectively |
|
472 | - * stripping it. |
|
473 | - * |
|
474 | - * @param string $name |
|
475 | - * @param string $reason A human-readable explanation why this is excluded - used when highlighting links. |
|
476 | - * @return URLInfo |
|
477 | - */ |
|
468 | + /** |
|
469 | + * Excludes a URL parameter entirely if present: |
|
470 | + * the parser will act as if the parameter was not |
|
471 | + * even present in the source URL, effectively |
|
472 | + * stripping it. |
|
473 | + * |
|
474 | + * @param string $name |
|
475 | + * @param string $reason A human-readable explanation why this is excluded - used when highlighting links. |
|
476 | + * @return URLInfo |
|
477 | + */ |
|
478 | 478 | public function excludeParam(string $name, string $reason='') : URLInfo |
479 | 479 | { |
480 | 480 | if(!isset($this->excludedParams[$name])) |
@@ -529,14 +529,14 @@ discard block |
||
529 | 529 | return self::$typeLabels[$this->getType()]; |
530 | 530 | } |
531 | 531 | |
532 | - /** |
|
533 | - * Whether excluded parameters should be highlighted in |
|
534 | - * a different color in the URL when using the |
|
535 | - * {@link URLInfo::getHighlighted()} method. |
|
536 | - * |
|
537 | - * @param bool $highlight |
|
538 | - * @return URLInfo |
|
539 | - */ |
|
532 | + /** |
|
533 | + * Whether excluded parameters should be highlighted in |
|
534 | + * a different color in the URL when using the |
|
535 | + * {@link URLInfo::getHighlighted()} method. |
|
536 | + * |
|
537 | + * @param bool $highlight |
|
538 | + * @return URLInfo |
|
539 | + */ |
|
540 | 540 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
541 | 541 | { |
542 | 542 | $this->highlightExcluded = $highlight; |
@@ -592,24 +592,24 @@ discard block |
||
592 | 592 | return $this; |
593 | 593 | } |
594 | 594 | |
595 | - /** |
|
596 | - * Whether the parameter exclusion mode is enabled: |
|
597 | - * In this case, if any parameters have been added to the |
|
598 | - * exclusion list, all relevant methods will exclude these. |
|
599 | - * |
|
600 | - * @return bool |
|
601 | - */ |
|
595 | + /** |
|
596 | + * Whether the parameter exclusion mode is enabled: |
|
597 | + * In this case, if any parameters have been added to the |
|
598 | + * exclusion list, all relevant methods will exclude these. |
|
599 | + * |
|
600 | + * @return bool |
|
601 | + */ |
|
602 | 602 | public function isParamExclusionEnabled() : bool |
603 | 603 | { |
604 | 604 | return $this->paramExclusion; |
605 | 605 | } |
606 | 606 | |
607 | - /** |
|
608 | - * Checks whether the link contains any parameters that |
|
609 | - * are on the list of excluded parameters. |
|
610 | - * |
|
611 | - * @return bool |
|
612 | - */ |
|
607 | + /** |
|
608 | + * Checks whether the link contains any parameters that |
|
609 | + * are on the list of excluded parameters. |
|
610 | + * |
|
611 | + * @return bool |
|
612 | + */ |
|
613 | 613 | public function containsExcludedParams() : bool |
614 | 614 | { |
615 | 615 | if(empty($this->excludedParams)) { |
@@ -697,26 +697,26 @@ discard block |
||
697 | 697 | ->canConnect(); |
698 | 698 | } |
699 | 699 | |
700 | - /** |
|
701 | - * Creates the connection tester instance that is used |
|
702 | - * to check if a URL can be connected to, and which is |
|
703 | - * used in the {@see URLInfo::tryConnect()} method. It |
|
704 | - * allows more settings to be used. |
|
705 | - * |
|
706 | - * @return URIConnectionTester |
|
707 | - */ |
|
700 | + /** |
|
701 | + * Creates the connection tester instance that is used |
|
702 | + * to check if a URL can be connected to, and which is |
|
703 | + * used in the {@see URLInfo::tryConnect()} method. It |
|
704 | + * allows more settings to be used. |
|
705 | + * |
|
706 | + * @return URIConnectionTester |
|
707 | + */ |
|
708 | 708 | public function createConnectionTester() : URIConnectionTester |
709 | 709 | { |
710 | 710 | return new URIConnectionTester($this); |
711 | 711 | } |
712 | 712 | |
713 | - /** |
|
714 | - * Adds/overwrites a URL parameter. |
|
715 | - * |
|
716 | - * @param string $name |
|
717 | - * @param string $val |
|
718 | - * @return URLInfo |
|
719 | - */ |
|
713 | + /** |
|
714 | + * Adds/overwrites a URL parameter. |
|
715 | + * |
|
716 | + * @param string $name |
|
717 | + * @param string $val |
|
718 | + * @return URLInfo |
|
719 | + */ |
|
720 | 720 | public function setParam(string $name, string $val) : URLInfo |
721 | 721 | { |
722 | 722 | $this->info['params'][$name] = $val; |
@@ -724,13 +724,13 @@ discard block |
||
724 | 724 | return $this; |
725 | 725 | } |
726 | 726 | |
727 | - /** |
|
728 | - * Removes a URL parameter. Has no effect if the |
|
729 | - * parameter is not present to begin with. |
|
730 | - * |
|
731 | - * @param string $param |
|
732 | - * @return URLInfo |
|
733 | - */ |
|
727 | + /** |
|
728 | + * Removes a URL parameter. Has no effect if the |
|
729 | + * parameter is not present to begin with. |
|
730 | + * |
|
731 | + * @param string $param |
|
732 | + * @return URLInfo |
|
733 | + */ |
|
734 | 734 | public function removeParam(string $param) : URLInfo |
735 | 735 | { |
736 | 736 | if(isset($this->info['params'][$param])) |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | { |
57 | 57 | $path = $this->info['path'] ?? ''; |
58 | 58 | |
59 | - if(strpos($path, '@') !== false) |
|
59 | + if (strpos($path, '@') !== false) |
|
60 | 60 | { |
61 | 61 | $this->info['path'] = str_replace(' ', '', $path); |
62 | 62 | } |
@@ -64,14 +64,14 @@ discard block |
||
64 | 64 | |
65 | 65 | private function filterScheme() : void |
66 | 66 | { |
67 | - if($this->hasScheme()) |
|
67 | + if ($this->hasScheme()) |
|
68 | 68 | { |
69 | 69 | $this->setScheme(strtolower($this->getScheme())); |
70 | 70 | } |
71 | 71 | else |
72 | 72 | { |
73 | 73 | $scheme = URISchemes::detectScheme($this->url); |
74 | - if(!empty($scheme)) { |
|
74 | + if (!empty($scheme)) { |
|
75 | 75 | $this->setScheme(URISchemes::resolveSchemeName($scheme)); |
76 | 76 | } |
77 | 77 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | private function filterAuth() : void |
81 | 81 | { |
82 | - if(!$this->hasAuth()) { |
|
82 | + if (!$this->hasAuth()) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | private function filterHost() : void |
93 | 93 | { |
94 | - if(!$this->hasHost()) |
|
94 | + if (!$this->hasHost()) |
|
95 | 95 | { |
96 | 96 | return; |
97 | 97 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | private function filterPath() : void |
106 | 106 | { |
107 | - if($this->hasPath()) { |
|
107 | + if ($this->hasPath()) { |
|
108 | 108 | $this->setPath($this->getPath()); |
109 | 109 | } |
110 | 110 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | { |
114 | 114 | $host = $this->getPath(); |
115 | 115 | |
116 | - if(empty($host) || !URLHosts::isHostKnown($host)) |
|
116 | + if (empty($host) || !URLHosts::isHostKnown($host)) |
|
117 | 117 | { |
118 | 118 | return; |
119 | 119 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | $this->setHost($host); |
122 | 122 | $this->removePath(); |
123 | 123 | |
124 | - if(!$this->hasScheme()) { |
|
124 | + if (!$this->hasScheme()) { |
|
125 | 125 | $this->setSchemeHTTPS(); |
126 | 126 | } |
127 | 127 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | $this->info['params'] = array(); |
132 | 132 | |
133 | 133 | $query = $this->getQuery(); |
134 | - if(empty($query)) { |
|
134 | + if (empty($query)) { |
|
135 | 135 | return; |
136 | 136 | } |
137 | 137 |