@@ -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|PathInfoInterface|SplFileInfo $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|PathInfoInterface|SplFileInfo $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($file) : array |
| 89 | 89 | { |
| 90 | 90 | return SerializedFile::factory($file)->parse(); |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | return FolderTree::delete($rootFolder); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Create a folder, if it does not exist yet. |
|
| 108 | - * |
|
| 109 | - * @param string|PathInfoInterface $path |
|
| 110 | - * @throws FileHelper_Exception |
|
| 111 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 112 | - */ |
|
| 106 | + /** |
|
| 107 | + * Create a folder, if it does not exist yet. |
|
| 108 | + * |
|
| 109 | + * @param string|PathInfoInterface $path |
|
| 110 | + * @throws FileHelper_Exception |
|
| 111 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 112 | + */ |
|
| 113 | 113 | public static function createFolder($path) : FolderInfo |
| 114 | 114 | { |
| 115 | 115 | 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|PathInfoInterface|SplFileInfo $sourcePath |
|
| 148 | - * @param string|PathInfoInterface|SplFileInfo $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|PathInfoInterface|SplFileInfo $sourcePath |
|
| 148 | + * @param string|PathInfoInterface|SplFileInfo $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($sourcePath, $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|PathInfoInterface|SplFileInfo $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|PathInfoInterface|SplFileInfo $filePath |
|
| 167 | + * @throws FileHelper_Exception |
|
| 168 | + * |
|
| 169 | + * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
| 170 | + */ |
|
| 171 | 171 | public static function deleteFile($filePath) : void |
| 172 | 172 | { |
| 173 | 173 | self::getFileInfo($filePath)->delete(); |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | public static function isPHPFile($filePath) : bool |
| 290 | 290 | { |
| 291 | - return self::getExtension($filePath) === 'php'; |
|
| 291 | + return self::getExtension($filePath) === 'php'; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -354,16 +354,16 @@ discard block |
||
| 354 | 354 | ->parse(); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * Corrects common formatting mistakes when users enter |
|
| 359 | - * file names, like too many spaces, dots and the like. |
|
| 360 | - * |
|
| 361 | - * NOTE: if the file name contains a path, the path is |
|
| 362 | - * stripped, leaving only the file name. |
|
| 363 | - * |
|
| 364 | - * @param string $name |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 357 | + /** |
|
| 358 | + * Corrects common formatting mistakes when users enter |
|
| 359 | + * file names, like too many spaces, dots and the like. |
|
| 360 | + * |
|
| 361 | + * NOTE: if the file name contains a path, the path is |
|
| 362 | + * stripped, leaving only the file name. |
|
| 363 | + * |
|
| 364 | + * @param string $name |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | 367 | public static function fixFileName(string $name) : string |
| 368 | 368 | { |
| 369 | 369 | return NameFixer::fixName($name); |
@@ -423,23 +423,23 @@ discard block |
||
| 423 | 423 | return self::findFiles($targetFolder, array('php'), $options); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - /** |
|
| 427 | - * Finds files according to the specified options. |
|
| 428 | - * |
|
| 429 | - * NOTE: This method only exists for backwards compatibility. |
|
| 430 | - * Use the {@see FileHelper::createFileFinder()} method instead, |
|
| 431 | - * which offers an object-oriented interface that is much easier |
|
| 432 | - * to use. |
|
| 433 | - * |
|
| 434 | - * @param string|PathInfoInterface|SplFileInfo $targetFolder |
|
| 435 | - * @param string[] $extensions |
|
| 436 | - * @param array<string,mixed> $options |
|
| 437 | - * @throws FileHelper_Exception |
|
| 438 | - * @return string[] |
|
| 439 | - * |
|
| 440 | - * @see FileHelper::createFileFinder() |
|
| 441 | - * @deprecated Use the file finder instead. |
|
| 442 | - */ |
|
| 426 | + /** |
|
| 427 | + * Finds files according to the specified options. |
|
| 428 | + * |
|
| 429 | + * NOTE: This method only exists for backwards compatibility. |
|
| 430 | + * Use the {@see FileHelper::createFileFinder()} method instead, |
|
| 431 | + * which offers an object-oriented interface that is much easier |
|
| 432 | + * to use. |
|
| 433 | + * |
|
| 434 | + * @param string|PathInfoInterface|SplFileInfo $targetFolder |
|
| 435 | + * @param string[] $extensions |
|
| 436 | + * @param array<string,mixed> $options |
|
| 437 | + * @throws FileHelper_Exception |
|
| 438 | + * @return string[] |
|
| 439 | + * |
|
| 440 | + * @see FileHelper::createFileFinder() |
|
| 441 | + * @deprecated Use the file finder instead. |
|
| 442 | + */ |
|
| 443 | 443 | public static function findFiles($targetFolder, array $extensions=array(), array $options=array()) : array |
| 444 | 444 | { |
| 445 | 445 | $finder = self::createFileFinder($targetFolder); |
@@ -498,13 +498,13 @@ discard block |
||
| 498 | 498 | return self::$unicodeHandling; |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - /** |
|
| 502 | - * Normalizes the slash style in a file or folder path, |
|
| 503 | - * by replacing any anti-slashes with forward slashes. |
|
| 504 | - * |
|
| 505 | - * @param string $path |
|
| 506 | - * @return string |
|
| 507 | - */ |
|
| 501 | + /** |
|
| 502 | + * Normalizes the slash style in a file or folder path, |
|
| 503 | + * by replacing any anti-slashes with forward slashes. |
|
| 504 | + * |
|
| 505 | + * @param string $path |
|
| 506 | + * @return string |
|
| 507 | + */ |
|
| 508 | 508 | public static function normalizePath(string $path) : string |
| 509 | 509 | { |
| 510 | 510 | return str_replace(array('\\', '//'), array('/', '/'), $path); |
@@ -629,70 +629,70 @@ discard block |
||
| 629 | 629 | ->getPaths(); |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - /** |
|
| 633 | - * Retrieves the maximum allowed upload file size, in bytes. |
|
| 634 | - * Takes into account the PHP ini settings <code>post_max_size</code> |
|
| 635 | - * and <code>upload_max_filesize</code>. Since these cannot |
|
| 636 | - * be modified at runtime, they are the hard limits for uploads. |
|
| 637 | - * |
|
| 638 | - * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
| 639 | - * |
|
| 640 | - * @return int Will return <code>-1</code> if no limit. |
|
| 641 | - */ |
|
| 632 | + /** |
|
| 633 | + * Retrieves the maximum allowed upload file size, in bytes. |
|
| 634 | + * Takes into account the PHP ini settings <code>post_max_size</code> |
|
| 635 | + * and <code>upload_max_filesize</code>. Since these cannot |
|
| 636 | + * be modified at runtime, they are the hard limits for uploads. |
|
| 637 | + * |
|
| 638 | + * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
| 639 | + * |
|
| 640 | + * @return int Will return <code>-1</code> if no limit. |
|
| 641 | + */ |
|
| 642 | 642 | public static function getMaxUploadFilesize() : int |
| 643 | 643 | { |
| 644 | 644 | return UploadFileSizeInfo::getFileSize(); |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - /** |
|
| 648 | - * Makes a path relative using a folder depth: will reduce the |
|
| 649 | - * length of the path so that only the amount of folders defined |
|
| 650 | - * in the <code>$depth</code> attribute are shown below the actual |
|
| 651 | - * folder or file in the path. |
|
| 652 | - * |
|
| 653 | - * @param string $path The absolute or relative path |
|
| 654 | - * @param int $depth The folder depth to reduce the path to |
|
| 655 | - * @return string |
|
| 656 | - */ |
|
| 647 | + /** |
|
| 648 | + * Makes a path relative using a folder depth: will reduce the |
|
| 649 | + * length of the path so that only the amount of folders defined |
|
| 650 | + * in the <code>$depth</code> attribute are shown below the actual |
|
| 651 | + * folder or file in the path. |
|
| 652 | + * |
|
| 653 | + * @param string $path The absolute or relative path |
|
| 654 | + * @param int $depth The folder depth to reduce the path to |
|
| 655 | + * @return string |
|
| 656 | + */ |
|
| 657 | 657 | public static function relativizePathByDepth(string $path, int $depth=2) : string |
| 658 | 658 | { |
| 659 | 659 | return PathRelativizer::relativizeByDepth($path, $depth); |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - /** |
|
| 663 | - * Makes the specified path relative to another path, |
|
| 664 | - * by removing one from the other if found. Also |
|
| 665 | - * normalizes the path to use forward slashes. |
|
| 666 | - * |
|
| 667 | - * Example: |
|
| 668 | - * |
|
| 669 | - * <pre> |
|
| 670 | - * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
| 671 | - * </pre> |
|
| 672 | - * |
|
| 673 | - * Result: <code>to/file.txt</code> |
|
| 674 | - * |
|
| 675 | - * @param string $path |
|
| 676 | - * @param string $relativeTo |
|
| 677 | - * @return string |
|
| 678 | - */ |
|
| 662 | + /** |
|
| 663 | + * Makes the specified path relative to another path, |
|
| 664 | + * by removing one from the other if found. Also |
|
| 665 | + * normalizes the path to use forward slashes. |
|
| 666 | + * |
|
| 667 | + * Example: |
|
| 668 | + * |
|
| 669 | + * <pre> |
|
| 670 | + * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
| 671 | + * </pre> |
|
| 672 | + * |
|
| 673 | + * Result: <code>to/file.txt</code> |
|
| 674 | + * |
|
| 675 | + * @param string $path |
|
| 676 | + * @param string $relativeTo |
|
| 677 | + * @return string |
|
| 678 | + */ |
|
| 679 | 679 | public static function relativizePath(string $path, string $relativeTo) : string |
| 680 | 680 | { |
| 681 | 681 | return PathRelativizer::relativize($path, $relativeTo); |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | - /** |
|
| 685 | - * Checks that the target file exists, and throws an exception |
|
| 686 | - * if it does not. |
|
| 687 | - * |
|
| 688 | - * @param string|SplFileInfo $path |
|
| 689 | - * @param int|NULL $errorCode Optional custom error code |
|
| 690 | - * @throws FileHelper_Exception |
|
| 691 | - * @return string The real path to the file |
|
| 692 | - * |
|
| 693 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 694 | - * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
|
| 695 | - */ |
|
| 684 | + /** |
|
| 685 | + * Checks that the target file exists, and throws an exception |
|
| 686 | + * if it does not. |
|
| 687 | + * |
|
| 688 | + * @param string|SplFileInfo $path |
|
| 689 | + * @param int|NULL $errorCode Optional custom error code |
|
| 690 | + * @throws FileHelper_Exception |
|
| 691 | + * @return string The real path to the file |
|
| 692 | + * |
|
| 693 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 694 | + * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
|
| 695 | + */ |
|
| 696 | 696 | public static function requireFileExists($path, ?int $errorCode=null) : string |
| 697 | 697 | { |
| 698 | 698 | return self::getPathInfo($path) |
@@ -715,18 +715,18 @@ discard block |
||
| 715 | 715 | ->getPath(); |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | - /** |
|
| 719 | - * Reads a specific line number from the target file and returns its |
|
| 720 | - * contents, if the file has such a line. Does so with little memory |
|
| 721 | - * usage, as the file is not read entirely into memory. |
|
| 722 | - * |
|
| 723 | - * @param string|PathInfoInterface|SplFileInfo $path |
|
| 724 | - * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
| 725 | - * @return string|NULL Will return null if the requested line does not exist. |
|
| 726 | - * @throws FileHelper_Exception |
|
| 727 | - * |
|
| 728 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 729 | - */ |
|
| 718 | + /** |
|
| 719 | + * Reads a specific line number from the target file and returns its |
|
| 720 | + * contents, if the file has such a line. Does so with little memory |
|
| 721 | + * usage, as the file is not read entirely into memory. |
|
| 722 | + * |
|
| 723 | + * @param string|PathInfoInterface|SplFileInfo $path |
|
| 724 | + * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
| 725 | + * @return string|NULL Will return null if the requested line does not exist. |
|
| 726 | + * @throws FileHelper_Exception |
|
| 727 | + * |
|
| 728 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 729 | + */ |
|
| 730 | 730 | public static function getLineFromFile($path, int $lineNumber) : ?string |
| 731 | 731 | { |
| 732 | 732 | return self::getFileInfo($path)->getLine($lineNumber); |
@@ -792,33 +792,33 @@ discard block |
||
| 792 | 792 | ->getLines($amount); |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - /** |
|
| 796 | - * Reads all content from a file. |
|
| 797 | - * |
|
| 798 | - * @param string|PathInfoInterface|SplFileInfo $filePath |
|
| 799 | - * @throws FileHelper_Exception |
|
| 800 | - * @return string |
|
| 801 | - * |
|
| 802 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 803 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 804 | - */ |
|
| 795 | + /** |
|
| 796 | + * Reads all content from a file. |
|
| 797 | + * |
|
| 798 | + * @param string|PathInfoInterface|SplFileInfo $filePath |
|
| 799 | + * @throws FileHelper_Exception |
|
| 800 | + * @return string |
|
| 801 | + * |
|
| 802 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 803 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 804 | + */ |
|
| 805 | 805 | public static function readContents($filePath) : string |
| 806 | 806 | { |
| 807 | 807 | return self::getFileInfo($filePath)->getContents(); |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - /** |
|
| 811 | - * Ensures that the target path exists on disk, and is a folder. |
|
| 812 | - * |
|
| 813 | - * @param string|PathInfoInterface|SplFileInfo $path |
|
| 814 | - * @return string The real path, with normalized slashes. |
|
| 815 | - * @throws FileHelper_Exception |
|
| 816 | - * |
|
| 817 | - * @see FileHelper::normalizePath() |
|
| 818 | - * |
|
| 819 | - * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST |
|
| 820 | - * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 821 | - */ |
|
| 810 | + /** |
|
| 811 | + * Ensures that the target path exists on disk, and is a folder. |
|
| 812 | + * |
|
| 813 | + * @param string|PathInfoInterface|SplFileInfo $path |
|
| 814 | + * @return string The real path, with normalized slashes. |
|
| 815 | + * @throws FileHelper_Exception |
|
| 816 | + * |
|
| 817 | + * @see FileHelper::normalizePath() |
|
| 818 | + * |
|
| 819 | + * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST |
|
| 820 | + * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 821 | + */ |
|
| 822 | 822 | public static function requireFolderExists($path) : string |
| 823 | 823 | { |
| 824 | 824 | return self::getFolderInfo($path) |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | public static function detectMimeType($fileName) : ?string |
| 209 | 209 | { |
| 210 | 210 | $ext = self::getExtension($fileName); |
| 211 | - if(empty($ext)) { |
|
| 211 | + if (empty($ext)) { |
|
| 212 | 212 | return null; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 253 | 253 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
| 254 | 254 | */ |
| 255 | - public static function sendFile($filePath, ?string $fileName = null, bool $asAttachment=true) : void |
|
| 255 | + public static function sendFile($filePath, ?string $fileName = null, bool $asAttachment = true) : void |
|
| 256 | 256 | { |
| 257 | 257 | self::getFileInfo($filePath)->getDownloader()->send($fileName, $asAttachment); |
| 258 | 258 | } |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * @throws FileHelper_Exception |
| 270 | 270 | * @see FileHelper::ERROR_CANNOT_OPEN_URL |
| 271 | 271 | */ |
| 272 | - public static function downloadFile(string $url, int $timeout=0, bool $SSLEnabled=false) : string |
|
| 272 | + public static function downloadFile(string $url, int $timeout = 0, bool $SSLEnabled = false) : string |
|
| 273 | 273 | { |
| 274 | 274 | return FileDownloader::factory($url) |
| 275 | 275 | ->setTimeout($timeout) |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | { |
| 325 | 325 | $info = self::getPathInfo($pathOrDirIterator); |
| 326 | 326 | |
| 327 | - if($extension === true || $info instanceof FolderInfo) |
|
| 327 | + if ($extension === true || $info instanceof FolderInfo) |
|
| 328 | 328 | { |
| 329 | 329 | return $info->getName(); |
| 330 | 330 | } |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
| 347 | 347 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
| 348 | 348 | */ |
| 349 | - public static function parseJSONFile($file, string $targetEncoding='', $sourceEncoding=null) : array |
|
| 349 | + public static function parseJSONFile($file, string $targetEncoding = '', $sourceEncoding = null) : array |
|
| 350 | 350 | { |
| 351 | 351 | return JSONFile::factory($file) |
| 352 | 352 | ->setTargetEncoding($targetEncoding) |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @throws FileHelper_Exception |
| 400 | 400 | * @see FileHelper::createFileFinder() |
| 401 | 401 | */ |
| 402 | - public static function findHTMLFiles($targetFolder, array $options=array()) : array |
|
| 402 | + public static function findHTMLFiles($targetFolder, array $options = array()) : array |
|
| 403 | 403 | { |
| 404 | 404 | return self::findFiles($targetFolder, array('html'), $options); |
| 405 | 405 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * @throws FileHelper_Exception |
| 419 | 419 | * @see FileHelper::createFileFinder() |
| 420 | 420 | */ |
| 421 | - public static function findPHPFiles($targetFolder, array $options=array()) : array |
|
| 421 | + public static function findPHPFiles($targetFolder, array $options = array()) : array |
|
| 422 | 422 | { |
| 423 | 423 | return self::findFiles($targetFolder, array('php'), $options); |
| 424 | 424 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | * @see FileHelper::createFileFinder() |
| 441 | 441 | * @deprecated Use the file finder instead. |
| 442 | 442 | */ |
| 443 | - public static function findFiles($targetFolder, array $extensions=array(), array $options=array()) : array |
|
| 443 | + public static function findFiles($targetFolder, array $extensions = array(), array $options = array()) : array |
|
| 444 | 444 | { |
| 445 | 445 | $finder = self::createFileFinder($targetFolder); |
| 446 | 446 | |
@@ -450,16 +450,16 @@ discard block |
||
| 450 | 450 | |
| 451 | 451 | $finder->setPathmodeStrip(); |
| 452 | 452 | |
| 453 | - if(isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 453 | + if (isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 454 | 454 | { |
| 455 | 455 | $finder->setPathmodeRelative(); |
| 456 | 456 | } |
| 457 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 457 | + else if (isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 458 | 458 | { |
| 459 | 459 | $finder->setPathmodeAbsolute(); |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - if(isset($options['strip-extension'])) |
|
| 462 | + if (isset($options['strip-extension'])) |
|
| 463 | 463 | { |
| 464 | 464 | $finder->stripExtensions(); |
| 465 | 465 | } |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | * @return string |
| 479 | 479 | * @throws FileHelper_Exception |
| 480 | 480 | */ |
| 481 | - public static function removeExtension($filename, bool $keepPath=false) : string |
|
| 481 | + public static function removeExtension($filename, bool $keepPath = false) : string |
|
| 482 | 482 | { |
| 483 | 483 | return self::getFileInfo($filename)->removeExtension($keepPath); |
| 484 | 484 | } |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | public static function createUnicodeHandling() : UnicodeHandling |
| 492 | 492 | { |
| 493 | - if(!isset(self::$unicodeHandling)) |
|
| 493 | + if (!isset(self::$unicodeHandling)) |
|
| 494 | 494 | { |
| 495 | 495 | self::$unicodeHandling = new UnicodeHandling(); |
| 496 | 496 | } |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 525 | 525 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 526 | 526 | */ |
| 527 | - public static function saveAsJSON($data, $file, bool $pretty=false) : JSONFile |
|
| 527 | + public static function saveAsJSON($data, $file, bool $pretty = false) : JSONFile |
|
| 528 | 528 | { |
| 529 | 529 | return JSONFile::factory($file)->putData($data, $pretty); |
| 530 | 530 | } |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 543 | 543 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 544 | 544 | */ |
| 545 | - public static function saveFile($filePath, string $content='') : FileInfo |
|
| 545 | + public static function saveFile($filePath, string $content = '') : FileInfo |
|
| 546 | 546 | { |
| 547 | 547 | return self::getFileInfo($filePath)->putContents($content); |
| 548 | 548 | } |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * @param int $depth The folder depth to reduce the path to |
| 655 | 655 | * @return string |
| 656 | 656 | */ |
| 657 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
| 657 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
| 658 | 658 | { |
| 659 | 659 | return PathRelativizer::relativizeByDepth($path, $depth); |
| 660 | 660 | } |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 694 | 694 | * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
| 695 | 695 | */ |
| 696 | - public static function requireFileExists($path, ?int $errorCode=null) : string |
|
| 696 | + public static function requireFileExists($path, ?int $errorCode = null) : string |
|
| 697 | 697 | { |
| 698 | 698 | return self::getPathInfo($path) |
| 699 | 699 | ->requireIsFile() |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * @return string |
| 708 | 708 | * @throws FileHelper_Exception |
| 709 | 709 | */ |
| 710 | - public static function requireFileReadable($path, ?int $errorCode=null) : string |
|
| 710 | + public static function requireFileReadable($path, ?int $errorCode = null) : string |
|
| 711 | 711 | { |
| 712 | 712 | return self::getPathInfo($path) |
| 713 | 713 | ->requireIsFile() |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 786 | 786 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
| 787 | 787 | */ |
| 788 | - public static function readLines($filePath, int $amount=0) : array |
|
| 788 | + public static function readLines($filePath, int $amount = 0) : array |
|
| 789 | 789 | { |
| 790 | 790 | return self::getFileInfo($filePath) |
| 791 | 791 | ->getLineReader() |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * |
| 836 | 836 | * @throws FileHelper_Exception |
| 837 | 837 | */ |
| 838 | - public static function createPathsReducer(array $paths=array()) : PathsReducer |
|
| 838 | + public static function createPathsReducer(array $paths = array()) : PathsReducer |
|
| 839 | 839 | { |
| 840 | 840 | return new PathsReducer($paths); |
| 841 | 841 | } |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | * @param bool $enabled |
| 75 | 75 | * @return $this |
| 76 | 76 | */ |
| 77 | - public function prop(string $name, bool $enabled=true) : self |
|
| 77 | + public function prop(string $name, bool $enabled = true) : self |
|
| 78 | 78 | { |
| 79 | 79 | $this->getAttributes()->prop($name, $enabled); |
| 80 | 80 | return $this; |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | trait Traits_Classable |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * @var string[] |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var string[] |
|
| 30 | + */ |
|
| 31 | 31 | protected array $classes = array(); |
| 32 | 32 | |
| 33 | 33 | public function hasClasses() : bool |
@@ -82,30 +82,30 @@ discard block |
||
| 82 | 82 | return $this; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Retrieves a list of all classes, if any. |
|
| 87 | - * |
|
| 88 | - * @return string[] |
|
| 89 | - */ |
|
| 85 | + /** |
|
| 86 | + * Retrieves a list of all classes, if any. |
|
| 87 | + * |
|
| 88 | + * @return string[] |
|
| 89 | + */ |
|
| 90 | 90 | public function getClasses() : array |
| 91 | 91 | { |
| 92 | 92 | return $this->classes; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Renders the class names list as space-separated string for use in an HTML tag. |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 95 | + /** |
|
| 96 | + * Renders the class names list as space-separated string for use in an HTML tag. |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | 100 | public function classesToString() : string |
| 101 | 101 | { |
| 102 | 102 | return implode(' ', $this->classes); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Renders the "class" attribute string for inserting into an HTML tag. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 105 | + /** |
|
| 106 | + * Renders the "class" attribute string for inserting into an HTML tag. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | 109 | public function classesToAttribute() : string |
| 110 | 110 | { |
| 111 | 111 | if(!empty($this->classes)) |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function addClass($name) |
| 43 | 43 | { |
| 44 | - if(!in_array($name, $this->classes, true)) { |
|
| 44 | + if (!in_array($name, $this->classes, true)) { |
|
| 45 | 45 | $this->classes[] = $name; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function addClasses(array $names) : self |
| 56 | 56 | { |
| 57 | - foreach($names as $name) { |
|
| 57 | + foreach ($names as $name) { |
|
| 58 | 58 | $this->addClass($name); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $idx = array_search($name, $this->classes, true); |
| 76 | 76 | |
| 77 | - if($idx !== false) { |
|
| 77 | + if ($idx !== false) { |
|
| 78 | 78 | unset($this->classes[$idx]); |
| 79 | 79 | sort($this->classes); |
| 80 | 80 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function classesToAttribute() : string |
| 110 | 110 | { |
| 111 | - if(!empty($this->classes)) |
|
| 111 | + if (!empty($this->classes)) |
|
| 112 | 112 | { |
| 113 | 113 | return sprintf( |
| 114 | 114 | ' class="%s" ', |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | trait Traits_Optionable |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * @var array<string,mixed>|NULL |
|
| 31 | - */ |
|
| 29 | + /** |
|
| 30 | + * @var array<string,mixed>|NULL |
|
| 31 | + */ |
|
| 32 | 32 | protected ?array $options = null; |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | return $this; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Sets a collection of options at once, from an |
|
| 54 | - * associative array. |
|
| 55 | - * |
|
| 56 | - * @param array<string,mixed> $options |
|
| 57 | - * @return $this |
|
| 58 | - */ |
|
| 52 | + /** |
|
| 53 | + * Sets a collection of options at once, from an |
|
| 54 | + * associative array. |
|
| 55 | + * |
|
| 56 | + * @param array<string,mixed> $options |
|
| 57 | + * @return $this |
|
| 58 | + */ |
|
| 59 | 59 | public function setOptions(array $options) : self |
| 60 | 60 | { |
| 61 | 61 | foreach($options as $name => $value) { |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | return $this; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Retrieves an option's value. |
|
| 70 | - * |
|
| 71 | - * NOTE: Use the specialized type getters to ensure an option |
|
| 72 | - * contains the expected type (for ex. getArrayOption()). |
|
| 73 | - * |
|
| 74 | - * @param string $name |
|
| 75 | - * @param mixed $default The default value to return if the option does not exist. |
|
| 76 | - * @return mixed |
|
| 77 | - */ |
|
| 68 | + /** |
|
| 69 | + * Retrieves an option's value. |
|
| 70 | + * |
|
| 71 | + * NOTE: Use the specialized type getters to ensure an option |
|
| 72 | + * contains the expected type (for ex. getArrayOption()). |
|
| 73 | + * |
|
| 74 | + * @param string $name |
|
| 75 | + * @param mixed $default The default value to return if the option does not exist. |
|
| 76 | + * @return mixed |
|
| 77 | + */ |
|
| 78 | 78 | public function getOption(string $name, $default=null) |
| 79 | 79 | { |
| 80 | 80 | if(!isset($this->options)) |
@@ -85,16 +85,16 @@ discard block |
||
| 85 | 85 | return $this->options[$name] ?? $default; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Enforces that the option value is a string. Numbers are converted |
|
| 90 | - * to string, strings are passed through, and all other types will |
|
| 91 | - * return the default value. The default value is also returned if |
|
| 92 | - * the string is empty. |
|
| 93 | - * |
|
| 94 | - * @param string $name |
|
| 95 | - * @param string $default Used if the option does not exist, is invalid, or empty. |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 88 | + /** |
|
| 89 | + * Enforces that the option value is a string. Numbers are converted |
|
| 90 | + * to string, strings are passed through, and all other types will |
|
| 91 | + * return the default value. The default value is also returned if |
|
| 92 | + * the string is empty. |
|
| 93 | + * |
|
| 94 | + * @param string $name |
|
| 95 | + * @param string $default Used if the option does not exist, is invalid, or empty. |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | 98 | public function getStringOption(string $name, string $default='') : string |
| 99 | 99 | { |
| 100 | 100 | $value = $this->getOption($name, false); |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | return $default; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Treats the option value as an integer value: will return |
|
| 131 | - * valid integer values (also from integer strings), or the |
|
| 132 | - * default value otherwise. |
|
| 133 | - * |
|
| 134 | - * @param string $name |
|
| 135 | - * @param int $default |
|
| 136 | - * @return int |
|
| 137 | - */ |
|
| 129 | + /** |
|
| 130 | + * Treats the option value as an integer value: will return |
|
| 131 | + * valid integer values (also from integer strings), or the |
|
| 132 | + * default value otherwise. |
|
| 133 | + * |
|
| 134 | + * @param string $name |
|
| 135 | + * @param int $default |
|
| 136 | + * @return int |
|
| 137 | + */ |
|
| 138 | 138 | public function getIntOption(string $name, int $default=0) : int |
| 139 | 139 | { |
| 140 | 140 | $value = $this->getOption($name); |
@@ -145,14 +145,14 @@ discard block |
||
| 145 | 145 | return $default; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Treats an option as an array, and returns its value |
|
| 150 | - * only if it contains an array - otherwise, an empty |
|
| 151 | - * array is returned. |
|
| 152 | - * |
|
| 153 | - * @param string $name |
|
| 154 | - * @return array<int|string,mixed> |
|
| 155 | - */ |
|
| 148 | + /** |
|
| 149 | + * Treats an option as an array, and returns its value |
|
| 150 | + * only if it contains an array - otherwise, an empty |
|
| 151 | + * array is returned. |
|
| 152 | + * |
|
| 153 | + * @param string $name |
|
| 154 | + * @return array<int|string,mixed> |
|
| 155 | + */ |
|
| 156 | 156 | public function getArrayOption(string $name) : array |
| 157 | 157 | { |
| 158 | 158 | $val = $this->getOption($name); |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | return array(); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Checks whether the specified option exists - even |
|
| 168 | - * if it has a NULL value. |
|
| 169 | - * |
|
| 170 | - * @param string $name |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 166 | + /** |
|
| 167 | + * Checks whether the specified option exists - even |
|
| 168 | + * if it has a NULL value. |
|
| 169 | + * |
|
| 170 | + * @param string $name |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | 173 | public function hasOption(string $name) : bool |
| 174 | 174 | { |
| 175 | 175 | if(!isset($this->options)) { |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | return array_key_exists($name, $this->options); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Returns all options in one associative array. |
|
| 184 | - * |
|
| 185 | - * @return array<string,mixed> |
|
| 186 | - */ |
|
| 182 | + /** |
|
| 183 | + * Returns all options in one associative array. |
|
| 184 | + * |
|
| 185 | + * @return array<string,mixed> |
|
| 186 | + */ |
|
| 187 | 187 | public function getOptions() : array |
| 188 | 188 | { |
| 189 | 189 | if(!isset($this->options)) { |
@@ -193,13 +193,13 @@ discard block |
||
| 193 | 193 | return $this->options; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Checks whether the option's value is the one specified. |
|
| 198 | - * |
|
| 199 | - * @param string $name |
|
| 200 | - * @param mixed $value |
|
| 201 | - * @return bool |
|
| 202 | - */ |
|
| 196 | + /** |
|
| 197 | + * Checks whether the option's value is the one specified. |
|
| 198 | + * |
|
| 199 | + * @param string $name |
|
| 200 | + * @param mixed $value |
|
| 201 | + * @return bool |
|
| 202 | + */ |
|
| 203 | 203 | public function isOption(string $name, $value) : bool |
| 204 | 204 | { |
| 205 | 205 | return $this->getOption($name) === $value; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function setOption(string $name, $value) : self |
| 43 | 43 | { |
| 44 | - if(!isset($this->options)) { |
|
| 44 | + if (!isset($this->options)) { |
|
| 45 | 45 | $this->options = $this->getDefaultOptions(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function setOptions(array $options) : self |
| 60 | 60 | { |
| 61 | - foreach($options as $name => $value) { |
|
| 61 | + foreach ($options as $name => $value) { |
|
| 62 | 62 | $this->setOption($name, $value); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | * @param mixed $default The default value to return if the option does not exist. |
| 76 | 76 | * @return mixed |
| 77 | 77 | */ |
| 78 | - public function getOption(string $name, $default=null) |
|
| 78 | + public function getOption(string $name, $default = null) |
|
| 79 | 79 | { |
| 80 | - if(!isset($this->options)) |
|
| 80 | + if (!isset($this->options)) |
|
| 81 | 81 | { |
| 82 | 82 | $this->options = $this->getDefaultOptions(); |
| 83 | 83 | } |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | * @param string $default Used if the option does not exist, is invalid, or empty. |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | - public function getStringOption(string $name, string $default='') : string |
|
| 98 | + public function getStringOption(string $name, string $default = '') : string |
|
| 99 | 99 | { |
| 100 | 100 | $value = $this->getOption($name, false); |
| 101 | 101 | |
| 102 | - if((is_string($value) || is_numeric($value)) && !empty($value)) { |
|
| 102 | + if ((is_string($value) || is_numeric($value)) && !empty($value)) { |
|
| 103 | 103 | return (string)$value; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * @param bool $default |
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | - public function getBoolOption(string $name, bool $default=false) : bool |
|
| 119 | + public function getBoolOption(string $name, bool $default = false) : bool |
|
| 120 | 120 | { |
| 121 | - if($this->getOption($name) === true) |
|
| 121 | + if ($this->getOption($name) === true) |
|
| 122 | 122 | { |
| 123 | 123 | return true; |
| 124 | 124 | } |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | * @param int $default |
| 136 | 136 | * @return int |
| 137 | 137 | */ |
| 138 | - public function getIntOption(string $name, int $default=0) : int |
|
| 138 | + public function getIntOption(string $name, int $default = 0) : int |
|
| 139 | 139 | { |
| 140 | 140 | $value = $this->getOption($name); |
| 141 | - if(ConvertHelper::isInteger($value)) { |
|
| 141 | + if (ConvertHelper::isInteger($value)) { |
|
| 142 | 142 | return (int)$value; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | public function getArrayOption(string $name) : array |
| 157 | 157 | { |
| 158 | 158 | $val = $this->getOption($name); |
| 159 | - if(is_array($val)) { |
|
| 159 | + if (is_array($val)) { |
|
| 160 | 160 | return $val; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function hasOption(string $name) : bool |
| 174 | 174 | { |
| 175 | - if(!isset($this->options)) { |
|
| 175 | + if (!isset($this->options)) { |
|
| 176 | 176 | $this->options = $this->getDefaultOptions(); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | public function getOptions() : array |
| 188 | 188 | { |
| 189 | - if(!isset($this->options)) { |
|
| 189 | + if (!isset($this->options)) { |
|
| 190 | 190 | $this->options = $this->getDefaultOptions(); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -56,12 +56,12 @@ |
||
| 56 | 56 | */ |
| 57 | 57 | public static function value2string($value) : string |
| 58 | 58 | { |
| 59 | - if($value === true) |
|
| 59 | + if ($value === true) |
|
| 60 | 60 | { |
| 61 | 61 | return 'true'; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if($value === false) |
|
| 64 | + if ($value === false) |
|
| 65 | 65 | { |
| 66 | 66 | return 'false'; |
| 67 | 67 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * @param bool $enabled |
| 54 | 54 | * @return $this |
| 55 | 55 | */ |
| 56 | - public function prop(string $name, bool $enabled=true) : self; |
|
| 56 | + public function prop(string $name, bool $enabled = true) : self; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * @param string $name |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param mixed $default The default value to return if the option does not exist. |
| 46 | 46 | * @return mixed |
| 47 | 47 | */ |
| 48 | - public function getOption(string $name, $default=null); |
|
| 48 | + public function getOption(string $name, $default = null); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * @param string $name |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function getArrayOption(string $name) : array; |
| 55 | 55 | |
| 56 | - public function getIntOption(string $name, int $default=0) : int; |
|
| 56 | + public function getIntOption(string $name, int $default = 0) : int; |
|
| 57 | 57 | |
| 58 | - public function getBoolOption(string $name, bool $default=false) : bool; |
|
| 58 | + public function getBoolOption(string $name, bool $default = false) : bool; |
|
| 59 | 59 | |
| 60 | - public function getStringOption(string $name, string $default='') : string; |
|
| 60 | + public function getStringOption(string $name, string $default = '') : string; |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * Sets a collection of options at once, from an |