@@ -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)) { |
@@ -156,26 +156,26 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | $this->filterParsed(); |
| 158 | 158 | |
| 159 | - if($this->detectEmail()) { |
|
| 159 | + if ($this->detectEmail()) { |
|
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - if($this->detectFragmentLink()) { |
|
| 163 | + if ($this->detectFragmentLink()) { |
|
| 164 | 164 | return; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - if($this->detectPhoneLink()) { |
|
| 167 | + if ($this->detectPhoneLink()) { |
|
| 168 | 168 | return; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if(!$this->isValid) { |
|
| 171 | + if (!$this->isValid) { |
|
| 172 | 172 | return; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // no scheme found: it may be an email address without the mailto: |
| 176 | 176 | // It can't be a variable, since without the scheme it would already |
| 177 | 177 | // have been recognized as a vaiable only link. |
| 178 | - if(!isset($this->info['scheme'])) { |
|
| 178 | + if (!isset($this->info['scheme'])) { |
|
| 179 | 179 | $this->setError( |
| 180 | 180 | self::ERROR_MISSING_SCHEME, |
| 181 | 181 | t('Cannot determine the link\'s scheme, e.g. %1$s.', 'http') |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | return; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if(!in_array($this->info['scheme'], $this->knownSchemes)) { |
|
| 187 | + if (!in_array($this->info['scheme'], $this->knownSchemes)) { |
|
| 188 | 188 | $this->setError( |
| 189 | 189 | self::ERROR_INVALID_SCHEME, |
| 190 | - t('The scheme %1$s is not supported for links.', $this->info['scheme']) . ' ' . |
|
| 190 | + t('The scheme %1$s is not supported for links.', $this->info['scheme']).' '. |
|
| 191 | 191 | t('Valid schemes are: %1$s.', implode(', ', $this->knownSchemes)) |
| 192 | 192 | ); |
| 193 | 193 | $this->isValid = false; |
@@ -197,17 +197,17 @@ discard block |
||
| 197 | 197 | // every link needs a host. This case can happen for ex, if |
| 198 | 198 | // the link starts with a typo with only one slash, like: |
| 199 | 199 | // "http:/hostname" |
| 200 | - if(!isset($this->info['host'])) { |
|
| 200 | + if (!isset($this->info['host'])) { |
|
| 201 | 201 | $this->setError( |
| 202 | 202 | self::ERROR_MISSING_HOST, |
| 203 | - t('Cannot determine the link\'s host name.') . ' ' . |
|
| 203 | + t('Cannot determine the link\'s host name.').' '. |
|
| 204 | 204 | t('This usually happens when there\'s a typo somewhere.') |
| 205 | 205 | ); |
| 206 | 206 | $this->isValid = false; |
| 207 | 207 | return; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if(!empty($this->info['query'])) |
|
| 210 | + if (!empty($this->info['query'])) |
|
| 211 | 211 | { |
| 212 | 212 | $this->params = \AppUtils\ConvertHelper::parseQueryString($this->info['query']); |
| 213 | 213 | ksort($this->params); |
@@ -252,30 +252,30 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | protected function filterParsed() |
| 254 | 254 | { |
| 255 | - foreach($this->info as $key => $val) |
|
| 255 | + foreach ($this->info as $key => $val) |
|
| 256 | 256 | { |
| 257 | - if(is_string($val)) { |
|
| 257 | + if (is_string($val)) { |
|
| 258 | 258 | $this->info[$key] = trim($val); |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if(isset($this->info['host'])) { |
|
| 262 | + if (isset($this->info['host'])) { |
|
| 263 | 263 | $this->info['host'] = str_replace(' ', '', $this->info['host']); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if(isset($this->info['path'])) { |
|
| 266 | + if (isset($this->info['path'])) { |
|
| 267 | 267 | $this->info['path'] = str_replace(' ', '', $this->info['path']); |
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | protected function detectEmail() |
| 272 | 272 | { |
| 273 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
| 273 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
| 274 | 274 | $this->isEmail = true; |
| 275 | 275 | return true; |
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if(isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
| 278 | + if (isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
| 279 | 279 | { |
| 280 | 280 | $this->info['scheme'] = 'email'; |
| 281 | 281 | $this->isEmail = true; |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | protected function detectFragmentLink() |
| 289 | 289 | { |
| 290 | - if(isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
| 290 | + if (isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
| 291 | 291 | $this->isFragment = true; |
| 292 | 292 | return true; |
| 293 | 293 | } |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | |
| 298 | 298 | protected function detectPhoneLink() |
| 299 | 299 | { |
| 300 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
| 300 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
| 301 | 301 | $this->isPhone = true; |
| 302 | 302 | return true; |
| 303 | 303 | } |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | public function isSecure() |
| 313 | 313 | { |
| 314 | - if(isset($this->info['scheme']) && $this->info['scheme']=='https') { |
|
| 314 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'https') { |
|
| 315 | 315 | return true; |
| 316 | 316 | } |
| 317 | 317 | |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | public function getPort() : int |
| 387 | 387 | { |
| 388 | 388 | $port = $this->getInfoKey('port'); |
| 389 | - if(!empty($port)) { |
|
| 389 | + if (!empty($port)) { |
|
| 390 | 390 | return (int)$port; |
| 391 | 391 | } |
| 392 | 392 | |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | |
| 467 | 467 | protected function getInfoKey(string $name) : string |
| 468 | 468 | { |
| 469 | - if(isset($this->info[$name])) { |
|
| 469 | + if (isset($this->info[$name])) { |
|
| 470 | 470 | return (string)$this->info[$name]; |
| 471 | 471 | } |
| 472 | 472 | |
@@ -475,34 +475,34 @@ discard block |
||
| 475 | 475 | |
| 476 | 476 | public function getNormalized() : string |
| 477 | 477 | { |
| 478 | - if(!$this->isValid) { |
|
| 478 | + if (!$this->isValid) { |
|
| 479 | 479 | return ''; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - if($this->isFragment === true) |
|
| 482 | + if ($this->isFragment === true) |
|
| 483 | 483 | { |
| 484 | 484 | return '#'.$this->getFragment(); |
| 485 | 485 | } |
| 486 | - else if($this->isPhone === true) |
|
| 486 | + else if ($this->isPhone === true) |
|
| 487 | 487 | { |
| 488 | 488 | return 'tel://'.$this->getHost(); |
| 489 | 489 | } |
| 490 | - else if($this->isEmail === true) |
|
| 490 | + else if ($this->isEmail === true) |
|
| 491 | 491 | { |
| 492 | 492 | return 'mailto:'.$this->getPath(); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | $normalized = $this->info['scheme'].'://'.$this->info['host']; |
| 496 | - if(isset($this->info['path'])) { |
|
| 496 | + if (isset($this->info['path'])) { |
|
| 497 | 497 | $normalized .= $this->info['path']; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | $params = $this->getParams(); |
| 501 | - if(!empty($params)) { |
|
| 501 | + if (!empty($params)) { |
|
| 502 | 502 | $normalized .= '?'.http_build_query($params); |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - if(isset($this->info['fragment'])) { |
|
| 505 | + if (isset($this->info['fragment'])) { |
|
| 506 | 506 | $normalized .= '#'.$this->info['fragment']; |
| 507 | 507 | } |
| 508 | 508 | |
@@ -530,11 +530,11 @@ discard block |
||
| 530 | 530 | */ |
| 531 | 531 | public function getHighlighted() : string |
| 532 | 532 | { |
| 533 | - if(!$this->isValid) { |
|
| 533 | + if (!$this->isValid) { |
|
| 534 | 534 | return ''; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - if($this->isEmail) { |
|
| 537 | + if ($this->isEmail) { |
|
| 538 | 538 | return sprintf( |
| 539 | 539 | '<span class="link-scheme scheme-mailto">mailto:</span>'. |
| 540 | 540 | '<span class="link-host">%s</span>', |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | ); |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - if($this->isFragment) { |
|
| 545 | + if ($this->isFragment) { |
|
| 546 | 546 | return sprintf( |
| 547 | 547 | '<span class="link-fragment-sign">#</span>'. |
| 548 | 548 | '<span class="link-fragment-value">%s</span>', |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | |
| 553 | 553 | $result = ''; |
| 554 | 554 | |
| 555 | - if($this->hasScheme()) |
|
| 555 | + if ($this->hasScheme()) |
|
| 556 | 556 | { |
| 557 | 557 | $result = sprintf( |
| 558 | 558 | '<span class="link-scheme scheme-%1$s">'. |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | |
| 565 | 565 | $result .= '<span class="link-component double-slashes">//</span>'; |
| 566 | 566 | |
| 567 | - if($this->hasUsername()) |
|
| 567 | + if ($this->hasUsername()) |
|
| 568 | 568 | { |
| 569 | 569 | $result .= sprintf( |
| 570 | 570 | '<span class="link-credentials">%s</span>'. |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | ); |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - if($this->hasHost()) |
|
| 579 | + if ($this->hasHost()) |
|
| 580 | 580 | { |
| 581 | 581 | $result .= |
| 582 | 582 | sprintf( |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | ); |
| 586 | 586 | } |
| 587 | 587 | |
| 588 | - if($this->hasPort()) |
|
| 588 | + if ($this->hasPort()) |
|
| 589 | 589 | { |
| 590 | 590 | $result .= sprintf( |
| 591 | 591 | '<span class="link-component port-separator">:</span>'. |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | ); |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | - if($this->hasPath()) |
|
| 597 | + if ($this->hasPath()) |
|
| 598 | 598 | { |
| 599 | 599 | $path = str_replace(array(';', '='), array(';<wbr>', '=<wbr>'), $this->getPath()); |
| 600 | 600 | $tokens = explode('/', $path); |
@@ -605,11 +605,11 @@ discard block |
||
| 605 | 605 | ); |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | - if(!empty($this->params)) |
|
| 608 | + if (!empty($this->params)) |
|
| 609 | 609 | { |
| 610 | 610 | $tokens = array(); |
| 611 | 611 | |
| 612 | - foreach($this->params as $param => $value) |
|
| 612 | + foreach ($this->params as $param => $value) |
|
| 613 | 613 | { |
| 614 | 614 | $parts = sprintf( |
| 615 | 615 | '<span class="link-param-name">%s</span>'. |
@@ -627,10 +627,10 @@ discard block |
||
| 627 | 627 | $tag = ''; |
| 628 | 628 | |
| 629 | 629 | // is parameter exclusion enabled, and is this an excluded parameter? |
| 630 | - if($this->paramExclusion && isset($this->excludedParams[$param])) |
|
| 630 | + if ($this->paramExclusion && isset($this->excludedParams[$param])) |
|
| 631 | 631 | { |
| 632 | 632 | // display the excluded parameter, but highlight it |
| 633 | - if($this->highlightExcluded) |
|
| 633 | + if ($this->highlightExcluded) |
|
| 634 | 634 | { |
| 635 | 635 | $tooltip = $this->excludedParams[$param]; |
| 636 | 636 | |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | '<span class="link-component query-sign">?</span>'.implode('<span class="link-component param-separator">&</span>', $tokens); |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - if(isset($this->info['fragment'])) { |
|
| 663 | + if (isset($this->info['fragment'])) { |
|
| 664 | 664 | $result .= sprintf( |
| 665 | 665 | '<span class="link-fragment-sign">#</span>'. |
| 666 | 666 | '<span class="link-fragment">%s</span>', |
@@ -683,7 +683,7 @@ discard block |
||
| 683 | 683 | |
| 684 | 684 | public function getErrorMessage() : string |
| 685 | 685 | { |
| 686 | - if(isset($this->error)) { |
|
| 686 | + if (isset($this->error)) { |
|
| 687 | 687 | return $this->error['message']; |
| 688 | 688 | } |
| 689 | 689 | |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | |
| 693 | 693 | public function getErrorCode() : int |
| 694 | 694 | { |
| 695 | - if(isset($this->error)) { |
|
| 695 | + if (isset($this->error)) { |
|
| 696 | 696 | return $this->error['code']; |
| 697 | 697 | } |
| 698 | 698 | |
@@ -722,13 +722,13 @@ discard block |
||
| 722 | 722 | */ |
| 723 | 723 | public function getParams() : array |
| 724 | 724 | { |
| 725 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 725 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 726 | 726 | return $this->params; |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | $keep = array(); |
| 730 | - foreach($this->params as $name => $value) { |
|
| 731 | - if(!isset($this->excludedParams[$name])) { |
|
| 730 | + foreach ($this->params as $name => $value) { |
|
| 731 | + if (!isset($this->excludedParams[$name])) { |
|
| 732 | 732 | $keep[$name] = $value; |
| 733 | 733 | } |
| 734 | 734 | } |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | */ |
| 755 | 755 | public function getParam(string $name) : string |
| 756 | 756 | { |
| 757 | - if(isset($this->params[$name])) { |
|
| 757 | + if (isset($this->params[$name])) { |
|
| 758 | 758 | return $this->params[$name]; |
| 759 | 759 | } |
| 760 | 760 | |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | */ |
| 774 | 774 | public function excludeParam(string $name, string $reason) : URLInfo |
| 775 | 775 | { |
| 776 | - if(!isset($this->excludedParams[$name])) |
|
| 776 | + if (!isset($this->excludedParams[$name])) |
|
| 777 | 777 | { |
| 778 | 778 | $this->excludedParams[$name] = $reason; |
| 779 | 779 | $this->setParamExclusion(); |
@@ -794,15 +794,15 @@ discard block |
||
| 794 | 794 | */ |
| 795 | 795 | public function getType() : string |
| 796 | 796 | { |
| 797 | - if($this->isEmail) { |
|
| 797 | + if ($this->isEmail) { |
|
| 798 | 798 | return self::TYPE_EMAIL; |
| 799 | 799 | } |
| 800 | 800 | |
| 801 | - if($this->isFragment) { |
|
| 801 | + if ($this->isFragment) { |
|
| 802 | 802 | return self::TYPE_FRAGMENT; |
| 803 | 803 | } |
| 804 | 804 | |
| 805 | - if($this->isPhone) { |
|
| 805 | + if ($this->isPhone) { |
|
| 806 | 806 | return self::TYPE_PHONE; |
| 807 | 807 | } |
| 808 | 808 | |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | |
| 812 | 812 | public function getTypeLabel() : string |
| 813 | 813 | { |
| 814 | - if(!isset(self::$typeLabels)) |
|
| 814 | + if (!isset(self::$typeLabels)) |
|
| 815 | 815 | { |
| 816 | 816 | self::$typeLabels = array( |
| 817 | 817 | self::TYPE_EMAIL => t('Email'), |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | |
| 824 | 824 | $type = $this->getType(); |
| 825 | 825 | |
| 826 | - if(!isset(self::$typeLabels[$type])) |
|
| 826 | + if (!isset(self::$typeLabels[$type])) |
|
| 827 | 827 | { |
| 828 | 828 | throw new BaseException( |
| 829 | 829 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -843,7 +843,7 @@ discard block |
||
| 843 | 843 | * @param bool $highlight |
| 844 | 844 | * @return URLInfo |
| 845 | 845 | */ |
| 846 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
| 846 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
| 847 | 847 | { |
| 848 | 848 | $this->highlightExcluded = $highlight; |
| 849 | 849 | return $this; |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | * @see URLInfo::isParamExclusionEnabled() |
| 892 | 892 | * @see URLInfo::setHighlightExcluded() |
| 893 | 893 | */ |
| 894 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
| 894 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
| 895 | 895 | { |
| 896 | 896 | $this->paramExclusion = $enabled; |
| 897 | 897 | return $this; |
@@ -917,13 +917,13 @@ discard block |
||
| 917 | 917 | */ |
| 918 | 918 | public function containsExcludedParams() : bool |
| 919 | 919 | { |
| 920 | - if(empty($this->excludedParams)) { |
|
| 920 | + if (empty($this->excludedParams)) { |
|
| 921 | 921 | return false; |
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | $names = array_keys($this->params); |
| 925 | - foreach($names as $name) { |
|
| 926 | - if(isset($this->excludedParams[$name])) { |
|
| 925 | + foreach ($names as $name) { |
|
| 926 | + if (isset($this->excludedParams[$name])) { |
|
| 927 | 927 | return true; |
| 928 | 928 | } |
| 929 | 929 | } |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | |
| 940 | 940 | public function offsetSet($offset, $value) |
| 941 | 941 | { |
| 942 | - if(in_array($offset, $this->infoKeys)) { |
|
| 942 | + if (in_array($offset, $this->infoKeys)) { |
|
| 943 | 943 | $this->info[$offset] = $value; |
| 944 | 944 | } |
| 945 | 945 | } |
@@ -956,11 +956,11 @@ discard block |
||
| 956 | 956 | |
| 957 | 957 | public function offsetGet($offset) |
| 958 | 958 | { |
| 959 | - if($offset === 'port') { |
|
| 959 | + if ($offset === 'port') { |
|
| 960 | 960 | return $this->getPort(); |
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - if(in_array($offset, $this->infoKeys)) { |
|
| 963 | + if (in_array($offset, $this->infoKeys)) { |
|
| 964 | 964 | return $this->getInfoKey($offset); |
| 965 | 965 | } |
| 966 | 966 | |
@@ -971,7 +971,7 @@ discard block |
||
| 971 | 971 | { |
| 972 | 972 | $cssFolder = realpath(__DIR__.'/../css'); |
| 973 | 973 | |
| 974 | - if($cssFolder === false) { |
|
| 974 | + if ($cssFolder === false) { |
|
| 975 | 975 | throw new BaseException( |
| 976 | 976 | 'Cannot find package CSS folder.', |
| 977 | 977 | null, |