@@ -38,40 +38,40 @@ discard block |
||
38 | 38 | const TYPE_PHONE = 'phone'; |
39 | 39 | const TYPE_URL = 'url'; |
40 | 40 | |
41 | - /** |
|
42 | - * The original URL that was passed to the constructor. |
|
43 | - * @var string |
|
44 | - */ |
|
41 | + /** |
|
42 | + * The original URL that was passed to the constructor. |
|
43 | + * @var string |
|
44 | + */ |
|
45 | 45 | protected $rawURL; |
46 | 46 | |
47 | - /** |
|
48 | - * @var array |
|
49 | - */ |
|
47 | + /** |
|
48 | + * @var array |
|
49 | + */ |
|
50 | 50 | protected $info; |
51 | 51 | |
52 | - /** |
|
53 | - * @var bool |
|
54 | - */ |
|
52 | + /** |
|
53 | + * @var bool |
|
54 | + */ |
|
55 | 55 | protected $isEmail = false; |
56 | 56 | |
57 | - /** |
|
58 | - * @var bool |
|
59 | - */ |
|
57 | + /** |
|
58 | + * @var bool |
|
59 | + */ |
|
60 | 60 | protected $isFragment = false; |
61 | 61 | |
62 | - /** |
|
63 | - * @var bool |
|
64 | - */ |
|
62 | + /** |
|
63 | + * @var bool |
|
64 | + */ |
|
65 | 65 | protected $isValid = true; |
66 | 66 | |
67 | - /** |
|
68 | - * @var bool |
|
69 | - */ |
|
67 | + /** |
|
68 | + * @var bool |
|
69 | + */ |
|
70 | 70 | protected $isPhone = false; |
71 | 71 | |
72 | - /** |
|
73 | - * @var array |
|
74 | - */ |
|
72 | + /** |
|
73 | + * @var array |
|
74 | + */ |
|
75 | 75 | protected $knownSchemes = array( |
76 | 76 | 'ftp', |
77 | 77 | 'http', |
@@ -82,41 +82,41 @@ discard block |
||
82 | 82 | 'file' |
83 | 83 | ); |
84 | 84 | |
85 | - /** |
|
86 | - * @var array |
|
87 | - */ |
|
85 | + /** |
|
86 | + * @var array |
|
87 | + */ |
|
88 | 88 | protected $error; |
89 | 89 | |
90 | - /** |
|
91 | - * @var array |
|
92 | - */ |
|
90 | + /** |
|
91 | + * @var array |
|
92 | + */ |
|
93 | 93 | protected $params = array(); |
94 | 94 | |
95 | - /** |
|
96 | - * @var string[] |
|
97 | - */ |
|
95 | + /** |
|
96 | + * @var string[] |
|
97 | + */ |
|
98 | 98 | protected $excludedParams = array(); |
99 | 99 | |
100 | - /** |
|
101 | - * @var bool |
|
102 | - * @see URLInfo::setParamExclusion() |
|
103 | - */ |
|
100 | + /** |
|
101 | + * @var bool |
|
102 | + * @see URLInfo::setParamExclusion() |
|
103 | + */ |
|
104 | 104 | protected $paramExclusion = false; |
105 | 105 | |
106 | - /** |
|
107 | - * @var array |
|
108 | - * @see URLInfo::getTypeLabel() |
|
109 | - */ |
|
106 | + /** |
|
107 | + * @var array |
|
108 | + * @see URLInfo::getTypeLabel() |
|
109 | + */ |
|
110 | 110 | protected static $typeLabels; |
111 | 111 | |
112 | - /** |
|
113 | - * @var bool |
|
114 | - */ |
|
112 | + /** |
|
113 | + * @var bool |
|
114 | + */ |
|
115 | 115 | protected $highlightExcluded = false; |
116 | 116 | |
117 | - /** |
|
118 | - * @var array |
|
119 | - */ |
|
117 | + /** |
|
118 | + * @var array |
|
119 | + */ |
|
120 | 120 | protected $infoKeys = array( |
121 | 121 | 'scheme', |
122 | 122 | 'host', |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | 'fragment' |
129 | 129 | ); |
130 | 130 | |
131 | - /** |
|
132 | - * @var string |
|
133 | - */ |
|
131 | + /** |
|
132 | + * @var string |
|
133 | + */ |
|
134 | 134 | protected $url; |
135 | 135 | |
136 | 136 | public function __construct(string $url) |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | $this->isValid = true; |
217 | 217 | } |
218 | 218 | |
219 | - /** |
|
220 | - * Filters an URL: removes control characters and the |
|
221 | - * like to have a clean URL to work with. |
|
222 | - * |
|
223 | - * @param string $url |
|
224 | - * @return string |
|
225 | - */ |
|
219 | + /** |
|
220 | + * Filters an URL: removes control characters and the |
|
221 | + * like to have a clean URL to work with. |
|
222 | + * |
|
223 | + * @param string $url |
|
224 | + * @return string |
|
225 | + */ |
|
226 | 226 | public static function filterURL(string $url) |
227 | 227 | { |
228 | 228 | // fix ampersands if it comes from HTML |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | return $url; |
246 | 246 | } |
247 | 247 | |
248 | - /** |
|
249 | - * Goes through all information in the parse_url result |
|
250 | - * array, and attempts to fix any user errors in formatting |
|
251 | - * that can be recovered from, mostly regarding stray spaces. |
|
252 | - */ |
|
248 | + /** |
|
249 | + * Goes through all information in the parse_url result |
|
250 | + * array, and attempts to fix any user errors in formatting |
|
251 | + * that can be recovered from, mostly regarding stray spaces. |
|
252 | + */ |
|
253 | 253 | protected function filterParsed() |
254 | 254 | { |
255 | 255 | foreach($this->info as $key => $val) |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | return $this->isPhone; |
334 | 334 | } |
335 | 335 | |
336 | - /** |
|
337 | - * Whether the URL is a regular URL, not one of the |
|
338 | - * other types like a phone number or email address. |
|
339 | - * |
|
340 | - * @return bool |
|
341 | - */ |
|
336 | + /** |
|
337 | + * Whether the URL is a regular URL, not one of the |
|
338 | + * other types like a phone number or email address. |
|
339 | + * |
|
340 | + * @return bool |
|
341 | + */ |
|
342 | 342 | public function isURL() : bool |
343 | 343 | { |
344 | 344 | $host = $this->getHost(); |
@@ -350,20 +350,20 @@ discard block |
||
350 | 350 | return $this->isValid; |
351 | 351 | } |
352 | 352 | |
353 | - /** |
|
354 | - * Retrieves the host name, or an empty string if none is present. |
|
355 | - * |
|
356 | - * @return string |
|
357 | - */ |
|
353 | + /** |
|
354 | + * Retrieves the host name, or an empty string if none is present. |
|
355 | + * |
|
356 | + * @return string |
|
357 | + */ |
|
358 | 358 | public function getHost() : string |
359 | 359 | { |
360 | 360 | return $this->getInfoKey('host'); |
361 | 361 | } |
362 | 362 | |
363 | - /** |
|
364 | - * Retrieves the path, or an empty string if none is present. |
|
365 | - * @return string |
|
366 | - */ |
|
363 | + /** |
|
364 | + * Retrieves the path, or an empty string if none is present. |
|
365 | + * @return string |
|
366 | + */ |
|
367 | 367 | public function getPath() : string |
368 | 368 | { |
369 | 369 | return $this->getInfoKey('path'); |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | return $this->getInfoKey('scheme'); |
380 | 380 | } |
381 | 381 | |
382 | - /** |
|
383 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
384 | - * @return int |
|
385 | - */ |
|
382 | + /** |
|
383 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
384 | + * @return int |
|
385 | + */ |
|
386 | 386 | public function getPort() : int |
387 | 387 | { |
388 | 388 | $port = $this->getInfoKey('port'); |
@@ -393,13 +393,13 @@ discard block |
||
393 | 393 | return -1; |
394 | 394 | } |
395 | 395 | |
396 | - /** |
|
397 | - * Retrieves the raw query string, or an empty string if none is present. |
|
398 | - * |
|
399 | - * @return string |
|
400 | - * |
|
401 | - * @see URLInfo::getParams() |
|
402 | - */ |
|
396 | + /** |
|
397 | + * Retrieves the raw query string, or an empty string if none is present. |
|
398 | + * |
|
399 | + * @return string |
|
400 | + * |
|
401 | + * @see URLInfo::getParams() |
|
402 | + */ |
|
403 | 403 | public function getQuery() : string |
404 | 404 | { |
405 | 405 | return $this->getInfoKey('query'); |
@@ -415,20 +415,20 @@ discard block |
||
415 | 415 | return $this->getInfoKey('pass'); |
416 | 416 | } |
417 | 417 | |
418 | - /** |
|
419 | - * Whether the URL contains a port number. |
|
420 | - * @return bool |
|
421 | - */ |
|
418 | + /** |
|
419 | + * Whether the URL contains a port number. |
|
420 | + * @return bool |
|
421 | + */ |
|
422 | 422 | public function hasPort() : bool |
423 | 423 | { |
424 | 424 | return $this->getPort() !== -1; |
425 | 425 | } |
426 | 426 | |
427 | - /** |
|
428 | - * Alias for the hasParams() method. |
|
429 | - * @return bool |
|
430 | - * @see URLInfo::hasParams() |
|
431 | - */ |
|
427 | + /** |
|
428 | + * Alias for the hasParams() method. |
|
429 | + * @return bool |
|
430 | + * @see URLInfo::hasParams() |
|
431 | + */ |
|
432 | 432 | public function hasQuery() : bool |
433 | 433 | { |
434 | 434 | return $this->hasParams(); |
@@ -509,25 +509,25 @@ discard block |
||
509 | 509 | return $normalized; |
510 | 510 | } |
511 | 511 | |
512 | - /** |
|
513 | - * Creates a hash of the URL, which can be used for comparisons. |
|
514 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
515 | - * the same links with a different parameter order will have the |
|
516 | - * same hash. |
|
517 | - * |
|
518 | - * @return string |
|
519 | - */ |
|
512 | + /** |
|
513 | + * Creates a hash of the URL, which can be used for comparisons. |
|
514 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
515 | + * the same links with a different parameter order will have the |
|
516 | + * same hash. |
|
517 | + * |
|
518 | + * @return string |
|
519 | + */ |
|
520 | 520 | public function getHash() |
521 | 521 | { |
522 | 522 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
523 | 523 | } |
524 | 524 | |
525 | - /** |
|
526 | - * Highlights the URL using HTML tags with specific highlighting |
|
527 | - * class names. |
|
528 | - * |
|
529 | - * @return string Will return an empty string if the URL is not valid. |
|
530 | - */ |
|
525 | + /** |
|
526 | + * Highlights the URL using HTML tags with specific highlighting |
|
527 | + * class names. |
|
528 | + * |
|
529 | + * @return string Will return an empty string if the URL is not valid. |
|
530 | + */ |
|
531 | 531 | public function getHighlighted() : string |
532 | 532 | { |
533 | 533 | if(!$this->isValid) { |
@@ -711,15 +711,15 @@ discard block |
||
711 | 711 | return count($params); |
712 | 712 | } |
713 | 713 | |
714 | - /** |
|
715 | - * Retrieves all parameters specified in the url, |
|
716 | - * if any, as an associative array. |
|
717 | - * |
|
718 | - * NOTE: Ignores parameters that have been added |
|
719 | - * to the excluded parameters list. |
|
720 | - * |
|
721 | - * @return array |
|
722 | - */ |
|
714 | + /** |
|
715 | + * Retrieves all parameters specified in the url, |
|
716 | + * if any, as an associative array. |
|
717 | + * |
|
718 | + * NOTE: Ignores parameters that have been added |
|
719 | + * to the excluded parameters list. |
|
720 | + * |
|
721 | + * @return array |
|
722 | + */ |
|
723 | 723 | public function getParams() : array |
724 | 724 | { |
725 | 725 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -736,22 +736,22 @@ discard block |
||
736 | 736 | return $keep; |
737 | 737 | } |
738 | 738 | |
739 | - /** |
|
740 | - * Retrieves the names of all parameters present in the URL, if any. |
|
741 | - * @return string[] |
|
742 | - */ |
|
739 | + /** |
|
740 | + * Retrieves the names of all parameters present in the URL, if any. |
|
741 | + * @return string[] |
|
742 | + */ |
|
743 | 743 | public function getParamNames() : array |
744 | 744 | { |
745 | 745 | $params = $this->getParams(); |
746 | 746 | return array_keys($params); |
747 | 747 | } |
748 | 748 | |
749 | - /** |
|
750 | - * Retrieves a specific parameter value from the URL. |
|
751 | - * |
|
752 | - * @param string $name |
|
753 | - * @return string The parameter value, or an empty string if it does not exist. |
|
754 | - */ |
|
749 | + /** |
|
750 | + * Retrieves a specific parameter value from the URL. |
|
751 | + * |
|
752 | + * @param string $name |
|
753 | + * @return string The parameter value, or an empty string if it does not exist. |
|
754 | + */ |
|
755 | 755 | public function getParam(string $name) : string |
756 | 756 | { |
757 | 757 | if(isset($this->params[$name])) { |
@@ -761,16 +761,16 @@ discard block |
||
761 | 761 | return ''; |
762 | 762 | } |
763 | 763 | |
764 | - /** |
|
765 | - * Excludes an URL parameter entirely if present: |
|
766 | - * the parser will act as if the parameter was not |
|
767 | - * even present in the source URL, effectively |
|
768 | - * stripping it. |
|
769 | - * |
|
770 | - * @param string $name |
|
771 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
772 | - * @return URLInfo |
|
773 | - */ |
|
764 | + /** |
|
765 | + * Excludes an URL parameter entirely if present: |
|
766 | + * the parser will act as if the parameter was not |
|
767 | + * even present in the source URL, effectively |
|
768 | + * stripping it. |
|
769 | + * |
|
770 | + * @param string $name |
|
771 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
772 | + * @return URLInfo |
|
773 | + */ |
|
774 | 774 | public function excludeParam(string $name, string $reason) : URLInfo |
775 | 775 | { |
776 | 776 | if(!isset($this->excludedParams[$name])) |
@@ -835,25 +835,25 @@ discard block |
||
835 | 835 | return self::$typeLabels[$this->getType()]; |
836 | 836 | } |
837 | 837 | |
838 | - /** |
|
839 | - * Whether excluded parameters should be highlighted in |
|
840 | - * a different color in the URL when using the |
|
841 | - * {@link URLInfo::getHighlighted()} method. |
|
842 | - * |
|
843 | - * @param bool $highlight |
|
844 | - * @return URLInfo |
|
845 | - */ |
|
838 | + /** |
|
839 | + * Whether excluded parameters should be highlighted in |
|
840 | + * a different color in the URL when using the |
|
841 | + * {@link URLInfo::getHighlighted()} method. |
|
842 | + * |
|
843 | + * @param bool $highlight |
|
844 | + * @return URLInfo |
|
845 | + */ |
|
846 | 846 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
847 | 847 | { |
848 | 848 | $this->highlightExcluded = $highlight; |
849 | 849 | return $this; |
850 | 850 | } |
851 | 851 | |
852 | - /** |
|
853 | - * Returns an array with all relevant URL information. |
|
854 | - * |
|
855 | - * @return array |
|
856 | - */ |
|
852 | + /** |
|
853 | + * Returns an array with all relevant URL information. |
|
854 | + * |
|
855 | + * @return array |
|
856 | + */ |
|
857 | 857 | public function toArray() : array |
858 | 858 | { |
859 | 859 | return array( |
@@ -897,24 +897,24 @@ discard block |
||
897 | 897 | return $this; |
898 | 898 | } |
899 | 899 | |
900 | - /** |
|
901 | - * Whether the parameter exclusion mode is enabled: |
|
902 | - * In this case, if any parameters have been added to the |
|
903 | - * exclusion list, all relevant methods will exclude these. |
|
904 | - * |
|
905 | - * @return bool |
|
906 | - */ |
|
900 | + /** |
|
901 | + * Whether the parameter exclusion mode is enabled: |
|
902 | + * In this case, if any parameters have been added to the |
|
903 | + * exclusion list, all relevant methods will exclude these. |
|
904 | + * |
|
905 | + * @return bool |
|
906 | + */ |
|
907 | 907 | public function isParamExclusionEnabled() : bool |
908 | 908 | { |
909 | 909 | return $this->paramExclusion; |
910 | 910 | } |
911 | 911 | |
912 | - /** |
|
913 | - * Checks whether the link contains any parameters that |
|
914 | - * are on the list of excluded parameters. |
|
915 | - * |
|
916 | - * @return bool |
|
917 | - */ |
|
912 | + /** |
|
913 | + * Checks whether the link contains any parameters that |
|
914 | + * are on the list of excluded parameters. |
|
915 | + * |
|
916 | + * @return bool |
|
917 | + */ |
|
918 | 918 | public function containsExcludedParams() : bool |
919 | 919 | { |
920 | 920 | if(empty($this->excludedParams)) { |