@@ -27,12 +27,12 @@ discard block |
||
| 27 | 27 | /** |
| 28 | 28 | * @var array<string,string>|NULL |
| 29 | 29 | */ |
| 30 | - protected static ?array $utfBoms = null; |
|
| 30 | + protected static ? array $utfBoms = null; |
|
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * @var string[]|NULL |
| 34 | 34 | */ |
| 35 | - protected static ?array $encodings = null; |
|
| 35 | + protected static ? array $encodings = null; |
|
| 36 | 36 | |
| 37 | 37 | public function __construct() |
| 38 | 38 | { |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | fclose($fp); |
| 72 | 72 | |
| 73 | - foreach(self::$utfBoms as $bom => $value) |
|
| 73 | + foreach (self::$utfBoms as $bom => $value) |
|
| 74 | 74 | { |
| 75 | - if(mb_strpos($text, $value) === 0) |
|
| 75 | + if (mb_strpos($text, $value) === 0) |
|
| 76 | 76 | { |
| 77 | 77 | return $bom; |
| 78 | 78 | } |
@@ -83,23 +83,23 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | private function initBOMs() : void |
| 85 | 85 | { |
| 86 | - if(isset(self::$utfBoms)) |
|
| 86 | + if (isset(self::$utfBoms)) |
|
| 87 | 87 | { |
| 88 | 88 | return; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | self::$utfBoms = array( |
| 92 | - 'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF), |
|
| 93 | - 'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00), |
|
| 94 | - 'UTF16-BE' => chr(0xFE) . chr(0xFF), |
|
| 95 | - 'UTF16-LE' => chr(0xFF) . chr(0xFE), |
|
| 96 | - 'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF) |
|
| 92 | + 'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF), |
|
| 93 | + 'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00), |
|
| 94 | + 'UTF16-BE' => chr(0xFE).chr(0xFF), |
|
| 95 | + 'UTF16-LE' => chr(0xFF).chr(0xFE), |
|
| 96 | + 'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF) |
|
| 97 | 97 | ); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | private function initEncodings() : void |
| 101 | 101 | { |
| 102 | - if(isset(self::$encodings)) |
|
| 102 | + if (isset(self::$encodings)) |
|
| 103 | 103 | { |
| 104 | 104 | return; |
| 105 | 105 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | self::$encodings = array(); |
| 110 | 110 | |
| 111 | - foreach($encodings as $string) |
|
| 111 | + foreach ($encodings as $string) |
|
| 112 | 112 | { |
| 113 | 113 | $withHyphen = str_replace('UTF', 'UTF-', $string); |
| 114 | 114 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $this->file = $info; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public function send(?string $fileName = null, bool $asAttachment=true) : void |
|
| 38 | + public function send(?string $fileName = null, bool $asAttachment = true) : void |
|
| 39 | 39 | { |
| 40 | 40 | $this->file |
| 41 | 41 | ->requireExists() |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | { |
| 54 | 54 | header("Cache-Control: public", true); |
| 55 | 55 | header("Content-Description: File Transfer", true); |
| 56 | - header("Content-Type: " . $this->detectMime(), true); |
|
| 56 | + header("Content-Type: ".$this->detectMime(), true); |
|
| 57 | 57 | |
| 58 | 58 | header(sprintf( |
| 59 | 59 | "Content-Disposition: %s; filename=%s", |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | private function resolveDisposition(bool $asAttachment) : string |
| 71 | 71 | { |
| 72 | - if($asAttachment) |
|
| 72 | + if ($asAttachment) |
|
| 73 | 73 | { |
| 74 | 74 | return 'attachment'; |
| 75 | 75 | } |
@@ -47,15 +47,15 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $file = new SplFileObject($this->file->getPath()); |
| 49 | 49 | |
| 50 | - if($file->eof()) { |
|
| 50 | + if ($file->eof()) { |
|
| 51 | 51 | return ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - $targetLine = $lineNumber-1; |
|
| 54 | + $targetLine = $lineNumber - 1; |
|
| 55 | 55 | |
| 56 | 56 | $file->seek($targetLine); |
| 57 | 57 | |
| 58 | - if($file->key() !== $targetLine) |
|
| 58 | + if ($file->key() !== $targetLine) |
|
| 59 | 59 | { |
| 60 | 60 | return null; |
| 61 | 61 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $number = $spl->key(); |
| 77 | 77 | |
| 78 | 78 | // if seeking to the end the cursor is still at 0, there are no lines. |
| 79 | - if($number === 0) |
|
| 79 | + if ($number === 0) |
|
| 80 | 80 | { |
| 81 | 81 | // since it's a very small file, to get reliable results, |
| 82 | 82 | // we read its contents and use that to determine what |
@@ -84,13 +84,13 @@ discard block |
||
| 84 | 84 | // that this is not practical to solve with the SplFileObject. |
| 85 | 85 | $content = file_get_contents($path); |
| 86 | 86 | |
| 87 | - if(empty($content)) { |
|
| 87 | + if (empty($content)) { |
|
| 88 | 88 | return 0; |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // return the line number we were able to reach + 1 (key is zero-based) |
| 93 | - return $number+1; |
|
| 93 | + return $number + 1; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | * @return string[] |
| 99 | 99 | * @throws FileHelper_Exception |
| 100 | 100 | */ |
| 101 | - public function getLines(int $amount=0) : array |
|
| 101 | + public function getLines(int $amount = 0) : array |
|
| 102 | 102 | { |
| 103 | 103 | $this->file->requireExists(); |
| 104 | 104 | |
| 105 | 105 | $fn = fopen($this->file->getPath(), 'rb'); |
| 106 | 106 | |
| 107 | - if($fn === false) |
|
| 107 | + if ($fn === false) |
|
| 108 | 108 | { |
| 109 | 109 | throw new FileHelper_Exception( |
| 110 | 110 | 'Could not open file for reading.', |
@@ -120,19 +120,19 @@ discard block |
||
| 120 | 120 | $counter = 0; |
| 121 | 121 | $first = true; |
| 122 | 122 | |
| 123 | - while(!feof($fn)) |
|
| 123 | + while (!feof($fn)) |
|
| 124 | 124 | { |
| 125 | 125 | $counter++; |
| 126 | 126 | |
| 127 | 127 | $line = fgets($fn); |
| 128 | 128 | |
| 129 | 129 | // can happen with zero length files |
| 130 | - if($line === false) { |
|
| 130 | + if ($line === false) { |
|
| 131 | 131 | continue; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // the first line may contain a unicode BOM marker. |
| 135 | - if($first) |
|
| 135 | + if ($first) |
|
| 136 | 136 | { |
| 137 | 137 | $line = ConvertHelper::stripUTFBom($line); |
| 138 | 138 | $first = false; |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $result[] = $line; |
| 142 | 142 | |
| 143 | - if($amount > 0 && $counter === $amount) { |
|
| 143 | + if ($amount > 0 && $counter === $amount) { |
|
| 144 | 144 | break; |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -49,13 +49,13 @@ |
||
| 49 | 49 | |
| 50 | 50 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
| 51 | 51 | |
| 52 | - while(strpos($name, ' ') !== false) { |
|
| 52 | + while (strpos($name, ' ') !== false) { |
|
| 53 | 53 | $name = str_replace(' ', ' ', $name); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
| 57 | 57 | |
| 58 | - while(strpos($name, '..') !== false) { |
|
| 58 | + while (strpos($name, '..') !== false) { |
|
| 59 | 59 | $name = str_replace('..', '.', $name); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param string[] $paths |
| 37 | 37 | * @throws FileHelper_Exception |
| 38 | 38 | */ |
| 39 | - public function __construct(array $paths=array()) |
|
| 39 | + public function __construct(array $paths = array()) |
|
| 40 | 40 | { |
| 41 | 41 | $this->addPaths($paths); |
| 42 | 42 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function addPaths(array $paths) : PathsReducer |
| 51 | 51 | { |
| 52 | - foreach($paths as $path) { |
|
| 52 | + foreach ($paths as $path) { |
|
| 53 | 53 | $this->addPath($path); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | $path = FileHelper::normalizePath($path); |
| 68 | 68 | |
| 69 | - if(!in_array($path, $this->paths, true)) { |
|
| 69 | + if (!in_array($path, $this->paths, true)) { |
|
| 70 | 70 | $this->paths[] = $path; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | $split = $this->splitPaths(); |
| 85 | 85 | |
| 86 | - if(empty($split)) { |
|
| 86 | + if (empty($split)) { |
|
| 87 | 87 | return array(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - while($this->shiftPart($split) === true) {} |
|
| 90 | + while ($this->shiftPart($split) === true) {} |
|
| 91 | 91 | |
| 92 | 92 | return $this->joinPaths($split); |
| 93 | 93 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $result = array(); |
| 102 | 102 | |
| 103 | 103 | foreach ($split as $entry) { |
| 104 | - if(!empty($entry)) { |
|
| 104 | + if (!empty($entry)) { |
|
| 105 | 105 | $result[] = implode('/', $entry); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -118,22 +118,22 @@ discard block |
||
| 118 | 118 | $current = null; |
| 119 | 119 | $result = array(); |
| 120 | 120 | |
| 121 | - foreach($split as $entry) |
|
| 121 | + foreach ($split as $entry) |
|
| 122 | 122 | { |
| 123 | - if(empty($entry)) { |
|
| 123 | + if (empty($entry)) { |
|
| 124 | 124 | return false; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $part = array_shift($entry); |
| 128 | - if(empty($entry)) { |
|
| 128 | + if (empty($entry)) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if($current === null) { |
|
| 132 | + if ($current === null) { |
|
| 133 | 133 | $current = $part; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if($part !== $current) { |
|
| 136 | + if ($part !== $current) { |
|
| 137 | 137 | return false; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | { |
| 153 | 153 | $split = array(); |
| 154 | 154 | |
| 155 | - foreach($this->paths as $path) { |
|
| 155 | + foreach ($this->paths as $path) { |
|
| 156 | 156 | $entry = ConvertHelper::explodeTrim('/', $path); |
| 157 | - if(!empty($entry)) { |
|
| 157 | + if (!empty($entry)) { |
|
| 158 | 158 | $split[] = $entry; |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | private function convertEncoding(string $contents) : string |
| 126 | 126 | { |
| 127 | - if(!empty($this->targetEncoding)) |
|
| 127 | + if (!empty($this->targetEncoding)) |
|
| 128 | 128 | { |
| 129 | 129 | return mb_convert_encoding( |
| 130 | 130 | $contents, |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | { |
| 147 | 147 | $options = null; |
| 148 | 148 | |
| 149 | - if($pretty) |
|
| 149 | + if ($pretty) |
|
| 150 | 150 | { |
| 151 | 151 | $options = JSON_PRETTY_PRINT; |
| 152 | 152 | } |
@@ -92,8 +92,7 @@ discard block |
||
| 92 | 92 | 512, |
| 93 | 93 | JSON_THROW_ON_ERROR |
| 94 | 94 | ); |
| 95 | - } |
|
| 96 | - catch (JsonException $e) |
|
| 95 | + } catch (JsonException $e) |
|
| 97 | 96 | { |
| 98 | 97 | throw new FileHelper_Exception( |
| 99 | 98 | 'Cannot decode json data', |
@@ -158,8 +157,7 @@ discard block |
||
| 158 | 157 | $this->file->putContents($json); |
| 159 | 158 | |
| 160 | 159 | return $this; |
| 161 | - } |
|
| 162 | - catch (JsonException $e) |
|
| 160 | + } catch (JsonException $e) |
|
| 163 | 161 | { |
| 164 | 162 | throw new FileHelper_Exception( |
| 165 | 163 | 'An error occurred while encoding a data set to JSON.', |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function setTimeout(int $timeout) : FileDownloader |
| 42 | 42 | { |
| 43 | - if($timeout > 0) |
|
| 43 | + if ($timeout > 0) |
|
| 44 | 44 | { |
| 45 | 45 | $this->timeout = $timeout; |
| 46 | 46 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param bool $enabled |
| 53 | 53 | * @return FileDownloader |
| 54 | 54 | */ |
| 55 | - public function setSSLEnabled(bool $enabled=true) : FileDownloader |
|
| 55 | + public function setSSLEnabled(bool $enabled = true) : FileDownloader |
|
| 56 | 56 | { |
| 57 | 57 | $this->SSLEnabled = $enabled; |
| 58 | 58 | return $this; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | $output = curl_exec($ch); |
| 75 | 75 | |
| 76 | - if($output === false) |
|
| 76 | + if ($output === false) |
|
| 77 | 77 | { |
| 78 | 78 | throw new FileHelper_Exception( |
| 79 | 79 | 'Unable to open URL', |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | curl_close($ch); |
| 90 | 90 | |
| 91 | - if(is_string($output)) |
|
| 91 | + if (is_string($output)) |
|
| 92 | 92 | { |
| 93 | 93 | return $output; |
| 94 | 94 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | $ch = curl_init(); |
| 110 | 110 | |
| 111 | - if(!is_resource($ch)) |
|
| 111 | + if (!is_resource($ch)) |
|
| 112 | 112 | { |
| 113 | 113 | throw new FileHelper_Exception( |
| 114 | 114 | 'Could not initialize a new cURL instance.', |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 126 | 126 | curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); |
| 127 | 127 | |
| 128 | - if(!$this->SSLEnabled) |
|
| 128 | + if (!$this->SSLEnabled) |
|
| 129 | 129 | { |
| 130 | 130 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
| 131 | 131 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
@@ -37,42 +37,42 @@ discard block |
||
| 37 | 37 | public const TYPE_PHONE = 'phone'; |
| 38 | 38 | public const TYPE_URL = 'url'; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The original URL that was passed to the constructor. |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 40 | + /** |
|
| 41 | + * The original URL that was passed to the constructor. |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | 44 | protected string $rawURL; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var array<string,mixed> |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var array<string,mixed> |
|
| 48 | + */ |
|
| 49 | 49 | protected array $info; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var string[] |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var string[] |
|
| 53 | + */ |
|
| 54 | 54 | protected array $excludedParams = array(); |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var bool |
|
| 58 | - * @see URLInfo::setParamExclusion() |
|
| 59 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var bool |
|
| 58 | + * @see URLInfo::setParamExclusion() |
|
| 59 | + */ |
|
| 60 | 60 | protected bool $paramExclusion = false; |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @var array<string,string>|NULL |
|
| 64 | - * @see URLInfo::getTypeLabel() |
|
| 65 | - */ |
|
| 62 | + /** |
|
| 63 | + * @var array<string,string>|NULL |
|
| 64 | + * @see URLInfo::getTypeLabel() |
|
| 65 | + */ |
|
| 66 | 66 | protected static ?array $typeLabels = null; |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @var bool |
|
| 70 | - */ |
|
| 68 | + /** |
|
| 69 | + * @var bool |
|
| 70 | + */ |
|
| 71 | 71 | protected bool $highlightExcluded = false; |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @var string[] |
|
| 75 | - */ |
|
| 73 | + /** |
|
| 74 | + * @var string[] |
|
| 75 | + */ |
|
| 76 | 76 | protected array $infoKeys = array( |
| 77 | 77 | 'scheme', |
| 78 | 78 | 'host', |
@@ -84,24 +84,24 @@ discard block |
||
| 84 | 84 | 'fragment' |
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @var string |
|
| 89 | - */ |
|
| 87 | + /** |
|
| 88 | + * @var string |
|
| 89 | + */ |
|
| 90 | 90 | protected string $url; |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @var URLInfo_Parser |
|
| 94 | - */ |
|
| 92 | + /** |
|
| 93 | + * @var URLInfo_Parser |
|
| 94 | + */ |
|
| 95 | 95 | protected URLInfo_Parser $parser; |
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @var URLInfo_Normalizer|NULL |
|
| 99 | - */ |
|
| 97 | + /** |
|
| 98 | + * @var URLInfo_Normalizer|NULL |
|
| 99 | + */ |
|
| 100 | 100 | protected ?URLInfo_Normalizer $normalizer = null; |
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * @var bool |
|
| 104 | - */ |
|
| 102 | + /** |
|
| 103 | + * @var bool |
|
| 104 | + */ |
|
| 105 | 105 | protected bool $encodeUTFChars = false; |
| 106 | 106 | |
| 107 | 107 | public function __construct(string $url) |
@@ -118,14 +118,14 @@ discard block |
||
| 118 | 118 | $this->info = $this->parser->getInfo(); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Whether to URL encode any non-encoded UTF8 characters in the URL. |
|
| 123 | - * Default is to leave them as-is for better readability, since |
|
| 124 | - * browsers handle this well. |
|
| 125 | - * |
|
| 126 | - * @param bool $enabled |
|
| 127 | - * @return URLInfo |
|
| 128 | - */ |
|
| 121 | + /** |
|
| 122 | + * Whether to URL encode any non-encoded UTF8 characters in the URL. |
|
| 123 | + * Default is to leave them as-is for better readability, since |
|
| 124 | + * browsers handle this well. |
|
| 125 | + * |
|
| 126 | + * @param bool $enabled |
|
| 127 | + * @return URLInfo |
|
| 128 | + */ |
|
| 129 | 129 | public function setUTFEncoding(bool $enabled=true) : URLInfo |
| 130 | 130 | { |
| 131 | 131 | if($this->encodeUTFChars !== $enabled) |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | return $this->encodeUTFChars; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Filters an URL: removes control characters and the |
|
| 147 | - * like to have a clean URL to work with. |
|
| 148 | - * |
|
| 149 | - * @param string $url |
|
| 150 | - * @return string |
|
| 151 | - */ |
|
| 145 | + /** |
|
| 146 | + * Filters an URL: removes control characters and the |
|
| 147 | + * like to have a clean URL to work with. |
|
| 148 | + * |
|
| 149 | + * @param string $url |
|
| 150 | + * @return string |
|
| 151 | + */ |
|
| 152 | 152 | public static function filterURL(string $url) |
| 153 | 153 | { |
| 154 | 154 | return URLInfo_Filter::filter($url); |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | return $this->info['type'] === self::TYPE_PHONE; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Whether the URL is a regular URL, not one of the |
|
| 183 | - * other types like a phone number or email address. |
|
| 184 | - * |
|
| 185 | - * @return bool |
|
| 186 | - */ |
|
| 181 | + /** |
|
| 182 | + * Whether the URL is a regular URL, not one of the |
|
| 183 | + * other types like a phone number or email address. |
|
| 184 | + * |
|
| 185 | + * @return bool |
|
| 186 | + */ |
|
| 187 | 187 | public function isURL() : bool |
| 188 | 188 | { |
| 189 | 189 | $host = $this->getHost(); |
@@ -195,20 +195,20 @@ discard block |
||
| 195 | 195 | return $this->parser->isValid(); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Retrieves the host name, or an empty string if none is present. |
|
| 200 | - * |
|
| 201 | - * @return string |
|
| 202 | - */ |
|
| 198 | + /** |
|
| 199 | + * Retrieves the host name, or an empty string if none is present. |
|
| 200 | + * |
|
| 201 | + * @return string |
|
| 202 | + */ |
|
| 203 | 203 | public function getHost() : string |
| 204 | 204 | { |
| 205 | 205 | return $this->getInfoKey('host'); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Retrieves the path, or an empty string if none is present. |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 208 | + /** |
|
| 209 | + * Retrieves the path, or an empty string if none is present. |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | 212 | public function getPath() : string |
| 213 | 213 | { |
| 214 | 214 | return $this->getInfoKey('path'); |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | return $this->getInfoKey('scheme'); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 229 | - * @return int |
|
| 230 | - */ |
|
| 227 | + /** |
|
| 228 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 229 | + * @return int |
|
| 230 | + */ |
|
| 231 | 231 | public function getPort() : int |
| 232 | 232 | { |
| 233 | 233 | $port = $this->getInfoKey('port'); |
@@ -239,13 +239,13 @@ discard block |
||
| 239 | 239 | return -1; |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Retrieves the raw query string, or an empty string if none is present. |
|
| 244 | - * |
|
| 245 | - * @return string |
|
| 246 | - * |
|
| 247 | - * @see URLInfo::getParams() |
|
| 248 | - */ |
|
| 242 | + /** |
|
| 243 | + * Retrieves the raw query string, or an empty string if none is present. |
|
| 244 | + * |
|
| 245 | + * @return string |
|
| 246 | + * |
|
| 247 | + * @see URLInfo::getParams() |
|
| 248 | + */ |
|
| 249 | 249 | public function getQuery() : string |
| 250 | 250 | { |
| 251 | 251 | return $this->getInfoKey('query'); |
@@ -261,20 +261,20 @@ discard block |
||
| 261 | 261 | return $this->getInfoKey('pass'); |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | - /** |
|
| 265 | - * Whether the URL contains a port number. |
|
| 266 | - * @return bool |
|
| 267 | - */ |
|
| 264 | + /** |
|
| 265 | + * Whether the URL contains a port number. |
|
| 266 | + * @return bool |
|
| 267 | + */ |
|
| 268 | 268 | public function hasPort() : bool |
| 269 | 269 | { |
| 270 | 270 | return $this->getPort() !== -1; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * Alias for the hasParams() method. |
|
| 275 | - * @return bool |
|
| 276 | - * @see URLInfo::hasParams() |
|
| 277 | - */ |
|
| 273 | + /** |
|
| 274 | + * Alias for the hasParams() method. |
|
| 275 | + * @return bool |
|
| 276 | + * @see URLInfo::hasParams() |
|
| 277 | + */ |
|
| 278 | 278 | public function hasQuery() : bool |
| 279 | 279 | { |
| 280 | 280 | return $this->hasParams(); |
@@ -319,23 +319,23 @@ discard block |
||
| 319 | 319 | return ''; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - /** |
|
| 323 | - * Retrieves a normalized URL: this ensures that all parameters |
|
| 324 | - * in the URL are always in the same order. |
|
| 325 | - * |
|
| 326 | - * @return string |
|
| 327 | - */ |
|
| 322 | + /** |
|
| 323 | + * Retrieves a normalized URL: this ensures that all parameters |
|
| 324 | + * in the URL are always in the same order. |
|
| 325 | + * |
|
| 326 | + * @return string |
|
| 327 | + */ |
|
| 328 | 328 | public function getNormalized() : string |
| 329 | 329 | { |
| 330 | 330 | return $this->normalize(true); |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | - /** |
|
| 334 | - * Like getNormalized(), but if a username and password are present |
|
| 335 | - * in the URL, returns the URL without them. |
|
| 336 | - * |
|
| 337 | - * @return string |
|
| 338 | - */ |
|
| 333 | + /** |
|
| 334 | + * Like getNormalized(), but if a username and password are present |
|
| 335 | + * in the URL, returns the URL without them. |
|
| 336 | + * |
|
| 337 | + * @return string |
|
| 338 | + */ |
|
| 339 | 339 | public function getNormalizedWithoutAuth() : string |
| 340 | 340 | { |
| 341 | 341 | return $this->normalize(false); |
@@ -356,25 +356,25 @@ discard block |
||
| 356 | 356 | return $this->normalizer->normalize(); |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - /** |
|
| 360 | - * Creates a hash of the URL, which can be used for comparisons. |
|
| 361 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
| 362 | - * the same links with a different parameter order will have the |
|
| 363 | - * same hash. |
|
| 364 | - * |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 359 | + /** |
|
| 360 | + * Creates a hash of the URL, which can be used for comparisons. |
|
| 361 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
| 362 | + * the same links with a different parameter order will have the |
|
| 363 | + * same hash. |
|
| 364 | + * |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | 367 | public function getHash() |
| 368 | 368 | { |
| 369 | 369 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - /** |
|
| 373 | - * Highlights the URL using HTML tags with specific highlighting |
|
| 374 | - * class names. |
|
| 375 | - * |
|
| 376 | - * @return string Will return an empty string if the URL is not valid. |
|
| 377 | - */ |
|
| 372 | + /** |
|
| 373 | + * Highlights the URL using HTML tags with specific highlighting |
|
| 374 | + * class names. |
|
| 375 | + * |
|
| 376 | + * @return string Will return an empty string if the URL is not valid. |
|
| 377 | + */ |
|
| 378 | 378 | public function getHighlighted() : string |
| 379 | 379 | { |
| 380 | 380 | if(!$this->isValid()) { |
@@ -408,15 +408,15 @@ discard block |
||
| 408 | 408 | return count($params); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - /** |
|
| 412 | - * Retrieves all parameters specified in the url, |
|
| 413 | - * if any, as an associative array. |
|
| 414 | - * |
|
| 415 | - * NOTE: Ignores parameters that have been added |
|
| 416 | - * to the excluded parameters list. |
|
| 417 | - * |
|
| 418 | - * @return array<string,string> |
|
| 419 | - */ |
|
| 411 | + /** |
|
| 412 | + * Retrieves all parameters specified in the url, |
|
| 413 | + * if any, as an associative array. |
|
| 414 | + * |
|
| 415 | + * NOTE: Ignores parameters that have been added |
|
| 416 | + * to the excluded parameters list. |
|
| 417 | + * |
|
| 418 | + * @return array<string,string> |
|
| 419 | + */ |
|
| 420 | 420 | public function getParams() : array |
| 421 | 421 | { |
| 422 | 422 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -434,22 +434,22 @@ discard block |
||
| 434 | 434 | return $keep; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - /** |
|
| 438 | - * Retrieves the names of all parameters present in the URL, if any. |
|
| 439 | - * @return string[] |
|
| 440 | - */ |
|
| 437 | + /** |
|
| 438 | + * Retrieves the names of all parameters present in the URL, if any. |
|
| 439 | + * @return string[] |
|
| 440 | + */ |
|
| 441 | 441 | public function getParamNames() : array |
| 442 | 442 | { |
| 443 | 443 | $params = $this->getParams(); |
| 444 | 444 | return array_keys($params); |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | - /** |
|
| 448 | - * Retrieves a specific parameter value from the URL. |
|
| 449 | - * |
|
| 450 | - * @param string $name |
|
| 451 | - * @return string The parameter value, or an empty string if it does not exist. |
|
| 452 | - */ |
|
| 447 | + /** |
|
| 448 | + * Retrieves a specific parameter value from the URL. |
|
| 449 | + * |
|
| 450 | + * @param string $name |
|
| 451 | + * @return string The parameter value, or an empty string if it does not exist. |
|
| 452 | + */ |
|
| 453 | 453 | public function getParam(string $name) : string |
| 454 | 454 | { |
| 455 | 455 | if(isset($this->info['params'][$name])) { |
@@ -459,16 +459,16 @@ discard block |
||
| 459 | 459 | return ''; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - /** |
|
| 463 | - * Excludes an URL parameter entirely if present: |
|
| 464 | - * the parser will act as if the parameter was not |
|
| 465 | - * even present in the source URL, effectively |
|
| 466 | - * stripping it. |
|
| 467 | - * |
|
| 468 | - * @param string $name |
|
| 469 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 470 | - * @return URLInfo |
|
| 471 | - */ |
|
| 462 | + /** |
|
| 463 | + * Excludes an URL parameter entirely if present: |
|
| 464 | + * the parser will act as if the parameter was not |
|
| 465 | + * even present in the source URL, effectively |
|
| 466 | + * stripping it. |
|
| 467 | + * |
|
| 468 | + * @param string $name |
|
| 469 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 470 | + * @return URLInfo |
|
| 471 | + */ |
|
| 472 | 472 | public function excludeParam(string $name, string $reason='') : URLInfo |
| 473 | 473 | { |
| 474 | 474 | if(!isset($this->excludedParams[$name])) |
@@ -521,14 +521,14 @@ discard block |
||
| 521 | 521 | return self::$typeLabels[$this->getType()]; |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - /** |
|
| 525 | - * Whether excluded parameters should be highlighted in |
|
| 526 | - * a different color in the URL when using the |
|
| 527 | - * {@link URLInfo::getHighlighted()} method. |
|
| 528 | - * |
|
| 529 | - * @param bool $highlight |
|
| 530 | - * @return URLInfo |
|
| 531 | - */ |
|
| 524 | + /** |
|
| 525 | + * Whether excluded parameters should be highlighted in |
|
| 526 | + * a different color in the URL when using the |
|
| 527 | + * {@link URLInfo::getHighlighted()} method. |
|
| 528 | + * |
|
| 529 | + * @param bool $highlight |
|
| 530 | + * @return URLInfo |
|
| 531 | + */ |
|
| 532 | 532 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
| 533 | 533 | { |
| 534 | 534 | $this->highlightExcluded = $highlight; |
@@ -584,24 +584,24 @@ discard block |
||
| 584 | 584 | return $this; |
| 585 | 585 | } |
| 586 | 586 | |
| 587 | - /** |
|
| 588 | - * Whether the parameter exclusion mode is enabled: |
|
| 589 | - * In this case, if any parameters have been added to the |
|
| 590 | - * exclusion list, all relevant methods will exclude these. |
|
| 591 | - * |
|
| 592 | - * @return bool |
|
| 593 | - */ |
|
| 587 | + /** |
|
| 588 | + * Whether the parameter exclusion mode is enabled: |
|
| 589 | + * In this case, if any parameters have been added to the |
|
| 590 | + * exclusion list, all relevant methods will exclude these. |
|
| 591 | + * |
|
| 592 | + * @return bool |
|
| 593 | + */ |
|
| 594 | 594 | public function isParamExclusionEnabled() : bool |
| 595 | 595 | { |
| 596 | 596 | return $this->paramExclusion; |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | - /** |
|
| 600 | - * Checks whether the link contains any parameters that |
|
| 601 | - * are on the list of excluded parameters. |
|
| 602 | - * |
|
| 603 | - * @return bool |
|
| 604 | - */ |
|
| 599 | + /** |
|
| 600 | + * Checks whether the link contains any parameters that |
|
| 601 | + * are on the list of excluded parameters. |
|
| 602 | + * |
|
| 603 | + * @return bool |
|
| 604 | + */ |
|
| 605 | 605 | public function containsExcludedParams() : bool |
| 606 | 606 | { |
| 607 | 607 | if(empty($this->excludedParams)) { |
@@ -672,16 +672,16 @@ discard block |
||
| 672 | 672 | return $this->highlightExcluded; |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - /** |
|
| 676 | - * Checks if the URL exists, i.e. can be connected to. Will return |
|
| 677 | - * true if the returned HTTP status code is `200` or `302`. |
|
| 678 | - * |
|
| 679 | - * NOTE: If the target URL requires HTTP authentication, the username |
|
| 680 | - * and password should be integrated into the URL. |
|
| 681 | - * |
|
| 682 | - * @return bool |
|
| 683 | - * @throws BaseException |
|
| 684 | - */ |
|
| 675 | + /** |
|
| 676 | + * Checks if the URL exists, i.e. can be connected to. Will return |
|
| 677 | + * true if the returned HTTP status code is `200` or `302`. |
|
| 678 | + * |
|
| 679 | + * NOTE: If the target URL requires HTTP authentication, the username |
|
| 680 | + * and password should be integrated into the URL. |
|
| 681 | + * |
|
| 682 | + * @return bool |
|
| 683 | + * @throws BaseException |
|
| 684 | + */ |
|
| 685 | 685 | public function tryConnect(bool $verifySSL=true) : bool |
| 686 | 686 | { |
| 687 | 687 | return $this->createConnectionTester() |
@@ -689,26 +689,26 @@ discard block |
||
| 689 | 689 | ->canConnect(); |
| 690 | 690 | } |
| 691 | 691 | |
| 692 | - /** |
|
| 693 | - * Creates the connection tester instance that is used |
|
| 694 | - * to check if a URL can be connected to, and which is |
|
| 695 | - * used in the {@see URLInfo::tryConnect()} method. It |
|
| 696 | - * allows more settings to be used. |
|
| 697 | - * |
|
| 698 | - * @return URLInfo_ConnectionTester |
|
| 699 | - */ |
|
| 692 | + /** |
|
| 693 | + * Creates the connection tester instance that is used |
|
| 694 | + * to check if a URL can be connected to, and which is |
|
| 695 | + * used in the {@see URLInfo::tryConnect()} method. It |
|
| 696 | + * allows more settings to be used. |
|
| 697 | + * |
|
| 698 | + * @return URLInfo_ConnectionTester |
|
| 699 | + */ |
|
| 700 | 700 | public function createConnectionTester() : URLInfo_ConnectionTester |
| 701 | 701 | { |
| 702 | 702 | return new URLInfo_ConnectionTester($this); |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - /** |
|
| 706 | - * Adds/overwrites an URL parameter. |
|
| 707 | - * |
|
| 708 | - * @param string $name |
|
| 709 | - * @param string $val |
|
| 710 | - * @return URLInfo |
|
| 711 | - */ |
|
| 705 | + /** |
|
| 706 | + * Adds/overwrites an URL parameter. |
|
| 707 | + * |
|
| 708 | + * @param string $name |
|
| 709 | + * @param string $val |
|
| 710 | + * @return URLInfo |
|
| 711 | + */ |
|
| 712 | 712 | public function setParam(string $name, string $val) : URLInfo |
| 713 | 713 | { |
| 714 | 714 | $this->info['params'][$name] = $val; |
@@ -716,13 +716,13 @@ discard block |
||
| 716 | 716 | return $this; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - /** |
|
| 720 | - * Removes an URL parameter. Has no effect if the |
|
| 721 | - * parameter is not present to begin with. |
|
| 722 | - * |
|
| 723 | - * @param string $param |
|
| 724 | - * @return URLInfo |
|
| 725 | - */ |
|
| 719 | + /** |
|
| 720 | + * Removes an URL parameter. Has no effect if the |
|
| 721 | + * parameter is not present to begin with. |
|
| 722 | + * |
|
| 723 | + * @param string $param |
|
| 724 | + * @return URLInfo |
|
| 725 | + */ |
|
| 726 | 726 | public function removeParam(string $param) : URLInfo |
| 727 | 727 | { |
| 728 | 728 | if(isset($this->info['params'][$param])) |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @var array<string,string>|NULL |
| 64 | 64 | * @see URLInfo::getTypeLabel() |
| 65 | 65 | */ |
| 66 | - protected static ?array $typeLabels = null; |
|
| 66 | + protected static ? array $typeLabels = null; |
|
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @var bool |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | * @param bool $enabled |
| 127 | 127 | * @return URLInfo |
| 128 | 128 | */ |
| 129 | - public function setUTFEncoding(bool $enabled=true) : URLInfo |
|
| 129 | + public function setUTFEncoding(bool $enabled = true) : URLInfo |
|
| 130 | 130 | { |
| 131 | - if($this->encodeUTFChars !== $enabled) |
|
| 131 | + if ($this->encodeUTFChars !== $enabled) |
|
| 132 | 132 | { |
| 133 | 133 | $this->encodeUTFChars = $enabled; |
| 134 | 134 | $this->parse(); // re-parse the URL to apply the changes |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | $port = $this->getInfoKey('port'); |
| 234 | 234 | |
| 235 | - if(!empty($port)) { |
|
| 235 | + if (!empty($port)) { |
|
| 236 | 236 | return (int)$port; |
| 237 | 237 | } |
| 238 | 238 | |
@@ -312,7 +312,7 @@ discard block |
||
| 312 | 312 | |
| 313 | 313 | protected function getInfoKey(string $name) : string |
| 314 | 314 | { |
| 315 | - if(isset($this->info[$name])) { |
|
| 315 | + if (isset($this->info[$name])) { |
|
| 316 | 316 | return (string)$this->info[$name]; |
| 317 | 317 | } |
| 318 | 318 | |
@@ -341,13 +341,13 @@ discard block |
||
| 341 | 341 | return $this->normalize(false); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - protected function normalize(bool $auth=true) : string |
|
| 344 | + protected function normalize(bool $auth = true) : string |
|
| 345 | 345 | { |
| 346 | - if(!$this->isValid()) { |
|
| 346 | + if (!$this->isValid()) { |
|
| 347 | 347 | return ''; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - if(!isset($this->normalizer)) { |
|
| 350 | + if (!isset($this->normalizer)) { |
|
| 351 | 351 | $this->normalizer = new URLInfo_Normalizer($this); |
| 352 | 352 | } |
| 353 | 353 | |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | */ |
| 378 | 378 | public function getHighlighted() : string |
| 379 | 379 | { |
| 380 | - if(!$this->isValid()) { |
|
| 380 | + if (!$this->isValid()) { |
|
| 381 | 381 | return ''; |
| 382 | 382 | } |
| 383 | 383 | |
@@ -419,14 +419,14 @@ discard block |
||
| 419 | 419 | */ |
| 420 | 420 | public function getParams() : array |
| 421 | 421 | { |
| 422 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 422 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 423 | 423 | return $this->info['params']; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | $keep = array(); |
| 427 | - foreach($this->info['params'] as $name => $value) |
|
| 427 | + foreach ($this->info['params'] as $name => $value) |
|
| 428 | 428 | { |
| 429 | - if(!isset($this->excludedParams[$name])) { |
|
| 429 | + if (!isset($this->excludedParams[$name])) { |
|
| 430 | 430 | $keep[$name] = $value; |
| 431 | 431 | } |
| 432 | 432 | } |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | */ |
| 453 | 453 | public function getParam(string $name) : string |
| 454 | 454 | { |
| 455 | - if(isset($this->info['params'][$name])) { |
|
| 455 | + if (isset($this->info['params'][$name])) { |
|
| 456 | 456 | return $this->info['params'][$name]; |
| 457 | 457 | } |
| 458 | 458 | |
@@ -469,9 +469,9 @@ discard block |
||
| 469 | 469 | * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
| 470 | 470 | * @return URLInfo |
| 471 | 471 | */ |
| 472 | - public function excludeParam(string $name, string $reason='') : URLInfo |
|
| 472 | + public function excludeParam(string $name, string $reason = '') : URLInfo |
|
| 473 | 473 | { |
| 474 | - if(!isset($this->excludedParams[$name])) |
|
| 474 | + if (!isset($this->excludedParams[$name])) |
|
| 475 | 475 | { |
| 476 | 476 | $this->excludedParams[$name] = $reason; |
| 477 | 477 | $this->setParamExclusion(); |
@@ -497,7 +497,7 @@ discard block |
||
| 497 | 497 | |
| 498 | 498 | public function getTypeLabel() : string |
| 499 | 499 | { |
| 500 | - if(!isset(self::$typeLabels)) |
|
| 500 | + if (!isset(self::$typeLabels)) |
|
| 501 | 501 | { |
| 502 | 502 | self::$typeLabels = array( |
| 503 | 503 | self::TYPE_EMAIL => t('Email'), |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | |
| 510 | 510 | $type = $this->getType(); |
| 511 | 511 | |
| 512 | - if(!isset(self::$typeLabels[$type])) |
|
| 512 | + if (!isset(self::$typeLabels[$type])) |
|
| 513 | 513 | { |
| 514 | 514 | throw new BaseException( |
| 515 | 515 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | * @param bool $highlight |
| 530 | 530 | * @return URLInfo |
| 531 | 531 | */ |
| 532 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
| 532 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
| 533 | 533 | { |
| 534 | 534 | $this->highlightExcluded = $highlight; |
| 535 | 535 | return $this; |
@@ -578,7 +578,7 @@ discard block |
||
| 578 | 578 | * @see URLInfo::isParamExclusionEnabled() |
| 579 | 579 | * @see URLInfo::setHighlightExcluded() |
| 580 | 580 | */ |
| 581 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
| 581 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
| 582 | 582 | { |
| 583 | 583 | $this->paramExclusion = $enabled; |
| 584 | 584 | return $this; |
@@ -604,13 +604,13 @@ discard block |
||
| 604 | 604 | */ |
| 605 | 605 | public function containsExcludedParams() : bool |
| 606 | 606 | { |
| 607 | - if(empty($this->excludedParams)) { |
|
| 607 | + if (empty($this->excludedParams)) { |
|
| 608 | 608 | return false; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | $names = array_keys($this->info['params']); |
| 612 | - foreach($names as $name) { |
|
| 613 | - if(isset($this->excludedParams[$name])) { |
|
| 612 | + foreach ($names as $name) { |
|
| 613 | + if (isset($this->excludedParams[$name])) { |
|
| 614 | 614 | return true; |
| 615 | 615 | } |
| 616 | 616 | } |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | |
| 627 | 627 | public function offsetSet($offset, $value) |
| 628 | 628 | { |
| 629 | - if(in_array($offset, $this->infoKeys)) { |
|
| 629 | + if (in_array($offset, $this->infoKeys)) { |
|
| 630 | 630 | $this->info[$offset] = $value; |
| 631 | 631 | } |
| 632 | 632 | } |
@@ -643,11 +643,11 @@ discard block |
||
| 643 | 643 | |
| 644 | 644 | public function offsetGet($offset) |
| 645 | 645 | { |
| 646 | - if($offset === 'port') { |
|
| 646 | + if ($offset === 'port') { |
|
| 647 | 647 | return $this->getPort(); |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - if(in_array($offset, $this->infoKeys)) { |
|
| 650 | + if (in_array($offset, $this->infoKeys)) { |
|
| 651 | 651 | return $this->getInfoKey($offset); |
| 652 | 652 | } |
| 653 | 653 | |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | * @return bool |
| 683 | 683 | * @throws BaseException |
| 684 | 684 | */ |
| 685 | - public function tryConnect(bool $verifySSL=true) : bool |
|
| 685 | + public function tryConnect(bool $verifySSL = true) : bool |
|
| 686 | 686 | { |
| 687 | 687 | return $this->createConnectionTester() |
| 688 | 688 | ->setVerifySSL($verifySSL) |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | */ |
| 726 | 726 | public function removeParam(string $param) : URLInfo |
| 727 | 727 | { |
| 728 | - if(isset($this->info['params'][$param])) |
|
| 728 | + if (isset($this->info['params'][$param])) |
|
| 729 | 729 | { |
| 730 | 730 | unset($this->info['params'][$param]); |
| 731 | 731 | } |
@@ -516,8 +516,7 @@ |
||
| 516 | 516 | if(isset($options['relative-path']) && $options['relative-path'] === true) |
| 517 | 517 | { |
| 518 | 518 | $finder->setPathmodeRelative(); |
| 519 | - } |
|
| 520 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 519 | + } else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 521 | 520 | { |
| 522 | 521 | $finder->setPathmodeAbsolute(); |
| 523 | 522 | } |
@@ -73,18 +73,18 @@ discard block |
||
| 73 | 73 | public const ERROR_PATH_NOT_WRITABLE = 340039; |
| 74 | 74 | public const ERROR_PATH_INVALID = 340040; |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Opens a serialized file and returns the unserialized data. |
|
| 78 | - * |
|
| 79 | - * @param string $file |
|
| 80 | - * @throws FileHelper_Exception |
|
| 81 | - * @return array<int|string,mixed> |
|
| 82 | - * @see SerializedFile::parse() |
|
| 83 | - * |
|
| 84 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 85 | - * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
| 86 | - * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
| 87 | - */ |
|
| 76 | + /** |
|
| 77 | + * Opens a serialized file and returns the unserialized data. |
|
| 78 | + * |
|
| 79 | + * @param string $file |
|
| 80 | + * @throws FileHelper_Exception |
|
| 81 | + * @return array<int|string,mixed> |
|
| 82 | + * @see SerializedFile::parse() |
|
| 83 | + * |
|
| 84 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 85 | + * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
| 86 | + * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
| 87 | + */ |
|
| 88 | 88 | public static function parseSerializedFile(string $file) : array |
| 89 | 89 | { |
| 90 | 90 | return SerializedFile::factory(self::getFileInfo($file)) |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | return FolderTree::delete($rootFolder); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Create a folder, if it does not exist yet. |
|
| 109 | - * |
|
| 110 | - * @param string|PathInfoInterface $path |
|
| 111 | - * @throws FileHelper_Exception |
|
| 112 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 113 | - */ |
|
| 107 | + /** |
|
| 108 | + * Create a folder, if it does not exist yet. |
|
| 109 | + * |
|
| 110 | + * @param string|PathInfoInterface $path |
|
| 111 | + * @throws FileHelper_Exception |
|
| 112 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 113 | + */ |
|
| 114 | 114 | public static function createFolder($path) : FolderInfo |
| 115 | 115 | { |
| 116 | 116 | return self::getFolderInfo($path)->create(); |
@@ -138,36 +138,36 @@ discard block |
||
| 138 | 138 | FolderTree::copy($source, $target); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Copies a file to the target location. Includes checks |
|
| 143 | - * for most error sources, like the source file not being |
|
| 144 | - * readable. Automatically creates the target folder if it |
|
| 145 | - * does not exist yet. |
|
| 146 | - * |
|
| 147 | - * @param string $sourcePath |
|
| 148 | - * @param string $targetPath |
|
| 149 | - * @throws FileHelper_Exception |
|
| 150 | - * |
|
| 151 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 152 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
| 153 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
| 154 | - * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
| 155 | - * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
| 156 | - */ |
|
| 141 | + /** |
|
| 142 | + * Copies a file to the target location. Includes checks |
|
| 143 | + * for most error sources, like the source file not being |
|
| 144 | + * readable. Automatically creates the target folder if it |
|
| 145 | + * does not exist yet. |
|
| 146 | + * |
|
| 147 | + * @param string $sourcePath |
|
| 148 | + * @param string $targetPath |
|
| 149 | + * @throws FileHelper_Exception |
|
| 150 | + * |
|
| 151 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 152 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
| 153 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
| 154 | + * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
| 155 | + * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
| 156 | + */ |
|
| 157 | 157 | public static function copyFile(string $sourcePath, string $targetPath) : void |
| 158 | 158 | { |
| 159 | 159 | self::getFileInfo($sourcePath)->copyTo($targetPath); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Deletes the target file. Ignored if it cannot be found, |
|
| 164 | - * and throws an exception if it fails. |
|
| 165 | - * |
|
| 166 | - * @param string $filePath |
|
| 167 | - * @throws FileHelper_Exception |
|
| 168 | - * |
|
| 169 | - * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
| 170 | - */ |
|
| 162 | + /** |
|
| 163 | + * Deletes the target file. Ignored if it cannot be found, |
|
| 164 | + * and throws an exception if it fails. |
|
| 165 | + * |
|
| 166 | + * @param string $filePath |
|
| 167 | + * @throws FileHelper_Exception |
|
| 168 | + * |
|
| 169 | + * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
| 170 | + */ |
|
| 171 | 171 | public static function deleteFile(string $filePath) : void |
| 172 | 172 | { |
| 173 | 173 | self::getFileInfo($filePath)->delete(); |
@@ -272,29 +272,29 @@ discard block |
||
| 272 | 272 | ->download(); |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - /** |
|
| 276 | - * Verifies whether the target file is a PHP file. The path |
|
| 277 | - * to the file can be a path to a file as a string, or a |
|
| 278 | - * DirectoryIterator object instance. |
|
| 279 | - * |
|
| 280 | - * @param string|DirectoryIterator $pathOrDirIterator |
|
| 281 | - * @return boolean |
|
| 282 | - */ |
|
| 275 | + /** |
|
| 276 | + * Verifies whether the target file is a PHP file. The path |
|
| 277 | + * to the file can be a path to a file as a string, or a |
|
| 278 | + * DirectoryIterator object instance. |
|
| 279 | + * |
|
| 280 | + * @param string|DirectoryIterator $pathOrDirIterator |
|
| 281 | + * @return boolean |
|
| 282 | + */ |
|
| 283 | 283 | public static function isPHPFile($pathOrDirIterator) : bool |
| 284 | 284 | { |
| 285 | - return self::getExtension($pathOrDirIterator) === 'php'; |
|
| 285 | + return self::getExtension($pathOrDirIterator) === 'php'; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | - /** |
|
| 289 | - * Retrieves the extension of the specified file. Can be a path |
|
| 290 | - * to a file as a string, or a DirectoryIterator object instance. |
|
| 291 | - * |
|
| 292 | - * NOTE: A folder will return an empty string. |
|
| 293 | - * |
|
| 294 | - * @param string|DirectoryIterator $pathOrDirIterator |
|
| 295 | - * @param bool $lowercase |
|
| 296 | - * @return string |
|
| 297 | - */ |
|
| 288 | + /** |
|
| 289 | + * Retrieves the extension of the specified file. Can be a path |
|
| 290 | + * to a file as a string, or a DirectoryIterator object instance. |
|
| 291 | + * |
|
| 292 | + * NOTE: A folder will return an empty string. |
|
| 293 | + * |
|
| 294 | + * @param string|DirectoryIterator $pathOrDirIterator |
|
| 295 | + * @param bool $lowercase |
|
| 296 | + * @return string |
|
| 297 | + */ |
|
| 298 | 298 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
| 299 | 299 | { |
| 300 | 300 | $info = self::getPathInfo($pathOrDirIterator); |
@@ -307,18 +307,18 @@ discard block |
||
| 307 | 307 | return ''; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * Retrieves the file name from a path, with or without extension. |
|
| 312 | - * The path to the file can be a string, or a DirectoryIterator object |
|
| 313 | - * instance. |
|
| 314 | - * |
|
| 315 | - * In case of folders, behaves like the "pathinfo" function: returns |
|
| 316 | - * the name of the folder. |
|
| 317 | - * |
|
| 318 | - * @param string|DirectoryIterator $pathOrDirIterator |
|
| 319 | - * @param bool $extension |
|
| 320 | - * @return string |
|
| 321 | - */ |
|
| 310 | + /** |
|
| 311 | + * Retrieves the file name from a path, with or without extension. |
|
| 312 | + * The path to the file can be a string, or a DirectoryIterator object |
|
| 313 | + * instance. |
|
| 314 | + * |
|
| 315 | + * In case of folders, behaves like the "pathinfo" function: returns |
|
| 316 | + * the name of the folder. |
|
| 317 | + * |
|
| 318 | + * @param string|DirectoryIterator $pathOrDirIterator |
|
| 319 | + * @param bool $extension |
|
| 320 | + * @return string |
|
| 321 | + */ |
|
| 322 | 322 | public static function getFilename($pathOrDirIterator, bool $extension = true) : string |
| 323 | 323 | { |
| 324 | 324 | $info = self::getPathInfo($pathOrDirIterator); |
@@ -352,16 +352,16 @@ discard block |
||
| 352 | 352 | ->parse(); |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * Corrects common formatting mistakes when users enter |
|
| 357 | - * file names, like too many spaces, dots and the like. |
|
| 358 | - * |
|
| 359 | - * NOTE: if the file name contains a path, the path is |
|
| 360 | - * stripped, leaving only the file name. |
|
| 361 | - * |
|
| 362 | - * @param string $name |
|
| 363 | - * @return string |
|
| 364 | - */ |
|
| 355 | + /** |
|
| 356 | + * Corrects common formatting mistakes when users enter |
|
| 357 | + * file names, like too many spaces, dots and the like. |
|
| 358 | + * |
|
| 359 | + * NOTE: if the file name contains a path, the path is |
|
| 360 | + * stripped, leaving only the file name. |
|
| 361 | + * |
|
| 362 | + * @param string $name |
|
| 363 | + * @return string |
|
| 364 | + */ |
|
| 365 | 365 | public static function fixFileName(string $name) : string |
| 366 | 366 | { |
| 367 | 367 | return NameFixer::fixName($name); |
@@ -421,23 +421,23 @@ discard block |
||
| 421 | 421 | return self::findFiles($targetFolder, array('php'), $options); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - /** |
|
| 425 | - * Finds files according to the specified options. |
|
| 426 | - * |
|
| 427 | - * NOTE: This method only exists for backwards compatibility. |
|
| 428 | - * Use the {@see FileHelper::createFileFinder()} method instead, |
|
| 429 | - * which offers an object-oriented interface that is much easier |
|
| 430 | - * to use. |
|
| 431 | - * |
|
| 432 | - * @param string|PathInfoInterface|DirectoryIterator $targetFolder |
|
| 433 | - * @param string[] $extensions |
|
| 434 | - * @param array<string,mixed> $options |
|
| 435 | - * @throws FileHelper_Exception |
|
| 436 | - * @return string[] |
|
| 437 | - * |
|
| 438 | - * @see FileHelper::createFileFinder() |
|
| 439 | - * @deprecated Use the file finder instead. |
|
| 440 | - */ |
|
| 424 | + /** |
|
| 425 | + * Finds files according to the specified options. |
|
| 426 | + * |
|
| 427 | + * NOTE: This method only exists for backwards compatibility. |
|
| 428 | + * Use the {@see FileHelper::createFileFinder()} method instead, |
|
| 429 | + * which offers an object-oriented interface that is much easier |
|
| 430 | + * to use. |
|
| 431 | + * |
|
| 432 | + * @param string|PathInfoInterface|DirectoryIterator $targetFolder |
|
| 433 | + * @param string[] $extensions |
|
| 434 | + * @param array<string,mixed> $options |
|
| 435 | + * @throws FileHelper_Exception |
|
| 436 | + * @return string[] |
|
| 437 | + * |
|
| 438 | + * @see FileHelper::createFileFinder() |
|
| 439 | + * @deprecated Use the file finder instead. |
|
| 440 | + */ |
|
| 441 | 441 | public static function findFiles($targetFolder, array $extensions=array(), array $options=array()) : array |
| 442 | 442 | { |
| 443 | 443 | $finder = self::createFileFinder($targetFolder); |
@@ -467,14 +467,14 @@ discard block |
||
| 467 | 467 | return $finder->getAll(); |
| 468 | 468 | } |
| 469 | 469 | |
| 470 | - /** |
|
| 471 | - * Removes the extension from the specified path or file name, |
|
| 472 | - * if any, and returns the name without the extension. |
|
| 473 | - * |
|
| 474 | - * @param string $filename |
|
| 475 | - * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to. |
|
| 476 | - * @return string |
|
| 477 | - */ |
|
| 470 | + /** |
|
| 471 | + * Removes the extension from the specified path or file name, |
|
| 472 | + * if any, and returns the name without the extension. |
|
| 473 | + * |
|
| 474 | + * @param string $filename |
|
| 475 | + * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to. |
|
| 476 | + * @return string |
|
| 477 | + */ |
|
| 478 | 478 | public static function removeExtension(string $filename, bool $keepPath=false) : string |
| 479 | 479 | { |
| 480 | 480 | return self::getFileInfo($filename)->removeExtension($keepPath); |
@@ -495,49 +495,49 @@ discard block |
||
| 495 | 495 | return self::$unicodeHandling; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | - /** |
|
| 499 | - * Normalizes the slash style in a file or folder path, |
|
| 500 | - * by replacing any anti-slashes with forward slashes. |
|
| 501 | - * |
|
| 502 | - * @param string $path |
|
| 503 | - * @return string |
|
| 504 | - */ |
|
| 498 | + /** |
|
| 499 | + * Normalizes the slash style in a file or folder path, |
|
| 500 | + * by replacing any anti-slashes with forward slashes. |
|
| 501 | + * |
|
| 502 | + * @param string $path |
|
| 503 | + * @return string |
|
| 504 | + */ |
|
| 505 | 505 | public static function normalizePath(string $path) : string |
| 506 | 506 | { |
| 507 | 507 | return str_replace(array('\\', '//'), array('/', '/'), $path); |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | - /** |
|
| 511 | - * Saves the specified data to a file, JSON encoded. |
|
| 512 | - * |
|
| 513 | - * @param mixed $data |
|
| 514 | - * @param string $file |
|
| 515 | - * @param bool $pretty |
|
| 516 | - * @throws FileHelper_Exception |
|
| 517 | - * |
|
| 518 | - * @see FileHelper::ERROR_JSON_ENCODE_ERROR |
|
| 519 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 520 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 521 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 522 | - */ |
|
| 510 | + /** |
|
| 511 | + * Saves the specified data to a file, JSON encoded. |
|
| 512 | + * |
|
| 513 | + * @param mixed $data |
|
| 514 | + * @param string $file |
|
| 515 | + * @param bool $pretty |
|
| 516 | + * @throws FileHelper_Exception |
|
| 517 | + * |
|
| 518 | + * @see FileHelper::ERROR_JSON_ENCODE_ERROR |
|
| 519 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 520 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 521 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 522 | + */ |
|
| 523 | 523 | public static function saveAsJSON($data, string $file, bool $pretty=false) : void |
| 524 | 524 | { |
| 525 | 525 | JSONFile::factory(self::getFileInfo($file)) |
| 526 | 526 | ->putData($data, $pretty); |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - /** |
|
| 530 | - * Saves the specified content to the target file, creating |
|
| 531 | - * the file and the folder as necessary. |
|
| 532 | - * |
|
| 533 | - * @param string $filePath |
|
| 534 | - * @param string $content |
|
| 535 | - * @throws FileHelper_Exception |
|
| 536 | - * |
|
| 537 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 538 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 539 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 540 | - */ |
|
| 529 | + /** |
|
| 530 | + * Saves the specified content to the target file, creating |
|
| 531 | + * the file and the folder as necessary. |
|
| 532 | + * |
|
| 533 | + * @param string $filePath |
|
| 534 | + * @param string $content |
|
| 535 | + * @throws FileHelper_Exception |
|
| 536 | + * |
|
| 537 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
| 538 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
| 539 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
| 540 | + */ |
|
| 541 | 541 | public static function saveFile(string $filePath, string $content='') : void |
| 542 | 542 | { |
| 543 | 543 | self::getFileInfo($filePath)->putContents($content); |
@@ -602,14 +602,14 @@ discard block |
||
| 602 | 602 | return $output; |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - /** |
|
| 606 | - * Retrieves the last modified date for the specified file or folder. |
|
| 607 | - * |
|
| 608 | - * Note: If the target does not exist, returns null. |
|
| 609 | - * |
|
| 610 | - * @param string $path |
|
| 611 | - * @return DateTime|NULL |
|
| 612 | - */ |
|
| 605 | + /** |
|
| 606 | + * Retrieves the last modified date for the specified file or folder. |
|
| 607 | + * |
|
| 608 | + * Note: If the target does not exist, returns null. |
|
| 609 | + * |
|
| 610 | + * @param string $path |
|
| 611 | + * @return DateTime|NULL |
|
| 612 | + */ |
|
| 613 | 613 | public static function getModifiedDate(string $path) : ?DateTime |
| 614 | 614 | { |
| 615 | 615 | $time = filemtime($path); |
@@ -649,70 +649,70 @@ discard block |
||
| 649 | 649 | ->getPaths(); |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - /** |
|
| 653 | - * Retrieves the maximum allowed upload file size, in bytes. |
|
| 654 | - * Takes into account the PHP ini settings <code>post_max_size</code> |
|
| 655 | - * and <code>upload_max_filesize</code>. Since these cannot |
|
| 656 | - * be modified at runtime, they are the hard limits for uploads. |
|
| 657 | - * |
|
| 658 | - * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
| 659 | - * |
|
| 660 | - * @return int Will return <code>-1</code> if no limit. |
|
| 661 | - */ |
|
| 652 | + /** |
|
| 653 | + * Retrieves the maximum allowed upload file size, in bytes. |
|
| 654 | + * Takes into account the PHP ini settings <code>post_max_size</code> |
|
| 655 | + * and <code>upload_max_filesize</code>. Since these cannot |
|
| 656 | + * be modified at runtime, they are the hard limits for uploads. |
|
| 657 | + * |
|
| 658 | + * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
| 659 | + * |
|
| 660 | + * @return int Will return <code>-1</code> if no limit. |
|
| 661 | + */ |
|
| 662 | 662 | public static function getMaxUploadFilesize() : int |
| 663 | 663 | { |
| 664 | 664 | return UploadFileSizeInfo::getFileSize(); |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - /** |
|
| 668 | - * Makes a path relative using a folder depth: will reduce the |
|
| 669 | - * length of the path so that only the amount of folders defined |
|
| 670 | - * in the <code>$depth</code> attribute are shown below the actual |
|
| 671 | - * folder or file in the path. |
|
| 672 | - * |
|
| 673 | - * @param string $path The absolute or relative path |
|
| 674 | - * @param int $depth The folder depth to reduce the path to |
|
| 675 | - * @return string |
|
| 676 | - */ |
|
| 667 | + /** |
|
| 668 | + * Makes a path relative using a folder depth: will reduce the |
|
| 669 | + * length of the path so that only the amount of folders defined |
|
| 670 | + * in the <code>$depth</code> attribute are shown below the actual |
|
| 671 | + * folder or file in the path. |
|
| 672 | + * |
|
| 673 | + * @param string $path The absolute or relative path |
|
| 674 | + * @param int $depth The folder depth to reduce the path to |
|
| 675 | + * @return string |
|
| 676 | + */ |
|
| 677 | 677 | public static function relativizePathByDepth(string $path, int $depth=2) : string |
| 678 | 678 | { |
| 679 | 679 | return PathRelativizer::relativizeByDepth($path, $depth); |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | - /** |
|
| 683 | - * Makes the specified path relative to another path, |
|
| 684 | - * by removing one from the other if found. Also |
|
| 685 | - * normalizes the path to use forward slashes. |
|
| 686 | - * |
|
| 687 | - * Example: |
|
| 688 | - * |
|
| 689 | - * <pre> |
|
| 690 | - * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
| 691 | - * </pre> |
|
| 692 | - * |
|
| 693 | - * Result: <code>to/file.txt</code> |
|
| 694 | - * |
|
| 695 | - * @param string $path |
|
| 696 | - * @param string $relativeTo |
|
| 697 | - * @return string |
|
| 698 | - */ |
|
| 682 | + /** |
|
| 683 | + * Makes the specified path relative to another path, |
|
| 684 | + * by removing one from the other if found. Also |
|
| 685 | + * normalizes the path to use forward slashes. |
|
| 686 | + * |
|
| 687 | + * Example: |
|
| 688 | + * |
|
| 689 | + * <pre> |
|
| 690 | + * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
| 691 | + * </pre> |
|
| 692 | + * |
|
| 693 | + * Result: <code>to/file.txt</code> |
|
| 694 | + * |
|
| 695 | + * @param string $path |
|
| 696 | + * @param string $relativeTo |
|
| 697 | + * @return string |
|
| 698 | + */ |
|
| 699 | 699 | public static function relativizePath(string $path, string $relativeTo) : string |
| 700 | 700 | { |
| 701 | 701 | return PathRelativizer::relativize($path, $relativeTo); |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - /** |
|
| 705 | - * Checks that the target file exists, and throws an exception |
|
| 706 | - * if it does not. |
|
| 707 | - * |
|
| 708 | - * @param string|DirectoryIterator $path |
|
| 709 | - * @param int|NULL $errorCode Optional custom error code |
|
| 710 | - * @throws FileHelper_Exception |
|
| 711 | - * @return string The real path to the file |
|
| 712 | - * |
|
| 713 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 714 | - * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
|
| 715 | - */ |
|
| 704 | + /** |
|
| 705 | + * Checks that the target file exists, and throws an exception |
|
| 706 | + * if it does not. |
|
| 707 | + * |
|
| 708 | + * @param string|DirectoryIterator $path |
|
| 709 | + * @param int|NULL $errorCode Optional custom error code |
|
| 710 | + * @throws FileHelper_Exception |
|
| 711 | + * @return string The real path to the file |
|
| 712 | + * |
|
| 713 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 714 | + * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
|
| 715 | + */ |
|
| 716 | 716 | public static function requireFileExists($path, ?int $errorCode=null) : string |
| 717 | 717 | { |
| 718 | 718 | return self::getPathInfo($path) |
@@ -735,18 +735,18 @@ discard block |
||
| 735 | 735 | ->getPath(); |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - /** |
|
| 739 | - * Reads a specific line number from the target file and returns its |
|
| 740 | - * contents, if the file has such a line. Does so with little memory |
|
| 741 | - * usage, as the file is not read entirely into memory. |
|
| 742 | - * |
|
| 743 | - * @param string $path |
|
| 744 | - * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
| 745 | - * @return string|NULL Will return null if the requested line does not exist. |
|
| 746 | - * @throws FileHelper_Exception |
|
| 747 | - * |
|
| 748 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 749 | - */ |
|
| 738 | + /** |
|
| 739 | + * Reads a specific line number from the target file and returns its |
|
| 740 | + * contents, if the file has such a line. Does so with little memory |
|
| 741 | + * usage, as the file is not read entirely into memory. |
|
| 742 | + * |
|
| 743 | + * @param string $path |
|
| 744 | + * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
| 745 | + * @return string|NULL Will return null if the requested line does not exist. |
|
| 746 | + * @throws FileHelper_Exception |
|
| 747 | + * |
|
| 748 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 749 | + */ |
|
| 750 | 750 | public static function getLineFromFile(string $path, int $lineNumber) : ?string |
| 751 | 751 | { |
| 752 | 752 | return self::getFileInfo($path) |
@@ -823,33 +823,33 @@ discard block |
||
| 823 | 823 | ->getLines($amount); |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | - /** |
|
| 827 | - * Reads all content from a file. |
|
| 828 | - * |
|
| 829 | - * @param string $filePath |
|
| 830 | - * @throws FileHelper_Exception |
|
| 831 | - * @return string |
|
| 832 | - * |
|
| 833 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 834 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 835 | - */ |
|
| 826 | + /** |
|
| 827 | + * Reads all content from a file. |
|
| 828 | + * |
|
| 829 | + * @param string $filePath |
|
| 830 | + * @throws FileHelper_Exception |
|
| 831 | + * @return string |
|
| 832 | + * |
|
| 833 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 834 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 835 | + */ |
|
| 836 | 836 | public static function readContents(string $filePath) : string |
| 837 | 837 | { |
| 838 | 838 | return self::getFileInfo($filePath)->getContents(); |
| 839 | 839 | } |
| 840 | 840 | |
| 841 | - /** |
|
| 842 | - * Ensures that the target path exists on disk, and is a folder. |
|
| 843 | - * |
|
| 844 | - * @param string $path |
|
| 845 | - * @return string The real path, with normalized slashes. |
|
| 846 | - * @throws FileHelper_Exception |
|
| 847 | - * |
|
| 848 | - * @see FileHelper::normalizePath() |
|
| 849 | - * |
|
| 850 | - * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST |
|
| 851 | - * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 852 | - */ |
|
| 841 | + /** |
|
| 842 | + * Ensures that the target path exists on disk, and is a folder. |
|
| 843 | + * |
|
| 844 | + * @param string $path |
|
| 845 | + * @return string The real path, with normalized slashes. |
|
| 846 | + * @throws FileHelper_Exception |
|
| 847 | + * |
|
| 848 | + * @see FileHelper::normalizePath() |
|
| 849 | + * |
|
| 850 | + * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST |
|
| 851 | + * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 852 | + */ |
|
| 853 | 853 | public static function requireFolderExists(string $path) : string |
| 854 | 854 | { |
| 855 | 855 | return self::getFolderInfo($path) |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public static function detectMimeType(string $fileName) : ?string |
| 208 | 208 | { |
| 209 | 209 | $ext = self::getExtension($fileName); |
| 210 | - if(empty($ext)) { |
|
| 210 | + if (empty($ext)) { |
|
| 211 | 211 | return null; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 248 | 248 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
| 249 | 249 | */ |
| 250 | - public static function sendFile(string $filePath, ?string $fileName = null, bool $asAttachment=true) : void |
|
| 250 | + public static function sendFile(string $filePath, ?string $fileName = null, bool $asAttachment = true) : void |
|
| 251 | 251 | { |
| 252 | 252 | self::getFileInfo($filePath)->getDownloader()->send($fileName, $asAttachment); |
| 253 | 253 | } |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @throws FileHelper_Exception |
| 265 | 265 | * @see FileHelper::ERROR_CANNOT_OPEN_URL |
| 266 | 266 | */ |
| 267 | - public static function downloadFile(string $url, int $timeout=0, bool $SSLEnabled=false) : string |
|
| 267 | + public static function downloadFile(string $url, int $timeout = 0, bool $SSLEnabled = false) : string |
|
| 268 | 268 | { |
| 269 | 269 | return FileDownloader::factory($url) |
| 270 | 270 | ->setTimeout($timeout) |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | { |
| 300 | 300 | $info = self::getPathInfo($pathOrDirIterator); |
| 301 | 301 | |
| 302 | - if($info instanceof FileInfo) |
|
| 302 | + if ($info instanceof FileInfo) |
|
| 303 | 303 | { |
| 304 | 304 | return $info->getExtension($lowercase); |
| 305 | 305 | } |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | { |
| 324 | 324 | $info = self::getPathInfo($pathOrDirIterator); |
| 325 | 325 | |
| 326 | - if($extension === true || $info instanceof FolderInfo) |
|
| 326 | + if ($extension === true || $info instanceof FolderInfo) |
|
| 327 | 327 | { |
| 328 | 328 | return $info->getName(); |
| 329 | 329 | } |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
| 345 | 345 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
| 346 | 346 | */ |
| 347 | - public static function parseJSONFile(string $file, string $targetEncoding='', $sourceEncoding=null) : array |
|
| 347 | + public static function parseJSONFile(string $file, string $targetEncoding = '', $sourceEncoding = null) : array |
|
| 348 | 348 | { |
| 349 | 349 | return JSONFile::factory(self::getFileInfo($file)) |
| 350 | 350 | ->setTargetEncoding($targetEncoding) |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | * @throws FileHelper_Exception |
| 398 | 398 | * @see FileHelper::createFileFinder() |
| 399 | 399 | */ |
| 400 | - public static function findHTMLFiles(string $targetFolder, array $options=array()) : array |
|
| 400 | + public static function findHTMLFiles(string $targetFolder, array $options = array()) : array |
|
| 401 | 401 | { |
| 402 | 402 | return self::findFiles($targetFolder, array('html'), $options); |
| 403 | 403 | } |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @throws FileHelper_Exception |
| 417 | 417 | * @see FileHelper::createFileFinder() |
| 418 | 418 | */ |
| 419 | - public static function findPHPFiles(string $targetFolder, array $options=array()) : array |
|
| 419 | + public static function findPHPFiles(string $targetFolder, array $options = array()) : array |
|
| 420 | 420 | { |
| 421 | 421 | return self::findFiles($targetFolder, array('php'), $options); |
| 422 | 422 | } |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | * @see FileHelper::createFileFinder() |
| 439 | 439 | * @deprecated Use the file finder instead. |
| 440 | 440 | */ |
| 441 | - public static function findFiles($targetFolder, array $extensions=array(), array $options=array()) : array |
|
| 441 | + public static function findFiles($targetFolder, array $extensions = array(), array $options = array()) : array |
|
| 442 | 442 | { |
| 443 | 443 | $finder = self::createFileFinder($targetFolder); |
| 444 | 444 | |
@@ -448,16 +448,16 @@ discard block |
||
| 448 | 448 | |
| 449 | 449 | $finder->setPathmodeStrip(); |
| 450 | 450 | |
| 451 | - if(isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 451 | + if (isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 452 | 452 | { |
| 453 | 453 | $finder->setPathmodeRelative(); |
| 454 | 454 | } |
| 455 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 455 | + else if (isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 456 | 456 | { |
| 457 | 457 | $finder->setPathmodeAbsolute(); |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if(isset($options['strip-extension'])) |
|
| 460 | + if (isset($options['strip-extension'])) |
|
| 461 | 461 | { |
| 462 | 462 | $finder->stripExtensions(); |
| 463 | 463 | } |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to. |
| 476 | 476 | * @return string |
| 477 | 477 | */ |
| 478 | - public static function removeExtension(string $filename, bool $keepPath=false) : string |
|
| 478 | + public static function removeExtension(string $filename, bool $keepPath = false) : string |
|
| 479 | 479 | { |
| 480 | 480 | return self::getFileInfo($filename)->removeExtension($keepPath); |
| 481 | 481 | } |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | public static function createUnicodeHandling() : UnicodeHandling |
| 489 | 489 | { |
| 490 | - if(!isset(self::$unicodeHandling)) |
|
| 490 | + if (!isset(self::$unicodeHandling)) |
|
| 491 | 491 | { |
| 492 | 492 | self::$unicodeHandling = new UnicodeHandling(); |
| 493 | 493 | } |
@@ -520,7 +520,7 @@ discard block |
||
| 520 | 520 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 521 | 521 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 522 | 522 | */ |
| 523 | - public static function saveAsJSON($data, string $file, bool $pretty=false) : void |
|
| 523 | + public static function saveAsJSON($data, string $file, bool $pretty = false) : void |
|
| 524 | 524 | { |
| 525 | 525 | JSONFile::factory(self::getFileInfo($file)) |
| 526 | 526 | ->putData($data, $pretty); |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 539 | 539 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 540 | 540 | */ |
| 541 | - public static function saveFile(string $filePath, string $content='') : void |
|
| 541 | + public static function saveFile(string $filePath, string $content = '') : void |
|
| 542 | 542 | { |
| 543 | 543 | self::getFileInfo($filePath)->putContents($content); |
| 544 | 544 | } |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | */ |
| 582 | 582 | public static function checkPHPFileSyntax(string $path) |
| 583 | 583 | { |
| 584 | - if(!self::canMakePHPCalls()) { |
|
| 584 | + if (!self::canMakePHPCalls()) { |
|
| 585 | 585 | return true; |
| 586 | 586 | } |
| 587 | 587 | |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | // when the validation is successful, the first entry |
| 593 | 593 | // in the array contains the success message. When it |
| 594 | 594 | // is invalid, the first entry is always empty. |
| 595 | - if(!empty($output[0])) { |
|
| 595 | + if (!empty($output[0])) { |
|
| 596 | 596 | return true; |
| 597 | 597 | } |
| 598 | 598 | |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | public static function getModifiedDate(string $path) : ?DateTime |
| 614 | 614 | { |
| 615 | 615 | $time = filemtime($path); |
| 616 | - if($time === false) { |
|
| 616 | + if ($time === false) { |
|
| 617 | 617 | return null; |
| 618 | 618 | } |
| 619 | 619 | |
@@ -674,7 +674,7 @@ discard block |
||
| 674 | 674 | * @param int $depth The folder depth to reduce the path to |
| 675 | 675 | * @return string |
| 676 | 676 | */ |
| 677 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
| 677 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
| 678 | 678 | { |
| 679 | 679 | return PathRelativizer::relativizeByDepth($path, $depth); |
| 680 | 680 | } |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 714 | 714 | * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
| 715 | 715 | */ |
| 716 | - public static function requireFileExists($path, ?int $errorCode=null) : string |
|
| 716 | + public static function requireFileExists($path, ?int $errorCode = null) : string |
|
| 717 | 717 | { |
| 718 | 718 | return self::getPathInfo($path) |
| 719 | 719 | ->requireIsFile() |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | * @return string |
| 728 | 728 | * @throws FileHelper_Exception |
| 729 | 729 | */ |
| 730 | - public static function requireFileReadable(string $path, ?int $errorCode=null) : string |
|
| 730 | + public static function requireFileReadable(string $path, ?int $errorCode = null) : string |
|
| 731 | 731 | { |
| 732 | 732 | return self::getPathInfo($path) |
| 733 | 733 | ->requireIsFile() |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 817 | 817 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
| 818 | 818 | */ |
| 819 | - public static function readLines(string $filePath, int $amount=0) : array |
|
| 819 | + public static function readLines(string $filePath, int $amount = 0) : array |
|
| 820 | 820 | { |
| 821 | 821 | return self::getFileInfo($filePath) |
| 822 | 822 | ->getLineReader() |
@@ -866,7 +866,7 @@ discard block |
||
| 866 | 866 | * |
| 867 | 867 | * @throws FileHelper_Exception |
| 868 | 868 | */ |
| 869 | - public static function createPathsReducer(array $paths=array()) : PathsReducer |
|
| 869 | + public static function createPathsReducer(array $paths = array()) : PathsReducer |
|
| 870 | 870 | { |
| 871 | 871 | return new PathsReducer($paths); |
| 872 | 872 | } |