@@ -19,15 +19,15 @@ discard block |
||
| 19 | 19 | const TYPE_PHONE = 'phone'; |
| 20 | 20 | const TYPE_URL = 'url'; |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The original URL that was passed to the constructor. |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 22 | + /** |
|
| 23 | + * The original URL that was passed to the constructor. |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | 26 | protected $rawURL; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | 31 | protected $info; |
| 32 | 32 | |
| 33 | 33 | protected $isEmail = false; |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | protected $isPhone = false; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string[] |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var string[] |
|
| 43 | + */ |
|
| 44 | 44 | protected $knownSchemes = array( |
| 45 | 45 | 'ftp', |
| 46 | 46 | 'http', |
@@ -51,36 +51,36 @@ discard block |
||
| 51 | 51 | 'file' |
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var array |
|
| 56 | - */ |
|
| 54 | + /** |
|
| 55 | + * @var array |
|
| 56 | + */ |
|
| 57 | 57 | protected $error; |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 59 | + /** |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | 62 | protected $params = array(); |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var string[] |
|
| 66 | - */ |
|
| 64 | + /** |
|
| 65 | + * @var string[] |
|
| 66 | + */ |
|
| 67 | 67 | protected $excludedParams = array(); |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var bool |
|
| 71 | - * @see URLInfo::setParamExclusion() |
|
| 72 | - */ |
|
| 69 | + /** |
|
| 70 | + * @var bool |
|
| 71 | + * @see URLInfo::setParamExclusion() |
|
| 72 | + */ |
|
| 73 | 73 | protected $paramExclusion = false; |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @var array |
|
| 77 | - * @see URLInfo::getTypeLabel() |
|
| 78 | - */ |
|
| 75 | + /** |
|
| 76 | + * @var array |
|
| 77 | + * @see URLInfo::getTypeLabel() |
|
| 78 | + */ |
|
| 79 | 79 | protected static $typeLabels; |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @var bool |
|
| 83 | - */ |
|
| 81 | + /** |
|
| 82 | + * @var bool |
|
| 83 | + */ |
|
| 84 | 84 | protected $highlightExcluded = false; |
| 85 | 85 | |
| 86 | 86 | protected $infoKeys = array( |
@@ -177,13 +177,13 @@ discard block |
||
| 177 | 177 | $this->isValid = true; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Filters an URL: removes control characters and the |
|
| 182 | - * like to have a clean URL to work with. |
|
| 183 | - * |
|
| 184 | - * @param string $url |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 180 | + /** |
|
| 181 | + * Filters an URL: removes control characters and the |
|
| 182 | + * like to have a clean URL to work with. |
|
| 183 | + * |
|
| 184 | + * @param string $url |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | 187 | public static function filterURL(string $url) |
| 188 | 188 | { |
| 189 | 189 | // fix ampersands if it comes from HTML |
@@ -206,11 +206,11 @@ discard block |
||
| 206 | 206 | return $url; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Goes through all information in the parse_url result |
|
| 211 | - * array, and attempts to fix any user errors in formatting |
|
| 212 | - * that can be recovered from, mostly regarding stray spaces. |
|
| 213 | - */ |
|
| 209 | + /** |
|
| 210 | + * Goes through all information in the parse_url result |
|
| 211 | + * array, and attempts to fix any user errors in formatting |
|
| 212 | + * that can be recovered from, mostly regarding stray spaces. |
|
| 213 | + */ |
|
| 214 | 214 | protected function filterParsed() |
| 215 | 215 | { |
| 216 | 216 | foreach($this->info as $key => $val) |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | return $this->isPhone; |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * Whether the URL is a regular URL, not one of the |
|
| 299 | - * other types like a phone number or email address. |
|
| 300 | - * |
|
| 301 | - * @return bool |
|
| 302 | - */ |
|
| 297 | + /** |
|
| 298 | + * Whether the URL is a regular URL, not one of the |
|
| 299 | + * other types like a phone number or email address. |
|
| 300 | + * |
|
| 301 | + * @return bool |
|
| 302 | + */ |
|
| 303 | 303 | public function isURL() : bool |
| 304 | 304 | { |
| 305 | 305 | $host = $this->getHost(); |
@@ -311,20 +311,20 @@ discard block |
||
| 311 | 311 | return $this->isValid; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Retrieves the host name, or an empty string if none is present. |
|
| 316 | - * |
|
| 317 | - * @return string |
|
| 318 | - */ |
|
| 314 | + /** |
|
| 315 | + * Retrieves the host name, or an empty string if none is present. |
|
| 316 | + * |
|
| 317 | + * @return string |
|
| 318 | + */ |
|
| 319 | 319 | public function getHost() : string |
| 320 | 320 | { |
| 321 | 321 | return $this->getInfoKey('host'); |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - /** |
|
| 325 | - * Retrieves the path, or an empty string if none is present. |
|
| 326 | - * @return string |
|
| 327 | - */ |
|
| 324 | + /** |
|
| 325 | + * Retrieves the path, or an empty string if none is present. |
|
| 326 | + * @return string |
|
| 327 | + */ |
|
| 328 | 328 | public function getPath() : string |
| 329 | 329 | { |
| 330 | 330 | return $this->getInfoKey('path'); |
@@ -340,10 +340,10 @@ discard block |
||
| 340 | 340 | return $this->getInfoKey('scheme'); |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 345 | - * @return int |
|
| 346 | - */ |
|
| 343 | + /** |
|
| 344 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 345 | + * @return int |
|
| 346 | + */ |
|
| 347 | 347 | public function getPort() : int |
| 348 | 348 | { |
| 349 | 349 | $port = $this->getInfoKey('port'); |
@@ -354,13 +354,13 @@ discard block |
||
| 354 | 354 | return -1; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * Retrieves the raw query string, or an empty string if none is present. |
|
| 359 | - * |
|
| 360 | - * @return string |
|
| 361 | - * |
|
| 362 | - * @see URLInfo::getParams() |
|
| 363 | - */ |
|
| 357 | + /** |
|
| 358 | + * Retrieves the raw query string, or an empty string if none is present. |
|
| 359 | + * |
|
| 360 | + * @return string |
|
| 361 | + * |
|
| 362 | + * @see URLInfo::getParams() |
|
| 363 | + */ |
|
| 364 | 364 | public function getQuery() : string |
| 365 | 365 | { |
| 366 | 366 | return $this->getInfoKey('query'); |
@@ -376,20 +376,20 @@ discard block |
||
| 376 | 376 | return $this->getInfoKey('pass'); |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Whether the URL contains a port number. |
|
| 381 | - * @return bool |
|
| 382 | - */ |
|
| 379 | + /** |
|
| 380 | + * Whether the URL contains a port number. |
|
| 381 | + * @return bool |
|
| 382 | + */ |
|
| 383 | 383 | public function hasPort() : bool |
| 384 | 384 | { |
| 385 | 385 | return $this->getPort() !== -1; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | - /** |
|
| 389 | - * Alias for the hasParams() method. |
|
| 390 | - * @return bool |
|
| 391 | - * @see URLInfo::hasParams() |
|
| 392 | - */ |
|
| 388 | + /** |
|
| 389 | + * Alias for the hasParams() method. |
|
| 390 | + * @return bool |
|
| 391 | + * @see URLInfo::hasParams() |
|
| 392 | + */ |
|
| 393 | 393 | public function hasQuery() : bool |
| 394 | 394 | { |
| 395 | 395 | return $this->hasParams(); |
@@ -470,25 +470,25 @@ discard block |
||
| 470 | 470 | return $normalized; |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - /** |
|
| 474 | - * Creates a hash of the URL, which can be used for comparisons. |
|
| 475 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
| 476 | - * the same links with a different parameter order will have the |
|
| 477 | - * same hash. |
|
| 478 | - * |
|
| 479 | - * @return string |
|
| 480 | - */ |
|
| 473 | + /** |
|
| 474 | + * Creates a hash of the URL, which can be used for comparisons. |
|
| 475 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
| 476 | + * the same links with a different parameter order will have the |
|
| 477 | + * same hash. |
|
| 478 | + * |
|
| 479 | + * @return string |
|
| 480 | + */ |
|
| 481 | 481 | public function getHash() |
| 482 | 482 | { |
| 483 | 483 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - /** |
|
| 487 | - * Highlights the URL using HTML tags with specific highlighting |
|
| 488 | - * class names. |
|
| 489 | - * |
|
| 490 | - * @return string Will return an empty string if the URL is not valid. |
|
| 491 | - */ |
|
| 486 | + /** |
|
| 487 | + * Highlights the URL using HTML tags with specific highlighting |
|
| 488 | + * class names. |
|
| 489 | + * |
|
| 490 | + * @return string Will return an empty string if the URL is not valid. |
|
| 491 | + */ |
|
| 492 | 492 | public function getHighlighted() : string |
| 493 | 493 | { |
| 494 | 494 | if(!$this->isValid) { |
@@ -670,15 +670,15 @@ discard block |
||
| 670 | 670 | return count($params); |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | - /** |
|
| 674 | - * Retrieves all parameters specified in the url, |
|
| 675 | - * if any, as an associative array. |
|
| 676 | - * |
|
| 677 | - * NOTE: Ignores parameters that have been added |
|
| 678 | - * to the excluded parameters list. |
|
| 679 | - * |
|
| 680 | - * @return array |
|
| 681 | - */ |
|
| 673 | + /** |
|
| 674 | + * Retrieves all parameters specified in the url, |
|
| 675 | + * if any, as an associative array. |
|
| 676 | + * |
|
| 677 | + * NOTE: Ignores parameters that have been added |
|
| 678 | + * to the excluded parameters list. |
|
| 679 | + * |
|
| 680 | + * @return array |
|
| 681 | + */ |
|
| 682 | 682 | public function getParams() : array |
| 683 | 683 | { |
| 684 | 684 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -695,26 +695,26 @@ discard block |
||
| 695 | 695 | return $keep; |
| 696 | 696 | } |
| 697 | 697 | |
| 698 | - /** |
|
| 699 | - * Retrieves the names of all parameters present in the URL, if any. |
|
| 700 | - * @return string[] |
|
| 701 | - */ |
|
| 698 | + /** |
|
| 699 | + * Retrieves the names of all parameters present in the URL, if any. |
|
| 700 | + * @return string[] |
|
| 701 | + */ |
|
| 702 | 702 | public function getParamNames() : array |
| 703 | 703 | { |
| 704 | 704 | $params = $this->getParams(); |
| 705 | 705 | return array_keys($params); |
| 706 | 706 | } |
| 707 | 707 | |
| 708 | - /** |
|
| 709 | - * Excludes an URL parameter entirely if present: |
|
| 710 | - * the parser will act as if the parameter was not |
|
| 711 | - * even present in the source URL, effectively |
|
| 712 | - * stripping it. |
|
| 713 | - * |
|
| 714 | - * @param string $name |
|
| 715 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 716 | - * @return URLInfo |
|
| 717 | - */ |
|
| 708 | + /** |
|
| 709 | + * Excludes an URL parameter entirely if present: |
|
| 710 | + * the parser will act as if the parameter was not |
|
| 711 | + * even present in the source URL, effectively |
|
| 712 | + * stripping it. |
|
| 713 | + * |
|
| 714 | + * @param string $name |
|
| 715 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 716 | + * @return URLInfo |
|
| 717 | + */ |
|
| 718 | 718 | public function excludeParam(string $name, string $reason) : URLInfo |
| 719 | 719 | { |
| 720 | 720 | if(!isset($this->excludedParams[$name])) |
@@ -779,25 +779,25 @@ discard block |
||
| 779 | 779 | return self::$typeLabels[$this->getType()]; |
| 780 | 780 | } |
| 781 | 781 | |
| 782 | - /** |
|
| 783 | - * Whether excluded parameters should be highlighted in |
|
| 784 | - * a different color in the URL when using the |
|
| 785 | - * {@link URLInfo::getHighlighted()} method. |
|
| 786 | - * |
|
| 787 | - * @param bool $highlight |
|
| 788 | - * @return URLInfo |
|
| 789 | - */ |
|
| 782 | + /** |
|
| 783 | + * Whether excluded parameters should be highlighted in |
|
| 784 | + * a different color in the URL when using the |
|
| 785 | + * {@link URLInfo::getHighlighted()} method. |
|
| 786 | + * |
|
| 787 | + * @param bool $highlight |
|
| 788 | + * @return URLInfo |
|
| 789 | + */ |
|
| 790 | 790 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
| 791 | 791 | { |
| 792 | 792 | $this->highlightExcluded = $highlight; |
| 793 | 793 | return $this; |
| 794 | 794 | } |
| 795 | 795 | |
| 796 | - /** |
|
| 797 | - * Returns an array with all relevant URL information. |
|
| 798 | - * |
|
| 799 | - * @return array |
|
| 800 | - */ |
|
| 796 | + /** |
|
| 797 | + * Returns an array with all relevant URL information. |
|
| 798 | + * |
|
| 799 | + * @return array |
|
| 800 | + */ |
|
| 801 | 801 | public function toArray() : array |
| 802 | 802 | { |
| 803 | 803 | return array( |
@@ -841,24 +841,24 @@ discard block |
||
| 841 | 841 | return $this; |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | - /** |
|
| 845 | - * Whether the parameter exclusion mode is enabled: |
|
| 846 | - * In this case, if any parameters have been added to the |
|
| 847 | - * exclusion list, all relevant methods will exclude these. |
|
| 848 | - * |
|
| 849 | - * @return bool |
|
| 850 | - */ |
|
| 844 | + /** |
|
| 845 | + * Whether the parameter exclusion mode is enabled: |
|
| 846 | + * In this case, if any parameters have been added to the |
|
| 847 | + * exclusion list, all relevant methods will exclude these. |
|
| 848 | + * |
|
| 849 | + * @return bool |
|
| 850 | + */ |
|
| 851 | 851 | public function isParamExclusionEnabled() : bool |
| 852 | 852 | { |
| 853 | 853 | return $this->paramExclusion; |
| 854 | 854 | } |
| 855 | 855 | |
| 856 | - /** |
|
| 857 | - * Checks whether the link contains any parameters that |
|
| 858 | - * are on the list of excluded parameters. |
|
| 859 | - * |
|
| 860 | - * @return bool |
|
| 861 | - */ |
|
| 856 | + /** |
|
| 857 | + * Checks whether the link contains any parameters that |
|
| 858 | + * are on the list of excluded parameters. |
|
| 859 | + * |
|
| 860 | + * @return bool |
|
| 861 | + */ |
|
| 862 | 862 | public function containsExcludedParams() : bool |
| 863 | 863 | { |
| 864 | 864 | if(empty($this->excludedParams)) { |
@@ -36,17 +36,17 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | protected $classes = array(); |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * The namespace detected in the file, if any. |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 39 | + /** |
|
| 40 | + * The namespace detected in the file, if any. |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | 43 | protected $namespace = ''; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @param string $path The path to the PHP file to parse. |
|
| 47 | - * @throws FileHelper_Exception |
|
| 48 | - * @see FileHelper::findPHPClasses() |
|
| 49 | - */ |
|
| 45 | + /** |
|
| 46 | + * @param string $path The path to the PHP file to parse. |
|
| 47 | + * @throws FileHelper_Exception |
|
| 48 | + * @see FileHelper::findPHPClasses() |
|
| 49 | + */ |
|
| 50 | 50 | public function __construct(string $path) |
| 51 | 51 | { |
| 52 | 52 | $this->path = realpath($path); |
@@ -66,66 +66,66 @@ discard block |
||
| 66 | 66 | $this->parseFile(); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * The name of the namespace of the classes in the file, if any. |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 69 | + /** |
|
| 70 | + * The name of the namespace of the classes in the file, if any. |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | 73 | public function getNamespace() : string |
| 74 | 74 | { |
| 75 | 75 | return $this->namespace; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Whether the file contains a namespace. |
|
| 80 | - * @return bool |
|
| 81 | - */ |
|
| 78 | + /** |
|
| 79 | + * Whether the file contains a namespace. |
|
| 80 | + * @return bool |
|
| 81 | + */ |
|
| 82 | 82 | public function hasNamespace() : bool |
| 83 | 83 | { |
| 84 | 84 | return !empty($this->namespace); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * The absolute path to the file. |
|
| 89 | - * @return string |
|
| 90 | - */ |
|
| 87 | + /** |
|
| 88 | + * The absolute path to the file. |
|
| 89 | + * @return string |
|
| 90 | + */ |
|
| 91 | 91 | public function getPath() : string |
| 92 | 92 | { |
| 93 | 93 | return $this->path; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Whether any classes were found in the file. |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 96 | + /** |
|
| 97 | + * Whether any classes were found in the file. |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | 100 | public function hasClasses() : bool |
| 101 | 101 | { |
| 102 | 102 | return !empty($this->classes); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * The names of the classes that were found in the file (with namespace if any). |
|
| 107 | - * @return string[] |
|
| 108 | - */ |
|
| 105 | + /** |
|
| 106 | + * The names of the classes that were found in the file (with namespace if any). |
|
| 107 | + * @return string[] |
|
| 108 | + */ |
|
| 109 | 109 | public function getClassNames() : array |
| 110 | 110 | { |
| 111 | 111 | return array_keys($this->classes); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Retrieves all classes that were detected in the file, |
|
| 116 | - * which can be used to retrieve more information about |
|
| 117 | - * them. |
|
| 118 | - * |
|
| 119 | - * @return FileHelper_PHPClassInfo_Class[] |
|
| 120 | - */ |
|
| 114 | + /** |
|
| 115 | + * Retrieves all classes that were detected in the file, |
|
| 116 | + * which can be used to retrieve more information about |
|
| 117 | + * them. |
|
| 118 | + * |
|
| 119 | + * @return FileHelper_PHPClassInfo_Class[] |
|
| 120 | + */ |
|
| 121 | 121 | public function getClasses() |
| 122 | 122 | { |
| 123 | 123 | return $this->classes; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * @throws FileHelper_Exception |
|
| 128 | - */ |
|
| 126 | + /** |
|
| 127 | + * @throws FileHelper_Exception |
|
| 128 | + */ |
|
| 129 | 129 | protected function parseFile() |
| 130 | 130 | { |
| 131 | 131 | $code = file_get_contents($this->path); |
@@ -180,13 +180,13 @@ discard block |
||
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Strips all whitespace from the string, replacing it with |
|
| 185 | - * regular spaces (newlines, tabs, etc.). |
|
| 186 | - * |
|
| 187 | - * @param string $string |
|
| 188 | - * @return string |
|
| 189 | - */ |
|
| 183 | + /** |
|
| 184 | + * Strips all whitespace from the string, replacing it with |
|
| 185 | + * regular spaces (newlines, tabs, etc.). |
|
| 186 | + * |
|
| 187 | + * @param string $string |
|
| 188 | + * @return string |
|
| 189 | + */ |
|
| 190 | 190 | protected function stripWhitespace(string $string) : string |
| 191 | 191 | { |
| 192 | 192 | return preg_replace('/[\s]/', ' ', $string); |
@@ -12,9 +12,9 @@ |
||
| 12 | 12 | |
| 13 | 13 | const PATH_MODE_STRIP = 'strip'; |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @var string |
|
| 17 | - */ |
|
| 15 | + /** |
|
| 16 | + * @var string |
|
| 17 | + */ |
|
| 18 | 18 | protected $path; |
| 19 | 19 | |
| 20 | 20 | protected $options = array( |
@@ -22,51 +22,51 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class FileHelper_PHPClassInfo_Class |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var FileHelper_PHPClassInfo |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var FileHelper_PHPClassInfo |
|
| 27 | + */ |
|
| 28 | 28 | protected $info; |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var bool |
|
| 32 | - */ |
|
| 30 | + /** |
|
| 31 | + * @var bool |
|
| 32 | + */ |
|
| 33 | 33 | protected $abstract = false; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var bool |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var bool |
|
| 37 | + */ |
|
| 38 | 38 | protected $final = false; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | 43 | protected $extends = ''; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string[] |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string[] |
|
| 47 | + */ |
|
| 48 | 48 | protected $implements = array(); |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | 53 | protected $name; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | 58 | protected $declaration; |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 60 | + /** |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | 63 | protected $keyword; |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param FileHelper_PHPClassInfo $info The class info instance. |
|
| 67 | - * @param string $declaration The full class declaration, e.g. "class SomeName extends SomeOtherClass". |
|
| 68 | - * @param string $keyword The class keyword, if any, i.e. "abstract" or "final". |
|
| 69 | - */ |
|
| 65 | + /** |
|
| 66 | + * @param FileHelper_PHPClassInfo $info The class info instance. |
|
| 67 | + * @param string $declaration The full class declaration, e.g. "class SomeName extends SomeOtherClass". |
|
| 68 | + * @param string $keyword The class keyword, if any, i.e. "abstract" or "final". |
|
| 69 | + */ |
|
| 70 | 70 | public function __construct(FileHelper_PHPClassInfo $info, string $declaration, string $keyword) |
| 71 | 71 | { |
| 72 | 72 | $this->info = $info; |
@@ -76,31 +76,31 @@ discard block |
||
| 76 | 76 | $this->analyzeCode(); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Check if this class is a subclass of the specified |
|
| 81 | - * class name. |
|
| 82 | - * |
|
| 83 | - * @param string $className |
|
| 84 | - * @return bool |
|
| 85 | - */ |
|
| 79 | + /** |
|
| 80 | + * Check if this class is a subclass of the specified |
|
| 81 | + * class name. |
|
| 82 | + * |
|
| 83 | + * @param string $className |
|
| 84 | + * @return bool |
|
| 85 | + */ |
|
| 86 | 86 | public function isSublassOf(string $className) : bool |
| 87 | 87 | { |
| 88 | 88 | return is_subclass_of($this->getNameNS(), $className); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * The class name without namespace. |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 91 | + /** |
|
| 92 | + * The class name without namespace. |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | 95 | public function getName() : string |
| 96 | 96 | { |
| 97 | 97 | return $this->name; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * The absolute class name with namespace (if any). |
|
| 102 | - * @return string |
|
| 103 | - */ |
|
| 100 | + /** |
|
| 101 | + * The absolute class name with namespace (if any). |
|
| 102 | + * @return string |
|
| 103 | + */ |
|
| 104 | 104 | public function getNameNS() : string |
| 105 | 105 | { |
| 106 | 106 | $name = $this->getName(); |
@@ -112,48 +112,48 @@ discard block |
||
| 112 | 112 | return $name; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Whether it is an abstract class. |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 115 | + /** |
|
| 116 | + * Whether it is an abstract class. |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | 119 | public function isAbstract() : bool |
| 120 | 120 | { |
| 121 | 121 | return $this->abstract; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Whether it is a final class. |
|
| 126 | - * @return bool |
|
| 127 | - */ |
|
| 124 | + /** |
|
| 125 | + * Whether it is a final class. |
|
| 126 | + * @return bool |
|
| 127 | + */ |
|
| 128 | 128 | public function isFinal() : bool |
| 129 | 129 | { |
| 130 | 130 | return $this->final; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * The name of the class that this class extends (with namespace, if specified). |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 133 | + /** |
|
| 134 | + * The name of the class that this class extends (with namespace, if specified). |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | 137 | public function getExtends() : string |
| 138 | 138 | { |
| 139 | 139 | return $this->extends; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * A list of interfaces the class implements, if any. |
|
| 144 | - * @return array |
|
| 145 | - */ |
|
| 142 | + /** |
|
| 143 | + * A list of interfaces the class implements, if any. |
|
| 144 | + * @return array |
|
| 145 | + */ |
|
| 146 | 146 | public function getImplements() : array |
| 147 | 147 | { |
| 148 | 148 | return $this->implements; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * The class declaration string, with normalized spaces and sorted interface names. |
|
| 153 | - * NOTE: does not include the keyword "abstract" or "final". |
|
| 154 | - * |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 151 | + /** |
|
| 152 | + * The class declaration string, with normalized spaces and sorted interface names. |
|
| 153 | + * NOTE: does not include the keyword "abstract" or "final". |
|
| 154 | + * |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | 157 | public function getDeclaration() : string |
| 158 | 158 | { |
| 159 | 159 | $parts = array(); |
@@ -173,10 +173,10 @@ discard block |
||
| 173 | 173 | return implode(' ', $parts); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * The keyword before "class", e.g. "abstract". |
|
| 178 | - * @return string |
|
| 179 | - */ |
|
| 176 | + /** |
|
| 177 | + * The keyword before "class", e.g. "abstract". |
|
| 178 | + * @return string |
|
| 179 | + */ |
|
| 180 | 180 | public function getKeyword() : string |
| 181 | 181 | { |
| 182 | 182 | return $this->keyword; |
@@ -58,32 +58,32 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | const ERROR_CANNOT_READ_FILE_CONTENTS = 340028; |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Opens a serialized file and returns the unserialized data. |
|
| 63 | - * |
|
| 64 | - * @param string $file |
|
| 65 | - * @throws FileHelper_Exception |
|
| 66 | - * @return array |
|
| 67 | - * @deprecated Use parseSerializedFile() instead. |
|
| 68 | - * @see FileHelper::parseSerializedFile() |
|
| 69 | - */ |
|
| 61 | + /** |
|
| 62 | + * Opens a serialized file and returns the unserialized data. |
|
| 63 | + * |
|
| 64 | + * @param string $file |
|
| 65 | + * @throws FileHelper_Exception |
|
| 66 | + * @return array |
|
| 67 | + * @deprecated Use parseSerializedFile() instead. |
|
| 68 | + * @see FileHelper::parseSerializedFile() |
|
| 69 | + */ |
|
| 70 | 70 | public static function openUnserialized(string $file) : array |
| 71 | 71 | { |
| 72 | 72 | return self::parseSerializedFile($file); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Opens a serialized file and returns the unserialized data. |
|
| 77 | - * |
|
| 78 | - * @param string $file |
|
| 79 | - * @throws FileHelper_Exception |
|
| 80 | - * @return array |
|
| 81 | - * @see FileHelper::parseSerializedFile() |
|
| 82 | - * |
|
| 83 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 84 | - * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
| 85 | - * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
| 86 | - */ |
|
| 75 | + /** |
|
| 76 | + * Opens a serialized file and returns the unserialized data. |
|
| 77 | + * |
|
| 78 | + * @param string $file |
|
| 79 | + * @throws FileHelper_Exception |
|
| 80 | + * @return array |
|
| 81 | + * @see FileHelper::parseSerializedFile() |
|
| 82 | + * |
|
| 83 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 84 | + * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
| 85 | + * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
| 86 | + */ |
|
| 87 | 87 | public static function parseSerializedFile(string $file) |
| 88 | 88 | { |
| 89 | 89 | self::requireFileExists($file); |
@@ -152,13 +152,13 @@ discard block |
||
| 152 | 152 | return rmdir($rootFolder); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Create a folder, if it does not exist yet. |
|
| 157 | - * |
|
| 158 | - * @param string $path |
|
| 159 | - * @throws FileHelper_Exception |
|
| 160 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 161 | - */ |
|
| 155 | + /** |
|
| 156 | + * Create a folder, if it does not exist yet. |
|
| 157 | + * |
|
| 158 | + * @param string $path |
|
| 159 | + * @throws FileHelper_Exception |
|
| 160 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 161 | + */ |
|
| 162 | 162 | public static function createFolder($path) |
| 163 | 163 | { |
| 164 | 164 | if(is_dir($path) || mkdir($path, 0777, true)) { |
@@ -205,22 +205,22 @@ discard block |
||
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Copies a file to the target location. Includes checks |
|
| 210 | - * for most error sources, like the source file not being |
|
| 211 | - * readable. Automatically creates the target folder if it |
|
| 212 | - * does not exist yet. |
|
| 213 | - * |
|
| 214 | - * @param string $sourcePath |
|
| 215 | - * @param string $targetPath |
|
| 216 | - * @throws FileHelper_Exception |
|
| 217 | - * |
|
| 218 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 219 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
| 220 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
| 221 | - * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
| 222 | - * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
| 223 | - */ |
|
| 208 | + /** |
|
| 209 | + * Copies a file to the target location. Includes checks |
|
| 210 | + * for most error sources, like the source file not being |
|
| 211 | + * readable. Automatically creates the target folder if it |
|
| 212 | + * does not exist yet. |
|
| 213 | + * |
|
| 214 | + * @param string $sourcePath |
|
| 215 | + * @param string $targetPath |
|
| 216 | + * @throws FileHelper_Exception |
|
| 217 | + * |
|
| 218 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 219 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
| 220 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
| 221 | + * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
| 222 | + * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
| 223 | + */ |
|
| 224 | 224 | public static function copyFile($sourcePath, $targetPath) |
| 225 | 225 | { |
| 226 | 226 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
@@ -271,15 +271,15 @@ discard block |
||
| 271 | 271 | ); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | - /** |
|
| 275 | - * Deletes the target file. Ignored if it cannot be found, |
|
| 276 | - * and throws an exception if it fails. |
|
| 277 | - * |
|
| 278 | - * @param string $filePath |
|
| 279 | - * @throws FileHelper_Exception |
|
| 280 | - * |
|
| 281 | - * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
| 282 | - */ |
|
| 274 | + /** |
|
| 275 | + * Deletes the target file. Ignored if it cannot be found, |
|
| 276 | + * and throws an exception if it fails. |
|
| 277 | + * |
|
| 278 | + * @param string $filePath |
|
| 279 | + * @throws FileHelper_Exception |
|
| 280 | + * |
|
| 281 | + * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
| 282 | + */ |
|
| 283 | 283 | public static function deleteFile(string $filePath) : void |
| 284 | 284 | { |
| 285 | 285 | if(!file_exists($filePath)) { |
@@ -301,13 +301,13 @@ discard block |
||
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
| 304 | - * Creates a new CSV parser instance and returns it. |
|
| 305 | - * @param string $delimiter |
|
| 306 | - * @param string $enclosure |
|
| 307 | - * @param string $escape |
|
| 308 | - * @param string $heading |
|
| 309 | - * @return \parseCSV |
|
| 310 | - */ |
|
| 304 | + * Creates a new CSV parser instance and returns it. |
|
| 305 | + * @param string $delimiter |
|
| 306 | + * @param string $enclosure |
|
| 307 | + * @param string $escape |
|
| 308 | + * @param string $heading |
|
| 309 | + * @return \parseCSV |
|
| 310 | + */ |
|
| 311 | 311 | public static function createCSVParser($delimiter = ';', $enclosure = '"', $escape = '\\', $heading=false) |
| 312 | 312 | { |
| 313 | 313 | if($delimiter===null) { $delimiter = ';'; } |
@@ -481,31 +481,31 @@ discard block |
||
| 481 | 481 | return $output; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - /** |
|
| 485 | - * Verifies whether the target file is a PHP file. The path |
|
| 486 | - * to the file can be a path to a file as a string, or a |
|
| 487 | - * DirectoryIterator object instance. |
|
| 488 | - * |
|
| 489 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
| 490 | - * @return boolean |
|
| 491 | - */ |
|
| 484 | + /** |
|
| 485 | + * Verifies whether the target file is a PHP file. The path |
|
| 486 | + * to the file can be a path to a file as a string, or a |
|
| 487 | + * DirectoryIterator object instance. |
|
| 488 | + * |
|
| 489 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
| 490 | + * @return boolean |
|
| 491 | + */ |
|
| 492 | 492 | public static function isPHPFile($pathOrDirIterator) |
| 493 | 493 | { |
| 494 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
| 495 | - return true; |
|
| 496 | - } |
|
| 494 | + if(self::getExtension($pathOrDirIterator) == 'php') { |
|
| 495 | + return true; |
|
| 496 | + } |
|
| 497 | 497 | |
| 498 | - return false; |
|
| 498 | + return false; |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - /** |
|
| 502 | - * Retrieves the extension of the specified file. Can be a path |
|
| 503 | - * to a file as a string, or a DirectoryIterator object instance. |
|
| 504 | - * |
|
| 505 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
| 506 | - * @param bool $lowercase |
|
| 507 | - * @return string |
|
| 508 | - */ |
|
| 501 | + /** |
|
| 502 | + * Retrieves the extension of the specified file. Can be a path |
|
| 503 | + * to a file as a string, or a DirectoryIterator object instance. |
|
| 504 | + * |
|
| 505 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
| 506 | + * @param bool $lowercase |
|
| 507 | + * @return string |
|
| 508 | + */ |
|
| 509 | 509 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
| 510 | 510 | { |
| 511 | 511 | if($pathOrDirIterator instanceof \DirectoryIterator) { |
@@ -516,51 +516,51 @@ discard block |
||
| 516 | 516 | |
| 517 | 517 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
| 518 | 518 | if($lowercase) { |
| 519 | - $ext = mb_strtolower($ext); |
|
| 519 | + $ext = mb_strtolower($ext); |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | return $ext; |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | - /** |
|
| 526 | - * Retrieves the file name from a path, with or without extension. |
|
| 527 | - * The path to the file can be a string, or a DirectoryIterator object |
|
| 528 | - * instance. |
|
| 529 | - * |
|
| 530 | - * In case of folders, behaves like the pathinfo function: returns |
|
| 531 | - * the name of the folder. |
|
| 532 | - * |
|
| 533 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
| 534 | - * @param bool $extension |
|
| 535 | - * @return string |
|
| 536 | - */ |
|
| 525 | + /** |
|
| 526 | + * Retrieves the file name from a path, with or without extension. |
|
| 527 | + * The path to the file can be a string, or a DirectoryIterator object |
|
| 528 | + * instance. |
|
| 529 | + * |
|
| 530 | + * In case of folders, behaves like the pathinfo function: returns |
|
| 531 | + * the name of the folder. |
|
| 532 | + * |
|
| 533 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
| 534 | + * @param bool $extension |
|
| 535 | + * @return string |
|
| 536 | + */ |
|
| 537 | 537 | public static function getFilename($pathOrDirIterator, $extension = true) |
| 538 | 538 | { |
| 539 | 539 | $path = $pathOrDirIterator; |
| 540 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 541 | - $path = $pathOrDirIterator->getFilename(); |
|
| 542 | - } |
|
| 540 | + if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
| 541 | + $path = $pathOrDirIterator->getFilename(); |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - $path = self::normalizePath($path); |
|
| 544 | + $path = self::normalizePath($path); |
|
| 545 | 545 | |
| 546 | - if(!$extension) { |
|
| 547 | - return pathinfo($path, PATHINFO_FILENAME); |
|
| 548 | - } |
|
| 546 | + if(!$extension) { |
|
| 547 | + return pathinfo($path, PATHINFO_FILENAME); |
|
| 548 | + } |
|
| 549 | 549 | |
| 550 | - return pathinfo($path, PATHINFO_BASENAME); |
|
| 550 | + return pathinfo($path, PATHINFO_BASENAME); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - /** |
|
| 554 | - * Tries to read the contents of the target file and |
|
| 555 | - * treat it as JSON to return the decoded JSON data. |
|
| 556 | - * |
|
| 557 | - * @param string $file |
|
| 558 | - * @throws FileHelper_Exception |
|
| 559 | - * @return array |
|
| 560 | - * |
|
| 561 | - * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
|
| 562 | - * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
|
| 563 | - */ |
|
| 553 | + /** |
|
| 554 | + * Tries to read the contents of the target file and |
|
| 555 | + * treat it as JSON to return the decoded JSON data. |
|
| 556 | + * |
|
| 557 | + * @param string $file |
|
| 558 | + * @throws FileHelper_Exception |
|
| 559 | + * @return array |
|
| 560 | + * |
|
| 561 | + * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
|
| 562 | + * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
|
| 563 | + */ |
|
| 564 | 564 | public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
| 565 | 565 | { |
| 566 | 566 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
@@ -596,16 +596,16 @@ discard block |
||
| 596 | 596 | return $json; |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - /** |
|
| 600 | - * Corrects common formatting mistakes when users enter |
|
| 601 | - * file names, like too many spaces, dots and the like. |
|
| 602 | - * |
|
| 603 | - * NOTE: if the file name contains a path, the path is |
|
| 604 | - * stripped, leaving only the file name. |
|
| 605 | - * |
|
| 606 | - * @param string $name |
|
| 607 | - * @return string |
|
| 608 | - */ |
|
| 599 | + /** |
|
| 600 | + * Corrects common formatting mistakes when users enter |
|
| 601 | + * file names, like too many spaces, dots and the like. |
|
| 602 | + * |
|
| 603 | + * NOTE: if the file name contains a path, the path is |
|
| 604 | + * stripped, leaving only the file name. |
|
| 605 | + * |
|
| 606 | + * @param string $name |
|
| 607 | + * @return string |
|
| 608 | + */ |
|
| 609 | 609 | public static function fixFileName(string $name) : string |
| 610 | 610 | { |
| 611 | 611 | $name = trim($name); |
@@ -635,40 +635,40 @@ discard block |
||
| 635 | 635 | return $name; |
| 636 | 636 | } |
| 637 | 637 | |
| 638 | - /** |
|
| 639 | - * Creates an instance of the file finder, which is an easier |
|
| 640 | - * alternative to the other manual findFile methods, since all |
|
| 641 | - * options can be set by chaining. |
|
| 642 | - * |
|
| 643 | - * @param string $path |
|
| 644 | - * @return FileHelper_FileFinder |
|
| 645 | - */ |
|
| 638 | + /** |
|
| 639 | + * Creates an instance of the file finder, which is an easier |
|
| 640 | + * alternative to the other manual findFile methods, since all |
|
| 641 | + * options can be set by chaining. |
|
| 642 | + * |
|
| 643 | + * @param string $path |
|
| 644 | + * @return FileHelper_FileFinder |
|
| 645 | + */ |
|
| 646 | 646 | public static function createFileFinder(string $path) : FileHelper_FileFinder |
| 647 | 647 | { |
| 648 | 648 | return new FileHelper_FileFinder($path); |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - /** |
|
| 652 | - * Searches for all HTML files in the target folder. |
|
| 653 | - * |
|
| 654 | - * @param string $targetFolder |
|
| 655 | - * @param array $options |
|
| 656 | - * @return string[] |
|
| 657 | - * @see FileHelper::createFileFinder() |
|
| 658 | - */ |
|
| 651 | + /** |
|
| 652 | + * Searches for all HTML files in the target folder. |
|
| 653 | + * |
|
| 654 | + * @param string $targetFolder |
|
| 655 | + * @param array $options |
|
| 656 | + * @return string[] |
|
| 657 | + * @see FileHelper::createFileFinder() |
|
| 658 | + */ |
|
| 659 | 659 | public static function findHTMLFiles($targetFolder, $options=array()) |
| 660 | 660 | { |
| 661 | 661 | return self::findFiles($targetFolder, array('html'), $options); |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | - /** |
|
| 665 | - * Searches for all PHP files in the target folder. |
|
| 666 | - * |
|
| 667 | - * @param string $targetFolder |
|
| 668 | - * @param array $options |
|
| 669 | - * @return string[] |
|
| 670 | - * @see FileHelper::createFileFinder() |
|
| 671 | - */ |
|
| 664 | + /** |
|
| 665 | + * Searches for all PHP files in the target folder. |
|
| 666 | + * |
|
| 667 | + * @param string $targetFolder |
|
| 668 | + * @param array $options |
|
| 669 | + * @return string[] |
|
| 670 | + * @see FileHelper::createFileFinder() |
|
| 671 | + */ |
|
| 672 | 672 | public static function findPHPFiles($targetFolder, $options=array()) |
| 673 | 673 | { |
| 674 | 674 | return self::findFiles($targetFolder, array('php'), $options); |
@@ -754,13 +754,13 @@ discard block |
||
| 754 | 754 | return $files; |
| 755 | 755 | } |
| 756 | 756 | |
| 757 | - /** |
|
| 758 | - * Removes the extension from the specified path or file name, |
|
| 759 | - * if any, and returns the name without the extension. |
|
| 760 | - * |
|
| 761 | - * @param string $filename |
|
| 762 | - * @return sTring |
|
| 763 | - */ |
|
| 757 | + /** |
|
| 758 | + * Removes the extension from the specified path or file name, |
|
| 759 | + * if any, and returns the name without the extension. |
|
| 760 | + * |
|
| 761 | + * @param string $filename |
|
| 762 | + * @return sTring |
|
| 763 | + */ |
|
| 764 | 764 | public static function removeExtension(string $filename) : string |
| 765 | 765 | { |
| 766 | 766 | // normalize paths to allow windows style slashes even on nix servers |
@@ -769,22 +769,22 @@ discard block |
||
| 769 | 769 | return pathinfo($filename, PATHINFO_FILENAME); |
| 770 | 770 | } |
| 771 | 771 | |
| 772 | - /** |
|
| 773 | - * Detects the UTF BOM in the target file, if any. Returns |
|
| 774 | - * the encoding matching the BOM, which can be any of the |
|
| 775 | - * following: |
|
| 776 | - * |
|
| 777 | - * <ul> |
|
| 778 | - * <li>UTF32-BE</li> |
|
| 779 | - * <li>UTF32-LE</li> |
|
| 780 | - * <li>UTF16-BE</li> |
|
| 781 | - * <li>UTF16-LE</li> |
|
| 782 | - * <li>UTF8</li> |
|
| 783 | - * </ul> |
|
| 784 | - * |
|
| 785 | - * @param string $filename |
|
| 786 | - * @return string|NULL |
|
| 787 | - */ |
|
| 772 | + /** |
|
| 773 | + * Detects the UTF BOM in the target file, if any. Returns |
|
| 774 | + * the encoding matching the BOM, which can be any of the |
|
| 775 | + * following: |
|
| 776 | + * |
|
| 777 | + * <ul> |
|
| 778 | + * <li>UTF32-BE</li> |
|
| 779 | + * <li>UTF32-LE</li> |
|
| 780 | + * <li>UTF16-BE</li> |
|
| 781 | + * <li>UTF16-LE</li> |
|
| 782 | + * <li>UTF8</li> |
|
| 783 | + * </ul> |
|
| 784 | + * |
|
| 785 | + * @param string $filename |
|
| 786 | + * @return string|NULL |
|
| 787 | + */ |
|
| 788 | 788 | public static function detectUTFBom(string $filename) |
| 789 | 789 | { |
| 790 | 790 | $fp = fopen($filename, 'r'); |
@@ -804,13 +804,13 @@ discard block |
||
| 804 | 804 | |
| 805 | 805 | protected static $utfBoms; |
| 806 | 806 | |
| 807 | - /** |
|
| 808 | - * Retrieves a list of all UTF byte order mark character |
|
| 809 | - * sequences, as an assocative array with UTF encoding => bom sequence |
|
| 810 | - * pairs. |
|
| 811 | - * |
|
| 812 | - * @return array |
|
| 813 | - */ |
|
| 807 | + /** |
|
| 808 | + * Retrieves a list of all UTF byte order mark character |
|
| 809 | + * sequences, as an assocative array with UTF encoding => bom sequence |
|
| 810 | + * pairs. |
|
| 811 | + * |
|
| 812 | + * @return array |
|
| 813 | + */ |
|
| 814 | 814 | public static function getUTFBOMs() |
| 815 | 815 | { |
| 816 | 816 | if(!isset(self::$utfBoms)) { |
@@ -826,15 +826,15 @@ discard block |
||
| 826 | 826 | return self::$utfBoms; |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | - /** |
|
| 830 | - * Checks whether the specified encoding is a valid |
|
| 831 | - * unicode encoding, for example "UTF16-LE" or "UTF8". |
|
| 832 | - * Also accounts for alternate way to write the, like |
|
| 833 | - * "UTF-8", and omitting little/big endian suffixes. |
|
| 834 | - * |
|
| 835 | - * @param string $encoding |
|
| 836 | - * @return boolean |
|
| 837 | - */ |
|
| 829 | + /** |
|
| 830 | + * Checks whether the specified encoding is a valid |
|
| 831 | + * unicode encoding, for example "UTF16-LE" or "UTF8". |
|
| 832 | + * Also accounts for alternate way to write the, like |
|
| 833 | + * "UTF-8", and omitting little/big endian suffixes. |
|
| 834 | + * |
|
| 835 | + * @param string $encoding |
|
| 836 | + * @return boolean |
|
| 837 | + */ |
|
| 838 | 838 | public static function isValidUnicodeEncoding(string $encoding) : bool |
| 839 | 839 | { |
| 840 | 840 | $encodings = self::getKnownUnicodeEncodings(); |
@@ -853,22 +853,22 @@ discard block |
||
| 853 | 853 | return in_array($encoding, $keep); |
| 854 | 854 | } |
| 855 | 855 | |
| 856 | - /** |
|
| 857 | - * Retrieves a list of all known unicode file encodings. |
|
| 858 | - * @return array |
|
| 859 | - */ |
|
| 856 | + /** |
|
| 857 | + * Retrieves a list of all known unicode file encodings. |
|
| 858 | + * @return array |
|
| 859 | + */ |
|
| 860 | 860 | public static function getKnownUnicodeEncodings() |
| 861 | 861 | { |
| 862 | 862 | return array_keys(self::getUTFBOMs()); |
| 863 | 863 | } |
| 864 | 864 | |
| 865 | - /** |
|
| 866 | - * Normalizes the slash style in a file or folder path, |
|
| 867 | - * by replacing any antislashes with forward slashes. |
|
| 868 | - * |
|
| 869 | - * @param string $path |
|
| 870 | - * @return string |
|
| 871 | - */ |
|
| 865 | + /** |
|
| 866 | + * Normalizes the slash style in a file or folder path, |
|
| 867 | + * by replacing any antislashes with forward slashes. |
|
| 868 | + * |
|
| 869 | + * @param string $path |
|
| 870 | + * @return string |
|
| 871 | + */ |
|
| 872 | 872 | public static function normalizePath($path) |
| 873 | 873 | { |
| 874 | 874 | if(is_string($path)) { |
@@ -905,18 +905,18 @@ discard block |
||
| 905 | 905 | } |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | - /** |
|
| 909 | - * Saves the specified content to the target file, creating |
|
| 910 | - * the file and the folder as necessary. |
|
| 911 | - * |
|
| 912 | - * @param string $filePath |
|
| 913 | - * @param string $content |
|
| 914 | - * @throws FileHelper_Exception |
|
| 915 | - * |
|
| 916 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 917 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 918 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 919 | - */ |
|
| 908 | + /** |
|
| 909 | + * Saves the specified content to the target file, creating |
|
| 910 | + * the file and the folder as necessary. |
|
| 911 | + * |
|
| 912 | + * @param string $filePath |
|
| 913 | + * @param string $content |
|
| 914 | + * @throws FileHelper_Exception |
|
| 915 | + * |
|
| 916 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 917 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 918 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 919 | + */ |
|
| 920 | 920 | public static function saveFile(string $filePath, string $content='') : void |
| 921 | 921 | { |
| 922 | 922 | // target file already exists |
@@ -969,12 +969,12 @@ discard block |
||
| 969 | 969 | ); |
| 970 | 970 | } |
| 971 | 971 | |
| 972 | - /** |
|
| 973 | - * Checks whether it is possible to run PHP command |
|
| 974 | - * line commands. |
|
| 975 | - * |
|
| 976 | - * @return boolean |
|
| 977 | - */ |
|
| 972 | + /** |
|
| 973 | + * Checks whether it is possible to run PHP command |
|
| 974 | + * line commands. |
|
| 975 | + * |
|
| 976 | + * @return boolean |
|
| 977 | + */ |
|
| 978 | 978 | public static function canMakePHPCalls() : bool |
| 979 | 979 | { |
| 980 | 980 | return self::cliCommandExists('php'); |
@@ -1049,16 +1049,16 @@ discard block |
||
| 1049 | 1049 | return $result; |
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | - /** |
|
| 1053 | - * Validates a PHP file's syntax. |
|
| 1054 | - * |
|
| 1055 | - * NOTE: This will fail silently if the PHP command line |
|
| 1056 | - * is not available. Use {@link FileHelper::canMakePHPCalls()} |
|
| 1057 | - * to check this beforehand as needed. |
|
| 1058 | - * |
|
| 1059 | - * @param string $path |
|
| 1060 | - * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise. |
|
| 1061 | - */ |
|
| 1052 | + /** |
|
| 1053 | + * Validates a PHP file's syntax. |
|
| 1054 | + * |
|
| 1055 | + * NOTE: This will fail silently if the PHP command line |
|
| 1056 | + * is not available. Use {@link FileHelper::canMakePHPCalls()} |
|
| 1057 | + * to check this beforehand as needed. |
|
| 1058 | + * |
|
| 1059 | + * @param string $path |
|
| 1060 | + * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise. |
|
| 1061 | + */ |
|
| 1062 | 1062 | public static function checkPHPFileSyntax($path) |
| 1063 | 1063 | { |
| 1064 | 1064 | if(!self::canMakePHPCalls()) { |
@@ -1082,14 +1082,14 @@ discard block |
||
| 1082 | 1082 | return $output; |
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | - /** |
|
| 1086 | - * Retrieves the last modified date for the specified file or folder. |
|
| 1087 | - * |
|
| 1088 | - * Note: If the target does not exist, returns null. |
|
| 1089 | - * |
|
| 1090 | - * @param string $path |
|
| 1091 | - * @return \DateTime|NULL |
|
| 1092 | - */ |
|
| 1085 | + /** |
|
| 1086 | + * Retrieves the last modified date for the specified file or folder. |
|
| 1087 | + * |
|
| 1088 | + * Note: If the target does not exist, returns null. |
|
| 1089 | + * |
|
| 1090 | + * @param string $path |
|
| 1091 | + * @return \DateTime|NULL |
|
| 1092 | + */ |
|
| 1093 | 1093 | public static function getModifiedDate($path) |
| 1094 | 1094 | { |
| 1095 | 1095 | $time = filemtime($path); |
@@ -1102,22 +1102,22 @@ discard block |
||
| 1102 | 1102 | return null; |
| 1103 | 1103 | } |
| 1104 | 1104 | |
| 1105 | - /** |
|
| 1106 | - * Retrieves the names of all subfolders in the specified path. |
|
| 1107 | - * |
|
| 1108 | - * Available options: |
|
| 1109 | - * |
|
| 1110 | - * - recursive: true/false |
|
| 1111 | - * Whether to search for subfolders recursively. |
|
| 1112 | - * |
|
| 1113 | - * - absolute-paths: true/false |
|
| 1114 | - * Whether to return a list of absolute paths. |
|
| 1115 | - * |
|
| 1116 | - * @param string $targetFolder |
|
| 1117 | - * @param array $options |
|
| 1118 | - * @throws FileHelper_Exception |
|
| 1119 | - * @return string[] |
|
| 1120 | - */ |
|
| 1105 | + /** |
|
| 1106 | + * Retrieves the names of all subfolders in the specified path. |
|
| 1107 | + * |
|
| 1108 | + * Available options: |
|
| 1109 | + * |
|
| 1110 | + * - recursive: true/false |
|
| 1111 | + * Whether to search for subfolders recursively. |
|
| 1112 | + * |
|
| 1113 | + * - absolute-paths: true/false |
|
| 1114 | + * Whether to return a list of absolute paths. |
|
| 1115 | + * |
|
| 1116 | + * @param string $targetFolder |
|
| 1117 | + * @param array $options |
|
| 1118 | + * @throws FileHelper_Exception |
|
| 1119 | + * @return string[] |
|
| 1120 | + */ |
|
| 1121 | 1121 | public static function getSubfolders($targetFolder, $options = array()) |
| 1122 | 1122 | { |
| 1123 | 1123 | if(!is_dir($targetFolder)) |
@@ -1178,16 +1178,16 @@ discard block |
||
| 1178 | 1178 | return $result; |
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | - /** |
|
| 1182 | - * Retrieves the maximum allowed upload file size, in bytes. |
|
| 1183 | - * Takes into account the PHP ini settings <code>post_max_size</code> |
|
| 1184 | - * and <code>upload_max_filesize</code>. Since these cannot |
|
| 1185 | - * be modified at runtime, they are the hard limits for uploads. |
|
| 1186 | - * |
|
| 1187 | - * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
| 1188 | - * |
|
| 1189 | - * @return int Will return <code>-1</code> if no limit. |
|
| 1190 | - */ |
|
| 1181 | + /** |
|
| 1182 | + * Retrieves the maximum allowed upload file size, in bytes. |
|
| 1183 | + * Takes into account the PHP ini settings <code>post_max_size</code> |
|
| 1184 | + * and <code>upload_max_filesize</code>. Since these cannot |
|
| 1185 | + * be modified at runtime, they are the hard limits for uploads. |
|
| 1186 | + * |
|
| 1187 | + * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
| 1188 | + * |
|
| 1189 | + * @return int Will return <code>-1</code> if no limit. |
|
| 1190 | + */ |
|
| 1191 | 1191 | public static function getMaxUploadFilesize() : int |
| 1192 | 1192 | { |
| 1193 | 1193 | static $max_size = -1; |
@@ -1224,16 +1224,16 @@ discard block |
||
| 1224 | 1224 | return round($size); |
| 1225 | 1225 | } |
| 1226 | 1226 | |
| 1227 | - /** |
|
| 1228 | - * Makes a path relative using a folder depth: will reduce the |
|
| 1229 | - * length of the path so that only the amount of folders defined |
|
| 1230 | - * in the <code>$depth</code> attribute are shown below the actual |
|
| 1231 | - * folder or file in the path. |
|
| 1232 | - * |
|
| 1233 | - * @param string $path The absolute or relative path |
|
| 1234 | - * @param int $depth The folder depth to reduce the path to |
|
| 1235 | - * @return string |
|
| 1236 | - */ |
|
| 1227 | + /** |
|
| 1228 | + * Makes a path relative using a folder depth: will reduce the |
|
| 1229 | + * length of the path so that only the amount of folders defined |
|
| 1230 | + * in the <code>$depth</code> attribute are shown below the actual |
|
| 1231 | + * folder or file in the path. |
|
| 1232 | + * |
|
| 1233 | + * @param string $path The absolute or relative path |
|
| 1234 | + * @param int $depth The folder depth to reduce the path to |
|
| 1235 | + * @return string |
|
| 1236 | + */ |
|
| 1237 | 1237 | public static function relativizePathByDepth(string $path, int $depth=2) : string |
| 1238 | 1238 | { |
| 1239 | 1239 | $path = self::normalizePath($path); |
@@ -1271,23 +1271,23 @@ discard block |
||
| 1271 | 1271 | return trim(implode('/', $tokens), '/'); |
| 1272 | 1272 | } |
| 1273 | 1273 | |
| 1274 | - /** |
|
| 1275 | - * Makes the specified path relative to another path, |
|
| 1276 | - * by removing one from the other if found. Also |
|
| 1277 | - * normalizes the path to use forward slashes. |
|
| 1278 | - * |
|
| 1279 | - * Example: |
|
| 1280 | - * |
|
| 1281 | - * <pre> |
|
| 1282 | - * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
| 1283 | - * </pre> |
|
| 1284 | - * |
|
| 1285 | - * Result: <code>to/file.txt</code> |
|
| 1286 | - * |
|
| 1287 | - * @param string $path |
|
| 1288 | - * @param string $relativeTo |
|
| 1289 | - * @return string |
|
| 1290 | - */ |
|
| 1274 | + /** |
|
| 1275 | + * Makes the specified path relative to another path, |
|
| 1276 | + * by removing one from the other if found. Also |
|
| 1277 | + * normalizes the path to use forward slashes. |
|
| 1278 | + * |
|
| 1279 | + * Example: |
|
| 1280 | + * |
|
| 1281 | + * <pre> |
|
| 1282 | + * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
| 1283 | + * </pre> |
|
| 1284 | + * |
|
| 1285 | + * Result: <code>to/file.txt</code> |
|
| 1286 | + * |
|
| 1287 | + * @param string $path |
|
| 1288 | + * @param string $relativeTo |
|
| 1289 | + * @return string |
|
| 1290 | + */ |
|
| 1291 | 1291 | public static function relativizePath(string $path, string $relativeTo) : string |
| 1292 | 1292 | { |
| 1293 | 1293 | $path = self::normalizePath($path); |
@@ -1299,17 +1299,17 @@ discard block |
||
| 1299 | 1299 | return $relative; |
| 1300 | 1300 | } |
| 1301 | 1301 | |
| 1302 | - /** |
|
| 1303 | - * Checks that the target file exists, and throws an exception |
|
| 1304 | - * if it does not. |
|
| 1305 | - * |
|
| 1306 | - * @param string $path |
|
| 1307 | - * @param int|NULL $errorCode Optional custom error code |
|
| 1308 | - * @throws FileHelper_Exception |
|
| 1309 | - * @return string The real path to the file |
|
| 1310 | - * |
|
| 1311 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 1312 | - */ |
|
| 1302 | + /** |
|
| 1303 | + * Checks that the target file exists, and throws an exception |
|
| 1304 | + * if it does not. |
|
| 1305 | + * |
|
| 1306 | + * @param string $path |
|
| 1307 | + * @param int|NULL $errorCode Optional custom error code |
|
| 1308 | + * @throws FileHelper_Exception |
|
| 1309 | + * @return string The real path to the file |
|
| 1310 | + * |
|
| 1311 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 1312 | + */ |
|
| 1313 | 1313 | public static function requireFileExists(string $path, $errorCode=null) : string |
| 1314 | 1314 | { |
| 1315 | 1315 | $result = realpath($path); |
@@ -1328,18 +1328,18 @@ discard block |
||
| 1328 | 1328 | ); |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - /** |
|
| 1332 | - * Reads a specific line number from the target file and returns its |
|
| 1333 | - * contents, if the file has such a line. Does so with little memory |
|
| 1334 | - * usage, as the file is not read entirely into memory. |
|
| 1335 | - * |
|
| 1336 | - * @param string $path |
|
| 1337 | - * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
| 1338 | - * @return string|NULL Will return null if the requested line does not exist. |
|
| 1339 | - * @throws FileHelper_Exception |
|
| 1340 | - * |
|
| 1341 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 1342 | - */ |
|
| 1331 | + /** |
|
| 1332 | + * Reads a specific line number from the target file and returns its |
|
| 1333 | + * contents, if the file has such a line. Does so with little memory |
|
| 1334 | + * usage, as the file is not read entirely into memory. |
|
| 1335 | + * |
|
| 1336 | + * @param string $path |
|
| 1337 | + * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
| 1338 | + * @return string|NULL Will return null if the requested line does not exist. |
|
| 1339 | + * @throws FileHelper_Exception |
|
| 1340 | + * |
|
| 1341 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 1342 | + */ |
|
| 1343 | 1343 | public static function getLineFromFile(string $path, int $lineNumber) : ?string |
| 1344 | 1344 | { |
| 1345 | 1345 | self::requireFileExists($path); |
@@ -1355,19 +1355,19 @@ discard block |
||
| 1355 | 1355 | $file->seek($targetLine); |
| 1356 | 1356 | |
| 1357 | 1357 | if($file->key() !== $targetLine) { |
| 1358 | - return null; |
|
| 1358 | + return null; |
|
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | 1361 | return $file->current(); |
| 1362 | 1362 | } |
| 1363 | 1363 | |
| 1364 | - /** |
|
| 1365 | - * Retrieves the total amount of lines in the file, without |
|
| 1366 | - * reading the whole file into memory. |
|
| 1367 | - * |
|
| 1368 | - * @param string $path |
|
| 1369 | - * @return int |
|
| 1370 | - */ |
|
| 1364 | + /** |
|
| 1365 | + * Retrieves the total amount of lines in the file, without |
|
| 1366 | + * reading the whole file into memory. |
|
| 1367 | + * |
|
| 1368 | + * @param string $path |
|
| 1369 | + * @return int |
|
| 1370 | + */ |
|
| 1371 | 1371 | public static function countFileLines(string $path) : int |
| 1372 | 1372 | { |
| 1373 | 1373 | self::requireFileExists($path); |
@@ -1397,26 +1397,26 @@ discard block |
||
| 1397 | 1397 | return $number+1; |
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | - /** |
|
| 1401 | - * Parses the target file to detect any PHP classes contained |
|
| 1402 | - * within, and retrieve information on them. Does not use the |
|
| 1403 | - * PHP reflection API. |
|
| 1404 | - * |
|
| 1405 | - * @param string $filePath |
|
| 1406 | - * @return FileHelper_PHPClassInfo |
|
| 1407 | - */ |
|
| 1400 | + /** |
|
| 1401 | + * Parses the target file to detect any PHP classes contained |
|
| 1402 | + * within, and retrieve information on them. Does not use the |
|
| 1403 | + * PHP reflection API. |
|
| 1404 | + * |
|
| 1405 | + * @param string $filePath |
|
| 1406 | + * @return FileHelper_PHPClassInfo |
|
| 1407 | + */ |
|
| 1408 | 1408 | public static function findPHPClasses(string $filePath) : FileHelper_PHPClassInfo |
| 1409 | 1409 | { |
| 1410 | 1410 | return new FileHelper_PHPClassInfo($filePath); |
| 1411 | 1411 | } |
| 1412 | 1412 | |
| 1413 | - /** |
|
| 1414 | - * Detects the end of line style used in the target file, if any. |
|
| 1415 | - * Can be used with large files, because it only reads part of it. |
|
| 1416 | - * |
|
| 1417 | - * @param string $filePath The path to the file. |
|
| 1418 | - * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found. |
|
| 1419 | - */ |
|
| 1413 | + /** |
|
| 1414 | + * Detects the end of line style used in the target file, if any. |
|
| 1415 | + * Can be used with large files, because it only reads part of it. |
|
| 1416 | + * |
|
| 1417 | + * @param string $filePath The path to the file. |
|
| 1418 | + * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found. |
|
| 1419 | + */ |
|
| 1420 | 1420 | public static function detectEOLCharacter(string $filePath) : ?ConvertHelper_EOL |
| 1421 | 1421 | { |
| 1422 | 1422 | // 20 lines is enough to get a good picture of the newline style in the file. |
@@ -1429,18 +1429,18 @@ discard block |
||
| 1429 | 1429 | return ConvertHelper::detectEOLCharacter($string); |
| 1430 | 1430 | } |
| 1431 | 1431 | |
| 1432 | - /** |
|
| 1433 | - * Reads the specified amount of lines from the target file. |
|
| 1434 | - * Unicode BOM compatible: any byte order marker is stripped |
|
| 1435 | - * from the resulting lines. |
|
| 1436 | - * |
|
| 1437 | - * @param string $filePath |
|
| 1438 | - * @param int $amount Set to 0 to read all lines. |
|
| 1439 | - * @return array |
|
| 1440 | - * |
|
| 1441 | - * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
|
| 1442 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 1443 | - */ |
|
| 1432 | + /** |
|
| 1433 | + * Reads the specified amount of lines from the target file. |
|
| 1434 | + * Unicode BOM compatible: any byte order marker is stripped |
|
| 1435 | + * from the resulting lines. |
|
| 1436 | + * |
|
| 1437 | + * @param string $filePath |
|
| 1438 | + * @param int $amount Set to 0 to read all lines. |
|
| 1439 | + * @return array |
|
| 1440 | + * |
|
| 1441 | + * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
|
| 1442 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 1443 | + */ |
|
| 1444 | 1444 | public static function readLines(string $filePath, int $amount=0) : array |
| 1445 | 1445 | { |
| 1446 | 1446 | self::requireFileExists($filePath); |
@@ -1491,16 +1491,16 @@ discard block |
||
| 1491 | 1491 | return $result; |
| 1492 | 1492 | } |
| 1493 | 1493 | |
| 1494 | - /** |
|
| 1495 | - * Reads all content from a file. |
|
| 1496 | - * |
|
| 1497 | - * @param string $filePath |
|
| 1498 | - * @throws FileHelper_Exception |
|
| 1499 | - * @return string |
|
| 1500 | - * |
|
| 1501 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 1502 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 1503 | - */ |
|
| 1494 | + /** |
|
| 1495 | + * Reads all content from a file. |
|
| 1496 | + * |
|
| 1497 | + * @param string $filePath |
|
| 1498 | + * @throws FileHelper_Exception |
|
| 1499 | + * @return string |
|
| 1500 | + * |
|
| 1501 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 1502 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 1503 | + */ |
|
| 1504 | 1504 | public static function readContents(string $filePath) : string |
| 1505 | 1505 | { |
| 1506 | 1506 | self::requireFileExists($filePath); |
@@ -7,9 +7,9 @@ |
||
| 7 | 7 | * @author Sebastian Mordziol <[email protected]> |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Examples environment config |
|
| 12 | - */ |
|
| 10 | + /** |
|
| 11 | + * Examples environment config |
|
| 12 | + */ |
|
| 13 | 13 | require_once '../prepend.php'; |
| 14 | 14 | |
| 15 | 15 | use function AppUtils\parseURL; |
@@ -17,33 +17,33 @@ |
||
| 17 | 17 | die('<b>ERROR:</b> Autoloader not present. Run composer update first.'); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * The composer autoloader |
|
| 22 | - */ |
|
| 20 | + /** |
|
| 21 | + * The composer autoloader |
|
| 22 | + */ |
|
| 23 | 23 | require_once $autoload; |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Translation global function. |
|
| 27 | - * @return string |
|
| 28 | - */ |
|
| 25 | + /** |
|
| 26 | + * Translation global function. |
|
| 27 | + * @return string |
|
| 28 | + */ |
|
| 29 | 29 | function t() |
| 30 | 30 | { |
| 31 | 31 | return call_user_func_array('\AppLocalize\t', func_get_args()); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Translation global function. |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 34 | + /** |
|
| 35 | + * Translation global function. |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | 38 | function pt() |
| 39 | 39 | { |
| 40 | 40 | return call_user_func_array('\AppLocalize\pt', func_get_args()); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Translation global function. |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 43 | + /** |
|
| 44 | + * Translation global function. |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | 47 | function pts() |
| 48 | 48 | { |
| 49 | 49 | return call_user_func_array('\AppLocalize\pts', func_get_args()); |
@@ -435,16 +435,16 @@ discard block |
||
| 435 | 435 | return $bytes . ' ' . t('B'); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - /** |
|
| 439 | - * Cuts a text to the specified length if it is longer than the |
|
| 440 | - * target length. Appends a text to signify it has been cut at |
|
| 441 | - * the end of the string. |
|
| 442 | - * |
|
| 443 | - * @param string $text |
|
| 444 | - * @param int $targetLength |
|
| 445 | - * @param string $append |
|
| 446 | - * @return string |
|
| 447 | - */ |
|
| 438 | + /** |
|
| 439 | + * Cuts a text to the specified length if it is longer than the |
|
| 440 | + * target length. Appends a text to signify it has been cut at |
|
| 441 | + * the end of the string. |
|
| 442 | + * |
|
| 443 | + * @param string $text |
|
| 444 | + * @param int $targetLength |
|
| 445 | + * @param string $append |
|
| 446 | + * @return string |
|
| 447 | + */ |
|
| 448 | 448 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
| 449 | 449 | { |
| 450 | 450 | $length = mb_strlen($text); |
@@ -514,27 +514,27 @@ discard block |
||
| 514 | 514 | return self::$booleanStrings[$string]; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - /** |
|
| 518 | - * Whether the specified string is a boolean string or boolean value. |
|
| 519 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 520 | - * |
|
| 521 | - * @param mixed $string |
|
| 522 | - * @return bool |
|
| 523 | - * @deprecated |
|
| 524 | - * @see ConvertHelper::isBoolean() |
|
| 525 | - */ |
|
| 517 | + /** |
|
| 518 | + * Whether the specified string is a boolean string or boolean value. |
|
| 519 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 520 | + * |
|
| 521 | + * @param mixed $string |
|
| 522 | + * @return bool |
|
| 523 | + * @deprecated |
|
| 524 | + * @see ConvertHelper::isBoolean() |
|
| 525 | + */ |
|
| 526 | 526 | public static function isBooleanString($string) : bool |
| 527 | 527 | { |
| 528 | 528 | return self::isBoolean($string); |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - /** |
|
| 532 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 533 | - * |
|
| 534 | - * @param string $text |
|
| 535 | - * @return string |
|
| 536 | - * @deprecated |
|
| 537 | - */ |
|
| 531 | + /** |
|
| 532 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 533 | + * |
|
| 534 | + * @param string $text |
|
| 535 | + * @return string |
|
| 536 | + * @deprecated |
|
| 537 | + */ |
|
| 538 | 538 | public static function text_makeXMLCompliant($text) |
| 539 | 539 | { |
| 540 | 540 | return XMLHelper::string2xml($text); |
@@ -636,13 +636,13 @@ discard block |
||
| 636 | 636 | return $translit->convert($string); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - /** |
|
| 640 | - * Retrieves the HEX character codes for all control |
|
| 641 | - * characters that the {@link stripControlCharacters()} |
|
| 642 | - * method will remove. |
|
| 643 | - * |
|
| 644 | - * @return string[] |
|
| 645 | - */ |
|
| 639 | + /** |
|
| 640 | + * Retrieves the HEX character codes for all control |
|
| 641 | + * characters that the {@link stripControlCharacters()} |
|
| 642 | + * method will remove. |
|
| 643 | + * |
|
| 644 | + * @return string[] |
|
| 645 | + */ |
|
| 646 | 646 | public static function getControlCharactersAsHex() |
| 647 | 647 | { |
| 648 | 648 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
@@ -678,13 +678,13 @@ discard block |
||
| 678 | 678 | return $stack; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - /** |
|
| 682 | - * Retrieves an array of all control characters that |
|
| 683 | - * the {@link stripControlCharacters()} method will |
|
| 684 | - * remove, as the actual UTF-8 characters. |
|
| 685 | - * |
|
| 686 | - * @return string[] |
|
| 687 | - */ |
|
| 681 | + /** |
|
| 682 | + * Retrieves an array of all control characters that |
|
| 683 | + * the {@link stripControlCharacters()} method will |
|
| 684 | + * remove, as the actual UTF-8 characters. |
|
| 685 | + * |
|
| 686 | + * @return string[] |
|
| 687 | + */ |
|
| 688 | 688 | public static function getControlCharactersAsUTF8() |
| 689 | 689 | { |
| 690 | 690 | $chars = self::getControlCharactersAsHex(); |
@@ -697,12 +697,12 @@ discard block |
||
| 697 | 697 | return $result; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - /** |
|
| 701 | - * Retrieves all control characters as JSON encoded |
|
| 702 | - * characters, e.g. "\u200b". |
|
| 703 | - * |
|
| 704 | - * @return string[] |
|
| 705 | - */ |
|
| 700 | + /** |
|
| 701 | + * Retrieves all control characters as JSON encoded |
|
| 702 | + * characters, e.g. "\u200b". |
|
| 703 | + * |
|
| 704 | + * @return string[] |
|
| 705 | + */ |
|
| 706 | 706 | public static function getControlCharactersAsJSON() |
| 707 | 707 | { |
| 708 | 708 | $chars = self::getControlCharactersAsHex(); |
@@ -759,20 +759,20 @@ discard block |
||
| 759 | 759 | return preg_replace(self::$controlCharsRegex, '', $string); |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - /** |
|
| 763 | - * Converts a unicode character to the PHPO notation. |
|
| 764 | - * |
|
| 765 | - * Example: |
|
| 766 | - * |
|
| 767 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 768 | - * |
|
| 769 | - * Returns |
|
| 770 | - * |
|
| 771 | - * <pre>\x0</pre> |
|
| 772 | - * |
|
| 773 | - * @param string $unicodeChar |
|
| 774 | - * @return string |
|
| 775 | - */ |
|
| 762 | + /** |
|
| 763 | + * Converts a unicode character to the PHPO notation. |
|
| 764 | + * |
|
| 765 | + * Example: |
|
| 766 | + * |
|
| 767 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 768 | + * |
|
| 769 | + * Returns |
|
| 770 | + * |
|
| 771 | + * <pre>\x0</pre> |
|
| 772 | + * |
|
| 773 | + * @param string $unicodeChar |
|
| 774 | + * @return string |
|
| 775 | + */ |
|
| 776 | 776 | public static function unicodeChar2php($unicodeChar) |
| 777 | 777 | { |
| 778 | 778 | $unicodeChar = json_decode($unicodeChar); |
@@ -895,25 +895,25 @@ discard block |
||
| 895 | 895 | return 'false'; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - /** |
|
| 899 | - * Converts an associative array with attribute name > value pairs |
|
| 900 | - * to an attribute string that can be used in an HTML tag. Empty |
|
| 901 | - * attribute values are ignored. |
|
| 902 | - * |
|
| 903 | - * Example: |
|
| 904 | - * |
|
| 905 | - * array2attributeString(array( |
|
| 906 | - * 'id' => 45, |
|
| 907 | - * 'href' => 'http://www.mistralys.com' |
|
| 908 | - * )); |
|
| 909 | - * |
|
| 910 | - * Result: |
|
| 911 | - * |
|
| 912 | - * id="45" href="http://www.mistralys.com" |
|
| 913 | - * |
|
| 914 | - * @param array $array |
|
| 915 | - * @return string |
|
| 916 | - */ |
|
| 898 | + /** |
|
| 899 | + * Converts an associative array with attribute name > value pairs |
|
| 900 | + * to an attribute string that can be used in an HTML tag. Empty |
|
| 901 | + * attribute values are ignored. |
|
| 902 | + * |
|
| 903 | + * Example: |
|
| 904 | + * |
|
| 905 | + * array2attributeString(array( |
|
| 906 | + * 'id' => 45, |
|
| 907 | + * 'href' => 'http://www.mistralys.com' |
|
| 908 | + * )); |
|
| 909 | + * |
|
| 910 | + * Result: |
|
| 911 | + * |
|
| 912 | + * id="45" href="http://www.mistralys.com" |
|
| 913 | + * |
|
| 914 | + * @param array $array |
|
| 915 | + * @return string |
|
| 916 | + */ |
|
| 917 | 917 | public static function array2attributeString($array) |
| 918 | 918 | { |
| 919 | 919 | $tokens = array(); |
@@ -932,14 +932,14 @@ discard block |
||
| 932 | 932 | return ' '.implode(' ', $tokens); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - /** |
|
| 936 | - * Converts a string so it can safely be used in a javascript |
|
| 937 | - * statement in an HTML tag: uses single quotes around the string |
|
| 938 | - * and encodes all special characters as needed. |
|
| 939 | - * |
|
| 940 | - * @param string $string |
|
| 941 | - * @return string |
|
| 942 | - */ |
|
| 935 | + /** |
|
| 936 | + * Converts a string so it can safely be used in a javascript |
|
| 937 | + * statement in an HTML tag: uses single quotes around the string |
|
| 938 | + * and encodes all special characters as needed. |
|
| 939 | + * |
|
| 940 | + * @param string $string |
|
| 941 | + * @return string |
|
| 942 | + */ |
|
| 943 | 943 | public static function string2attributeJS($string, $quoted=true) |
| 944 | 944 | { |
| 945 | 945 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -950,15 +950,15 @@ discard block |
||
| 950 | 950 | return $converted; |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | - /** |
|
| 954 | - * Checks if the specified string is a boolean value, which |
|
| 955 | - * includes string representations of boolean values, like |
|
| 956 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 957 | - * or <code>false</code>. |
|
| 958 | - * |
|
| 959 | - * @param mixed $value |
|
| 960 | - * @return boolean |
|
| 961 | - */ |
|
| 953 | + /** |
|
| 954 | + * Checks if the specified string is a boolean value, which |
|
| 955 | + * includes string representations of boolean values, like |
|
| 956 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 957 | + * or <code>false</code>. |
|
| 958 | + * |
|
| 959 | + * @param mixed $value |
|
| 960 | + * @return boolean |
|
| 961 | + */ |
|
| 962 | 962 | public static function isBoolean($value) : bool |
| 963 | 963 | { |
| 964 | 964 | if(is_bool($value)) { |
@@ -972,12 +972,12 @@ discard block |
||
| 972 | 972 | return array_key_exists($value, self::$booleanStrings); |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | - /** |
|
| 976 | - * Converts an associative array to an HTML style attribute value string. |
|
| 977 | - * |
|
| 978 | - * @param array $subject |
|
| 979 | - * @return string |
|
| 980 | - */ |
|
| 975 | + /** |
|
| 976 | + * Converts an associative array to an HTML style attribute value string. |
|
| 977 | + * |
|
| 978 | + * @param array $subject |
|
| 979 | + * @return string |
|
| 980 | + */ |
|
| 981 | 981 | public static function array2styleString(array $subject) : string |
| 982 | 982 | { |
| 983 | 983 | $tokens = array(); |
@@ -988,23 +988,23 @@ discard block |
||
| 988 | 988 | return implode(';', $tokens); |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | - /** |
|
| 992 | - * Converts a DateTime object to a timestamp, which |
|
| 993 | - * is PHP 5.2 compatible. |
|
| 994 | - * |
|
| 995 | - * @param \DateTime $date |
|
| 996 | - * @return integer |
|
| 997 | - */ |
|
| 991 | + /** |
|
| 992 | + * Converts a DateTime object to a timestamp, which |
|
| 993 | + * is PHP 5.2 compatible. |
|
| 994 | + * |
|
| 995 | + * @param \DateTime $date |
|
| 996 | + * @return integer |
|
| 997 | + */ |
|
| 998 | 998 | public static function date2timestamp(\DateTime $date) : int |
| 999 | 999 | { |
| 1000 | 1000 | return (int)$date->format('U'); |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - /** |
|
| 1004 | - * Converts a timestamp into a DateTime instance. |
|
| 1005 | - * @param int $timestamp |
|
| 1006 | - * @return \DateTime |
|
| 1007 | - */ |
|
| 1003 | + /** |
|
| 1004 | + * Converts a timestamp into a DateTime instance. |
|
| 1005 | + * @param int $timestamp |
|
| 1006 | + * @return \DateTime |
|
| 1007 | + */ |
|
| 1008 | 1008 | public static function timestamp2date(int $timestamp) : \DateTime |
| 1009 | 1009 | { |
| 1010 | 1010 | $date = new \DateTime(); |
@@ -1012,13 +1012,13 @@ discard block |
||
| 1012 | 1012 | return $date; |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - /** |
|
| 1016 | - * Strips an absolute path to a file within the application |
|
| 1017 | - * to make the path relative to the application root path. |
|
| 1018 | - * |
|
| 1019 | - * @param string $path |
|
| 1020 | - * @return string |
|
| 1021 | - */ |
|
| 1015 | + /** |
|
| 1016 | + * Strips an absolute path to a file within the application |
|
| 1017 | + * to make the path relative to the application root path. |
|
| 1018 | + * |
|
| 1019 | + * @param string $path |
|
| 1020 | + * @return string |
|
| 1021 | + */ |
|
| 1022 | 1022 | public static function fileRelativize($path) |
| 1023 | 1023 | { |
| 1024 | 1024 | $path = str_replace('\\', '/', $path); |
@@ -1030,22 +1030,22 @@ discard block |
||
| 1030 | 1030 | |
| 1031 | 1031 | const JS_REGEX_JSON = 'json'; |
| 1032 | 1032 | |
| 1033 | - /** |
|
| 1034 | - * Takes a regular expression and attempts to convert it to |
|
| 1035 | - * its javascript equivalent. Returns an array containing the |
|
| 1036 | - * format string itself (without start and end characters), |
|
| 1037 | - * and the modifiers. |
|
| 1038 | - * |
|
| 1039 | - * This is intended to be used with the RegExp object, for ex: |
|
| 1040 | - * |
|
| 1041 | - * <script> |
|
| 1042 | - * var expression = <?php echo json_encode(ConvertHelper::regex2js('/ab+c/i')) ?>; |
|
| 1043 | - * var reg = new RegExp(expression.format, expression.modifiers); |
|
| 1044 | - * </script> |
|
| 1045 | - * |
|
| 1046 | - * @param string $regex |
|
| 1047 | - * @return array |
|
| 1048 | - */ |
|
| 1033 | + /** |
|
| 1034 | + * Takes a regular expression and attempts to convert it to |
|
| 1035 | + * its javascript equivalent. Returns an array containing the |
|
| 1036 | + * format string itself (without start and end characters), |
|
| 1037 | + * and the modifiers. |
|
| 1038 | + * |
|
| 1039 | + * This is intended to be used with the RegExp object, for ex: |
|
| 1040 | + * |
|
| 1041 | + * <script> |
|
| 1042 | + * var expression = <?php echo json_encode(ConvertHelper::regex2js('/ab+c/i')) ?>; |
|
| 1043 | + * var reg = new RegExp(expression.format, expression.modifiers); |
|
| 1044 | + * </script> |
|
| 1045 | + * |
|
| 1046 | + * @param string $regex |
|
| 1047 | + * @return array |
|
| 1048 | + */ |
|
| 1049 | 1049 | public static function regex2js($regex, $return=self::JS_REGEX_OBJECT) |
| 1050 | 1050 | { |
| 1051 | 1051 | $regex = trim($regex); |
@@ -1091,12 +1091,12 @@ discard block |
||
| 1091 | 1091 | ); |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | - /** |
|
| 1095 | - * Strips all known UTF byte order marks from the specified string. |
|
| 1096 | - * |
|
| 1097 | - * @param string $string |
|
| 1098 | - * @return string |
|
| 1099 | - */ |
|
| 1094 | + /** |
|
| 1095 | + * Strips all known UTF byte order marks from the specified string. |
|
| 1096 | + * |
|
| 1097 | + * @param string $string |
|
| 1098 | + * @return string |
|
| 1099 | + */ |
|
| 1100 | 1100 | public static function stripUTFBom($string) |
| 1101 | 1101 | { |
| 1102 | 1102 | $boms = FileHelper::getUTFBOMs(); |
@@ -1111,13 +1111,13 @@ discard block |
||
| 1111 | 1111 | return $string; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | - /** |
|
| 1115 | - * Converts a string to valid utf8, regardless |
|
| 1116 | - * of the string's encoding(s). |
|
| 1117 | - * |
|
| 1118 | - * @param string $string |
|
| 1119 | - * @return string |
|
| 1120 | - */ |
|
| 1114 | + /** |
|
| 1115 | + * Converts a string to valid utf8, regardless |
|
| 1116 | + * of the string's encoding(s). |
|
| 1117 | + * |
|
| 1118 | + * @param string $string |
|
| 1119 | + * @return string |
|
| 1120 | + */ |
|
| 1121 | 1121 | public static function string2utf8($string) |
| 1122 | 1122 | { |
| 1123 | 1123 | if(!self::isStringASCII($string)) { |
@@ -1127,15 +1127,15 @@ discard block |
||
| 1127 | 1127 | return $string; |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | - /** |
|
| 1131 | - * Checks whether the specified string is an ASCII |
|
| 1132 | - * string, without any special or UTF8 characters. |
|
| 1133 | - * Note: empty strings and NULL are considered ASCII. |
|
| 1134 | - * Any variable types other than strings are not. |
|
| 1135 | - * |
|
| 1136 | - * @param string $string |
|
| 1137 | - * @return boolean |
|
| 1138 | - */ |
|
| 1130 | + /** |
|
| 1131 | + * Checks whether the specified string is an ASCII |
|
| 1132 | + * string, without any special or UTF8 characters. |
|
| 1133 | + * Note: empty strings and NULL are considered ASCII. |
|
| 1134 | + * Any variable types other than strings are not. |
|
| 1135 | + * |
|
| 1136 | + * @param string $string |
|
| 1137 | + * @return boolean |
|
| 1138 | + */ |
|
| 1139 | 1139 | public static function isStringASCII($string) |
| 1140 | 1140 | { |
| 1141 | 1141 | if($string === '' || $string === NULL) { |
@@ -1160,22 +1160,22 @@ discard block |
||
| 1160 | 1160 | return $url; |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | - /** |
|
| 1164 | - * Calculates a percentage match of the source string with the target string. |
|
| 1165 | - * |
|
| 1166 | - * Options are: |
|
| 1167 | - * |
|
| 1168 | - * - maxLevenshtein, default: 10 |
|
| 1169 | - * Any levenshtein results above this value are ignored. |
|
| 1170 | - * |
|
| 1171 | - * - precision, default: 1 |
|
| 1172 | - * The precision of the percentage float value |
|
| 1173 | - * |
|
| 1174 | - * @param string $source |
|
| 1175 | - * @param string $target |
|
| 1176 | - * @param array $options |
|
| 1177 | - * @return float |
|
| 1178 | - */ |
|
| 1163 | + /** |
|
| 1164 | + * Calculates a percentage match of the source string with the target string. |
|
| 1165 | + * |
|
| 1166 | + * Options are: |
|
| 1167 | + * |
|
| 1168 | + * - maxLevenshtein, default: 10 |
|
| 1169 | + * Any levenshtein results above this value are ignored. |
|
| 1170 | + * |
|
| 1171 | + * - precision, default: 1 |
|
| 1172 | + * The precision of the percentage float value |
|
| 1173 | + * |
|
| 1174 | + * @param string $source |
|
| 1175 | + * @param string $target |
|
| 1176 | + * @param array $options |
|
| 1177 | + * @return float |
|
| 1178 | + */ |
|
| 1179 | 1179 | public static function matchString($source, $target, $options=array()) |
| 1180 | 1180 | { |
| 1181 | 1181 | $defaults = array( |
@@ -1259,14 +1259,14 @@ discard block |
||
| 1259 | 1259 | |
| 1260 | 1260 | const INTERVAL_SECONDS = 'seconds'; |
| 1261 | 1261 | |
| 1262 | - /** |
|
| 1263 | - * Calculates the total amount of days / hours / minutes or seconds |
|
| 1264 | - * of a date interval object and returns the value. |
|
| 1265 | - * |
|
| 1266 | - * @param \DateInterval $interval |
|
| 1267 | - * @param string $unit |
|
| 1268 | - * @return integer |
|
| 1269 | - */ |
|
| 1262 | + /** |
|
| 1263 | + * Calculates the total amount of days / hours / minutes or seconds |
|
| 1264 | + * of a date interval object and returns the value. |
|
| 1265 | + * |
|
| 1266 | + * @param \DateInterval $interval |
|
| 1267 | + * @param string $unit |
|
| 1268 | + * @return integer |
|
| 1269 | + */ |
|
| 1270 | 1270 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) |
| 1271 | 1271 | { |
| 1272 | 1272 | $total = $interval->format('%a'); |
@@ -1304,13 +1304,13 @@ discard block |
||
| 1304 | 1304 | 'Sunday' |
| 1305 | 1305 | ); |
| 1306 | 1306 | |
| 1307 | - /** |
|
| 1308 | - * Converts a date to the corresponding day name. |
|
| 1309 | - * |
|
| 1310 | - * @param \DateTime $date |
|
| 1311 | - * @param string $short |
|
| 1312 | - * @return string|NULL |
|
| 1313 | - */ |
|
| 1307 | + /** |
|
| 1308 | + * Converts a date to the corresponding day name. |
|
| 1309 | + * |
|
| 1310 | + * @param \DateTime $date |
|
| 1311 | + * @param string $short |
|
| 1312 | + * @return string|NULL |
|
| 1313 | + */ |
|
| 1314 | 1314 | public static function date2dayName(\DateTime $date, $short=false) |
| 1315 | 1315 | { |
| 1316 | 1316 | $day = $date->format('l'); |
@@ -1325,21 +1325,21 @@ discard block |
||
| 1325 | 1325 | return null; |
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | - /** |
|
| 1329 | - * Retrieves a list of english day names. |
|
| 1330 | - * @return string[] |
|
| 1331 | - */ |
|
| 1328 | + /** |
|
| 1329 | + * Retrieves a list of english day names. |
|
| 1330 | + * @return string[] |
|
| 1331 | + */ |
|
| 1332 | 1332 | public static function getDayNamesInvariant() |
| 1333 | 1333 | { |
| 1334 | 1334 | return self::$daysInvariant; |
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | - /** |
|
| 1338 | - * Retrieves the day names list for the current locale. |
|
| 1339 | - * |
|
| 1340 | - * @param string $short |
|
| 1341 | - * @return string[] |
|
| 1342 | - */ |
|
| 1337 | + /** |
|
| 1338 | + * Retrieves the day names list for the current locale. |
|
| 1339 | + * |
|
| 1340 | + * @param string $short |
|
| 1341 | + * @return string[] |
|
| 1342 | + */ |
|
| 1343 | 1343 | public static function getDayNames($short=false) |
| 1344 | 1344 | { |
| 1345 | 1345 | if($short) { |
@@ -1399,14 +1399,14 @@ discard block |
||
| 1399 | 1399 | return $last; |
| 1400 | 1400 | } |
| 1401 | 1401 | |
| 1402 | - /** |
|
| 1403 | - * Splits a string into an array of all characters it is composed of. |
|
| 1404 | - * Spaces and newlines (both \r and \n) are also considered single |
|
| 1405 | - * characters. Unicode character safe. |
|
| 1406 | - * |
|
| 1407 | - * @param string $string |
|
| 1408 | - * @return string[] |
|
| 1409 | - */ |
|
| 1402 | + /** |
|
| 1403 | + * Splits a string into an array of all characters it is composed of. |
|
| 1404 | + * Spaces and newlines (both \r and \n) are also considered single |
|
| 1405 | + * characters. Unicode character safe. |
|
| 1406 | + * |
|
| 1407 | + * @param string $string |
|
| 1408 | + * @return string[] |
|
| 1409 | + */ |
|
| 1410 | 1410 | public static function string2array(string $string) : array |
| 1411 | 1411 | { |
| 1412 | 1412 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
@@ -1417,12 +1417,12 @@ discard block |
||
| 1417 | 1417 | return array(); |
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | - /** |
|
| 1421 | - * Checks whether the specified string contains HTML code. |
|
| 1422 | - * |
|
| 1423 | - * @param string $string |
|
| 1424 | - * @return boolean |
|
| 1425 | - */ |
|
| 1420 | + /** |
|
| 1421 | + * Checks whether the specified string contains HTML code. |
|
| 1422 | + * |
|
| 1423 | + * @param string $string |
|
| 1424 | + * @return boolean |
|
| 1425 | + */ |
|
| 1426 | 1426 | public static function isStringHTML(string $string) : bool |
| 1427 | 1427 | { |
| 1428 | 1428 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1437,18 +1437,18 @@ discard block |
||
| 1437 | 1437 | return false; |
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | - /** |
|
| 1441 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1442 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1443 | - * are no calculated correctly. |
|
| 1444 | - * |
|
| 1445 | - * @param string $str |
|
| 1446 | - * @param int $width |
|
| 1447 | - * @param string $break |
|
| 1448 | - * @param bool $cut |
|
| 1449 | - * @return string |
|
| 1450 | - * @see https://stackoverflow.com/a/4988494/2298192 |
|
| 1451 | - */ |
|
| 1440 | + /** |
|
| 1441 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1442 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1443 | + * are no calculated correctly. |
|
| 1444 | + * |
|
| 1445 | + * @param string $str |
|
| 1446 | + * @param int $width |
|
| 1447 | + * @param string $break |
|
| 1448 | + * @param bool $cut |
|
| 1449 | + * @return string |
|
| 1450 | + * @see https://stackoverflow.com/a/4988494/2298192 |
|
| 1451 | + */ |
|
| 1452 | 1452 | public static function wordwrap($str, $width = 75, $break = "\n", $cut = false) |
| 1453 | 1453 | { |
| 1454 | 1454 | $lines = explode($break, $str); |
@@ -1494,27 +1494,27 @@ discard block |
||
| 1494 | 1494 | return implode($break, $lines); |
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 1497 | - /** |
|
| 1498 | - * Calculates the byte length of a string, taking into |
|
| 1499 | - * account any unicode characters. |
|
| 1500 | - * |
|
| 1501 | - * @param string $string |
|
| 1502 | - * @return int |
|
| 1503 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1504 | - */ |
|
| 1497 | + /** |
|
| 1498 | + * Calculates the byte length of a string, taking into |
|
| 1499 | + * account any unicode characters. |
|
| 1500 | + * |
|
| 1501 | + * @param string $string |
|
| 1502 | + * @return int |
|
| 1503 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1504 | + */ |
|
| 1505 | 1505 | public static function string2bytes($string) |
| 1506 | 1506 | { |
| 1507 | 1507 | return mb_strlen($string, '8bit'); |
| 1508 | 1508 | } |
| 1509 | 1509 | |
| 1510 | - /** |
|
| 1511 | - * Creates a short, 8-character long hash for the specified string. |
|
| 1512 | - * |
|
| 1513 | - * WARNING: Not cryptographically safe. |
|
| 1514 | - * |
|
| 1515 | - * @param string $string |
|
| 1516 | - * @return string |
|
| 1517 | - */ |
|
| 1510 | + /** |
|
| 1511 | + * Creates a short, 8-character long hash for the specified string. |
|
| 1512 | + * |
|
| 1513 | + * WARNING: Not cryptographically safe. |
|
| 1514 | + * |
|
| 1515 | + * @param string $string |
|
| 1516 | + * @return string |
|
| 1517 | + */ |
|
| 1518 | 1518 | public static function string2shortHash($string) |
| 1519 | 1519 | { |
| 1520 | 1520 | return hash('crc32', $string, false); |
@@ -1540,23 +1540,23 @@ discard block |
||
| 1540 | 1540 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | - /** |
|
| 1544 | - * Parses the specified query string like the native |
|
| 1545 | - * function <code>parse_str</code>, without the key |
|
| 1546 | - * naming limitations. |
|
| 1547 | - * |
|
| 1548 | - * Using parse_str, dots or spaces in key names are |
|
| 1549 | - * replaced by underscores. This method keeps all names |
|
| 1550 | - * intact. |
|
| 1551 | - * |
|
| 1552 | - * It still uses the parse_str implementation as it |
|
| 1553 | - * is tested and tried, but fixes the parameter names |
|
| 1554 | - * after parsing, as needed. |
|
| 1555 | - * |
|
| 1556 | - * @param string $queryString |
|
| 1557 | - * @return array |
|
| 1558 | - * @see https://www.php.net/manual/en/function.parse-str.php |
|
| 1559 | - */ |
|
| 1543 | + /** |
|
| 1544 | + * Parses the specified query string like the native |
|
| 1545 | + * function <code>parse_str</code>, without the key |
|
| 1546 | + * naming limitations. |
|
| 1547 | + * |
|
| 1548 | + * Using parse_str, dots or spaces in key names are |
|
| 1549 | + * replaced by underscores. This method keeps all names |
|
| 1550 | + * intact. |
|
| 1551 | + * |
|
| 1552 | + * It still uses the parse_str implementation as it |
|
| 1553 | + * is tested and tried, but fixes the parameter names |
|
| 1554 | + * after parsing, as needed. |
|
| 1555 | + * |
|
| 1556 | + * @param string $queryString |
|
| 1557 | + * @return array |
|
| 1558 | + * @see https://www.php.net/manual/en/function.parse-str.php |
|
| 1559 | + */ |
|
| 1560 | 1560 | public static function parseQueryString(string $queryString) : array |
| 1561 | 1561 | { |
| 1562 | 1562 | // allow HTML entities notation |
@@ -1596,16 +1596,16 @@ discard block |
||
| 1596 | 1596 | $placeholders = array(); |
| 1597 | 1597 | foreach($paramNames as $paramName) |
| 1598 | 1598 | { |
| 1599 | - // create a unique placeholder name |
|
| 1600 | - $placeholder = '__PLACEHOLDER'.$counter.'__'; |
|
| 1599 | + // create a unique placeholder name |
|
| 1600 | + $placeholder = '__PLACEHOLDER'.$counter.'__'; |
|
| 1601 | 1601 | |
| 1602 | - // store the placeholder name to replace later |
|
| 1603 | - $table[$placeholder] = $paramName; |
|
| 1602 | + // store the placeholder name to replace later |
|
| 1603 | + $table[$placeholder] = $paramName; |
|
| 1604 | 1604 | |
| 1605 | - // add the placeholder to replace in the query string before parsing |
|
| 1606 | - $placeholders[$paramName.'='] = $placeholder.'='; |
|
| 1605 | + // add the placeholder to replace in the query string before parsing |
|
| 1606 | + $placeholders[$paramName.'='] = $placeholder.'='; |
|
| 1607 | 1607 | |
| 1608 | - $counter++; |
|
| 1608 | + $counter++; |
|
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | 1611 | // next challenge: replacing the parameter names by placeholders |
@@ -1632,23 +1632,23 @@ discard block |
||
| 1632 | 1632 | |
| 1633 | 1633 | foreach($parsed as $name => $value) |
| 1634 | 1634 | { |
| 1635 | - $keep[$table[$name]] = $value; |
|
| 1635 | + $keep[$table[$name]] = $value; |
|
| 1636 | 1636 | } |
| 1637 | 1637 | |
| 1638 | 1638 | return $keep; |
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | - /** |
|
| 1642 | - * Searches for needle in the specified string, and returns a list |
|
| 1643 | - * of all occurrences, including the matched string. The matched |
|
| 1644 | - * string is useful when doing a case insensitive search, as it |
|
| 1645 | - * shows the exact matched case of needle. |
|
| 1646 | - * |
|
| 1647 | - * @param string $needle |
|
| 1648 | - * @param string $haystack |
|
| 1649 | - * @param bool $caseInsensitive |
|
| 1650 | - * @return ConvertHelper_StringMatch[] |
|
| 1651 | - */ |
|
| 1641 | + /** |
|
| 1642 | + * Searches for needle in the specified string, and returns a list |
|
| 1643 | + * of all occurrences, including the matched string. The matched |
|
| 1644 | + * string is useful when doing a case insensitive search, as it |
|
| 1645 | + * shows the exact matched case of needle. |
|
| 1646 | + * |
|
| 1647 | + * @param string $needle |
|
| 1648 | + * @param string $haystack |
|
| 1649 | + * @param bool $caseInsensitive |
|
| 1650 | + * @return ConvertHelper_StringMatch[] |
|
| 1651 | + */ |
|
| 1652 | 1652 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
| 1653 | 1653 | { |
| 1654 | 1654 | if($needle === '') { |
@@ -1674,14 +1674,14 @@ discard block |
||
| 1674 | 1674 | return $positions; |
| 1675 | 1675 | } |
| 1676 | 1676 | |
| 1677 | - /** |
|
| 1678 | - * Like explode, but trims all entries, and removes |
|
| 1679 | - * empty entries from the resulting array. |
|
| 1680 | - * |
|
| 1681 | - * @param string $delimiter |
|
| 1682 | - * @param string $string |
|
| 1683 | - * @return string[] |
|
| 1684 | - */ |
|
| 1677 | + /** |
|
| 1678 | + * Like explode, but trims all entries, and removes |
|
| 1679 | + * empty entries from the resulting array. |
|
| 1680 | + * |
|
| 1681 | + * @param string $delimiter |
|
| 1682 | + * @param string $string |
|
| 1683 | + * @return string[] |
|
| 1684 | + */ |
|
| 1685 | 1685 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1686 | 1686 | { |
| 1687 | 1687 | if(empty($string) || empty($delimiter)) { |
@@ -1703,12 +1703,12 @@ discard block |
||
| 1703 | 1703 | |
| 1704 | 1704 | protected static $eolChars; |
| 1705 | 1705 | |
| 1706 | - /** |
|
| 1707 | - * Detects the most used end-of-line character in the subject string. |
|
| 1708 | - * |
|
| 1709 | - * @param string $str The string to check. |
|
| 1710 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1711 | - */ |
|
| 1706 | + /** |
|
| 1707 | + * Detects the most used end-of-line character in the subject string. |
|
| 1708 | + * |
|
| 1709 | + * @param string $str The string to check. |
|
| 1710 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1711 | + */ |
|
| 1712 | 1712 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1713 | 1713 | { |
| 1714 | 1714 | if(empty($subjectString)) { |
@@ -1720,27 +1720,27 @@ discard block |
||
| 1720 | 1720 | $cr = chr((int)hexdec('0d')); |
| 1721 | 1721 | $lf = chr((int)hexdec('0a')); |
| 1722 | 1722 | |
| 1723 | - self::$eolChars = array( |
|
| 1724 | - array( |
|
| 1725 | - 'char' => $cr.$lf, |
|
| 1726 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1727 | - 'description' => t('Carriage return followed by a line feed'), |
|
| 1728 | - ), |
|
| 1729 | - array( |
|
| 1730 | - 'char' => $lf.$cr, |
|
| 1731 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1732 | - 'description' => t('Line feed followed by a carriage return'), |
|
| 1733 | - ), |
|
| 1734 | - array( |
|
| 1735 | - 'char' => $lf, |
|
| 1736 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1737 | - 'description' => t('Line feed'), |
|
| 1738 | - ), |
|
| 1739 | - array( |
|
| 1740 | - 'char' => $cr, |
|
| 1741 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1742 | - 'description' => t('Carriage Return'), |
|
| 1743 | - ), |
|
| 1723 | + self::$eolChars = array( |
|
| 1724 | + array( |
|
| 1725 | + 'char' => $cr.$lf, |
|
| 1726 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1727 | + 'description' => t('Carriage return followed by a line feed'), |
|
| 1728 | + ), |
|
| 1729 | + array( |
|
| 1730 | + 'char' => $lf.$cr, |
|
| 1731 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1732 | + 'description' => t('Line feed followed by a carriage return'), |
|
| 1733 | + ), |
|
| 1734 | + array( |
|
| 1735 | + 'char' => $lf, |
|
| 1736 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1737 | + 'description' => t('Line feed'), |
|
| 1738 | + ), |
|
| 1739 | + array( |
|
| 1740 | + 'char' => $cr, |
|
| 1741 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1742 | + 'description' => t('Carriage Return'), |
|
| 1743 | + ), |
|
| 1744 | 1744 | ); |
| 1745 | 1745 | } |
| 1746 | 1746 | |
@@ -1768,13 +1768,13 @@ discard block |
||
| 1768 | 1768 | ); |
| 1769 | 1769 | } |
| 1770 | 1770 | |
| 1771 | - /** |
|
| 1772 | - * Removes the specified keys from the target array, |
|
| 1773 | - * if they exist. |
|
| 1774 | - * |
|
| 1775 | - * @param array $array |
|
| 1776 | - * @param array $keys |
|
| 1777 | - */ |
|
| 1771 | + /** |
|
| 1772 | + * Removes the specified keys from the target array, |
|
| 1773 | + * if they exist. |
|
| 1774 | + * |
|
| 1775 | + * @param array $array |
|
| 1776 | + * @param array $keys |
|
| 1777 | + */ |
|
| 1778 | 1778 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1779 | 1779 | { |
| 1780 | 1780 | foreach($keys as $key) |