@@ -23,44 +23,44 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class Request_URLComparer |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var Request |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var Request |
|
| 28 | + */ |
|
| 29 | 29 | protected Request $request; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | 34 | protected string $sourceURL; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | 39 | protected string $targetURL; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var string[] |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var string[] |
|
| 43 | + */ |
|
| 44 | 44 | protected array $limitParams = array(); |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var bool |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var bool |
|
| 48 | + */ |
|
| 49 | 49 | protected bool $isMatch = false; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | 54 | protected bool $ignoreFragment = true; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var URLInfo |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var URLInfo |
|
| 58 | + */ |
|
| 59 | 59 | protected URLInfo $sourceInfo; |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var URLInfo |
|
| 63 | - */ |
|
| 61 | + /** |
|
| 62 | + * @var URLInfo |
|
| 63 | + */ |
|
| 64 | 64 | protected URLInfo $targetInfo; |
| 65 | 65 | |
| 66 | 66 | public function __construct(Request $request, string $sourceURL, string $targetURL) |
@@ -23,101 +23,101 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class SVNHelper |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var integer |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var integer |
|
| 28 | + */ |
|
| 29 | 29 | public const ERROR_LOCAL_PATH_DOES_NOT_EXIST = 22401; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var integer |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var integer |
|
| 33 | + */ |
|
| 34 | 34 | public const ERROR_INVALID_REP_URL = 22402; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var integer |
|
| 38 | - */ |
|
| 36 | + /** |
|
| 37 | + * @var integer |
|
| 38 | + */ |
|
| 39 | 39 | public const ERROR_PATH_IS_OUTSIDE_REPOSITORY = 22403; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var integer |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var integer |
|
| 43 | + */ |
|
| 44 | 44 | public const ERROR_TARGET_FOLDER_IS_A_FILE = 22404; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var integer |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var integer |
|
| 48 | + */ |
|
| 49 | 49 | public const ERROR_CANNOT_ADD_INEXISTENT_FILE = 22405; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var integer |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var integer |
|
| 53 | + */ |
|
| 54 | 54 | public const ERROR_TARGET_PATH_NOT_FOUND = 22406; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var integer |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var integer |
|
| 58 | + */ |
|
| 59 | 59 | public const ERROR_INVALID_TARGET_TYPE = 22407; |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var integer |
|
| 63 | - */ |
|
| 61 | + /** |
|
| 62 | + * @var integer |
|
| 63 | + */ |
|
| 64 | 64 | public const ERROR_INVALID_LOG_CALLBACK = 22408; |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @var SVNHelper_Target_Folder |
|
| 68 | - */ |
|
| 66 | + /** |
|
| 67 | + * @var SVNHelper_Target_Folder |
|
| 68 | + */ |
|
| 69 | 69 | protected $target; |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @var string |
|
| 73 | - */ |
|
| 71 | + /** |
|
| 72 | + * @var string |
|
| 73 | + */ |
|
| 74 | 74 | protected $path; |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * @var string |
|
| 78 | - */ |
|
| 76 | + /** |
|
| 77 | + * @var string |
|
| 78 | + */ |
|
| 79 | 79 | protected $url; |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 81 | + /** |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | 84 | protected $user; |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * @var string |
|
| 88 | - */ |
|
| 86 | + /** |
|
| 87 | + * @var string |
|
| 88 | + */ |
|
| 89 | 89 | protected $pass; |
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * @var array |
|
| 93 | - */ |
|
| 91 | + /** |
|
| 92 | + * @var array |
|
| 93 | + */ |
|
| 94 | 94 | protected $options = array( |
| 95 | 95 | 'binaries-path' => '' |
| 96 | 96 | ); |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @var boolean |
|
| 100 | - */ |
|
| 98 | + /** |
|
| 99 | + * @var boolean |
|
| 100 | + */ |
|
| 101 | 101 | protected $isWindows = false; |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @var array |
|
| 105 | - */ |
|
| 103 | + /** |
|
| 104 | + * @var array |
|
| 105 | + */ |
|
| 106 | 106 | protected $normalize = array( |
| 107 | 107 | 'from' => '\\', |
| 108 | 108 | 'to' => '/' |
| 109 | 109 | ); |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * @var string |
|
| 113 | - */ |
|
| 111 | + /** |
|
| 112 | + * @var string |
|
| 113 | + */ |
|
| 114 | 114 | protected $sourcePath; |
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * @param string $repPath The path to the repository |
|
| 118 | - * @param string $repURL The SVN URL to the repository |
|
| 119 | - * @throws SVNHelper_Exception |
|
| 120 | - */ |
|
| 116 | + /** |
|
| 117 | + * @param string $repPath The path to the repository |
|
| 118 | + * @param string $repURL The SVN URL to the repository |
|
| 119 | + * @throws SVNHelper_Exception |
|
| 120 | + */ |
|
| 121 | 121 | public function __construct(string $repPath, string $repURL) |
| 122 | 122 | { |
| 123 | 123 | $this->isWindows = substr(PHP_OS, 0, 3) == 'WIN'; |
@@ -178,16 +178,16 @@ discard block |
||
| 178 | 178 | return $this->pass; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - /** |
|
| 182 | - * Normalizes slashes in the path according to the |
|
| 183 | - * operating system, i.e. forward slashes for NIX-systems |
|
| 184 | - * and backward slashes for Windows. |
|
| 185 | - * |
|
| 186 | - * @param string $path An absolute path to normalize |
|
| 187 | - * @param bool $relativize Whether to return a path relative to the repository |
|
| 188 | - * @throws SVNHelper_Exception |
|
| 189 | - * @return string |
|
| 190 | - */ |
|
| 181 | + /** |
|
| 182 | + * Normalizes slashes in the path according to the |
|
| 183 | + * operating system, i.e. forward slashes for NIX-systems |
|
| 184 | + * and backward slashes for Windows. |
|
| 185 | + * |
|
| 186 | + * @param string $path An absolute path to normalize |
|
| 187 | + * @param bool $relativize Whether to return a path relative to the repository |
|
| 188 | + * @throws SVNHelper_Exception |
|
| 189 | + * @return string |
|
| 190 | + */ |
|
| 191 | 191 | public function normalizePath($path, $relativize=false) |
| 192 | 192 | { |
| 193 | 193 | if(empty($path)) { |
@@ -222,32 +222,32 @@ discard block |
||
| 222 | 222 | ); |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Retrieves the path slash style according to the |
|
| 227 | - * current operating system. |
|
| 228 | - * |
|
| 229 | - * @return string |
|
| 230 | - */ |
|
| 225 | + /** |
|
| 226 | + * Retrieves the path slash style according to the |
|
| 227 | + * current operating system. |
|
| 228 | + * |
|
| 229 | + * @return string |
|
| 230 | + */ |
|
| 231 | 231 | public function getSlash() |
| 232 | 232 | { |
| 233 | 233 | return $this->normalize['to']; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Keeps instances of files. |
|
| 238 | - * @var SVNHelper_Target[] |
|
| 239 | - */ |
|
| 236 | + /** |
|
| 237 | + * Keeps instances of files. |
|
| 238 | + * @var SVNHelper_Target[] |
|
| 239 | + */ |
|
| 240 | 240 | protected $targets = array(); |
| 241 | 241 | |
| 242 | - /** |
|
| 243 | - * Retrieves a file instance from the SVN repository: |
|
| 244 | - * this allows all possible operations on the file as |
|
| 245 | - * well as accessing more information on it. |
|
| 246 | - * |
|
| 247 | - * @param string $path A path to the file, relative to the repository path or absolute. |
|
| 248 | - * @return SVNHelper_Target_File |
|
| 249 | - * @throws SVNHelper_Exception |
|
| 250 | - */ |
|
| 242 | + /** |
|
| 243 | + * Retrieves a file instance from the SVN repository: |
|
| 244 | + * this allows all possible operations on the file as |
|
| 245 | + * well as accessing more information on it. |
|
| 246 | + * |
|
| 247 | + * @param string $path A path to the file, relative to the repository path or absolute. |
|
| 248 | + * @return SVNHelper_Target_File |
|
| 249 | + * @throws SVNHelper_Exception |
|
| 250 | + */ |
|
| 251 | 251 | public function getFile(string $path) : SVNHelper_Target_File |
| 252 | 252 | { |
| 253 | 253 | $path = $this->filterPath($path); |
@@ -256,15 +256,15 @@ discard block |
||
| 256 | 256 | ->requireIsFile(); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Retrieves a folder instance from the SVN repository: |
|
| 261 | - * This allows all possible operations on the folder as |
|
| 262 | - * well as accessing more information on it. |
|
| 263 | - * |
|
| 264 | - * @param string $path |
|
| 265 | - * @return SVNHelper_Target_Folder |
|
| 266 | - * @throws SVNHelper_Exception |
|
| 267 | - */ |
|
| 259 | + /** |
|
| 260 | + * Retrieves a folder instance from the SVN repository: |
|
| 261 | + * This allows all possible operations on the folder as |
|
| 262 | + * well as accessing more information on it. |
|
| 263 | + * |
|
| 264 | + * @param string $path |
|
| 265 | + * @return SVNHelper_Target_Folder |
|
| 266 | + * @throws SVNHelper_Exception |
|
| 267 | + */ |
|
| 268 | 268 | public function getFolder(string $path) : SVNHelper_Target_Folder |
| 269 | 269 | { |
| 270 | 270 | $path = $this->filterPath($path); |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | ->requireIsFolder(); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * Passes the path through realpath and ensures it exists. |
|
| 278 | - * |
|
| 279 | - * @param string $path |
|
| 280 | - * @throws SVNHelper_Exception |
|
| 281 | - * @return string |
|
| 282 | - */ |
|
| 276 | + /** |
|
| 277 | + * Passes the path through realpath and ensures it exists. |
|
| 278 | + * |
|
| 279 | + * @param string $path |
|
| 280 | + * @throws SVNHelper_Exception |
|
| 281 | + * @return string |
|
| 282 | + */ |
|
| 283 | 283 | protected function filterPath($path) |
| 284 | 284 | { |
| 285 | 285 | if(empty($path)) { |
@@ -304,13 +304,13 @@ discard block |
||
| 304 | 304 | ); |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * Retrieves a target file or folder within the repository. |
|
| 309 | - * |
|
| 310 | - * @param string $type The target type, "File" or "Folder". |
|
| 311 | - * @param string $relativePath A path relative to the root folder. |
|
| 312 | - * @return SVNHelper_Target |
|
| 313 | - */ |
|
| 307 | + /** |
|
| 308 | + * Retrieves a target file or folder within the repository. |
|
| 309 | + * |
|
| 310 | + * @param string $type The target type, "File" or "Folder". |
|
| 311 | + * @param string $relativePath A path relative to the root folder. |
|
| 312 | + * @return SVNHelper_Target |
|
| 313 | + */ |
|
| 314 | 314 | protected function getTarget(string $type, string $relativePath) : SVNHelper_Target |
| 315 | 315 | { |
| 316 | 316 | $key = $type.':'.$relativePath; |
@@ -358,33 +358,33 @@ discard block |
||
| 358 | 358 | return $this->url; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - /** |
|
| 362 | - * Updates the whole SVN repository from the root folder. |
|
| 363 | - * @return SVNHelper_CommandResult |
|
| 364 | - */ |
|
| 361 | + /** |
|
| 362 | + * Updates the whole SVN repository from the root folder. |
|
| 363 | + * @return SVNHelper_CommandResult |
|
| 364 | + */ |
|
| 365 | 365 | public function runUpdate() |
| 366 | 366 | { |
| 367 | 367 | return $this->createUpdate($this->target)->execute(); |
| 368 | 368 | } |
| 369 | 369 | |
| 370 | - /** |
|
| 371 | - * Creates an update command for the target file or folder. |
|
| 372 | - * This can be configured further before it is executed. |
|
| 373 | - * |
|
| 374 | - * @param SVNHelper_Target $target |
|
| 375 | - * @return SVNHelper_Command_Update |
|
| 376 | - */ |
|
| 370 | + /** |
|
| 371 | + * Creates an update command for the target file or folder. |
|
| 372 | + * This can be configured further before it is executed. |
|
| 373 | + * |
|
| 374 | + * @param SVNHelper_Target $target |
|
| 375 | + * @return SVNHelper_Command_Update |
|
| 376 | + */ |
|
| 377 | 377 | public function createUpdate(SVNHelper_Target $target) |
| 378 | 378 | { |
| 379 | 379 | return $this->createCommand('Update', $target); |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - /** |
|
| 383 | - * Creates an add command for the targt file or folder. |
|
| 384 | - * |
|
| 385 | - * @param SVNHelper_Target $target |
|
| 386 | - * @return SVNHelper_Command_Add |
|
| 387 | - */ |
|
| 382 | + /** |
|
| 383 | + * Creates an add command for the targt file or folder. |
|
| 384 | + * |
|
| 385 | + * @param SVNHelper_Target $target |
|
| 386 | + * @return SVNHelper_Command_Add |
|
| 387 | + */ |
|
| 388 | 388 | public function createAdd(SVNHelper_Target $target) |
| 389 | 389 | { |
| 390 | 390 | return $this->createCommand('Add', $target); |
@@ -401,12 +401,12 @@ discard block |
||
| 401 | 401 | return $this->createCommand('Info', $target); |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - /** |
|
| 405 | - * Creates a status command for the target file or folder. |
|
| 406 | - * |
|
| 407 | - * @param SVNHelper_Target $target |
|
| 408 | - * @return SVNHelper_Command_Status |
|
| 409 | - */ |
|
| 404 | + /** |
|
| 405 | + * Creates a status command for the target file or folder. |
|
| 406 | + * |
|
| 407 | + * @param SVNHelper_Target $target |
|
| 408 | + * @return SVNHelper_Command_Status |
|
| 409 | + */ |
|
| 410 | 410 | public function createStatus(SVNHelper_Target $target) |
| 411 | 411 | { |
| 412 | 412 | return $this->createCommand('Status', $target); |
@@ -431,28 +431,28 @@ discard block |
||
| 431 | 431 | return $cmd; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | - /** |
|
| 435 | - * Creates a path relative to the repository for the target |
|
| 436 | - * file or folder, from an absolute path. |
|
| 437 | - * |
|
| 438 | - * @param string $path An absolute path. |
|
| 439 | - * @return string |
|
| 440 | - */ |
|
| 434 | + /** |
|
| 435 | + * Creates a path relative to the repository for the target |
|
| 436 | + * file or folder, from an absolute path. |
|
| 437 | + * |
|
| 438 | + * @param string $path An absolute path. |
|
| 439 | + * @return string |
|
| 440 | + */ |
|
| 441 | 441 | public function relativizePath($path) |
| 442 | 442 | { |
| 443 | 443 | return $this->normalizePath($path, true); |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - /** |
|
| 447 | - * Adds a folder: creates it as necessary (recursive), |
|
| 448 | - * and adds it to be committed if it is not versioned yet. |
|
| 449 | - * Use this instead of {@link getFolder()} when you are |
|
| 450 | - * not sure that it exists yet, and will need it. |
|
| 451 | - * |
|
| 452 | - * @param string $path Absolute or relative path to the folder |
|
| 453 | - * @throws SVNHelper_Exception |
|
| 454 | - * @return SVNHelper_Target_Folder |
|
| 455 | - */ |
|
| 446 | + /** |
|
| 447 | + * Adds a folder: creates it as necessary (recursive), |
|
| 448 | + * and adds it to be committed if it is not versioned yet. |
|
| 449 | + * Use this instead of {@link getFolder()} when you are |
|
| 450 | + * not sure that it exists yet, and will need it. |
|
| 451 | + * |
|
| 452 | + * @param string $path Absolute or relative path to the folder |
|
| 453 | + * @throws SVNHelper_Exception |
|
| 454 | + * @return SVNHelper_Target_Folder |
|
| 455 | + */ |
|
| 456 | 456 | public function addFolder($path) |
| 457 | 457 | { |
| 458 | 458 | if(is_dir($path)) { |
@@ -502,14 +502,14 @@ discard block |
||
| 502 | 502 | |
| 503 | 503 | protected static $logCallback; |
| 504 | 504 | |
| 505 | - /** |
|
| 506 | - * Sets the callback function/method to use for |
|
| 507 | - * SVH helper log messages. This gets the message |
|
| 508 | - * and the SVNHelper instance as parameters. |
|
| 509 | - * |
|
| 510 | - * @param callable $callback |
|
| 511 | - * @throws SVNHelper_Exception |
|
| 512 | - */ |
|
| 505 | + /** |
|
| 506 | + * Sets the callback function/method to use for |
|
| 507 | + * SVH helper log messages. This gets the message |
|
| 508 | + * and the SVNHelper instance as parameters. |
|
| 509 | + * |
|
| 510 | + * @param callable $callback |
|
| 511 | + * @throws SVNHelper_Exception |
|
| 512 | + */ |
|
| 513 | 513 | public static function setLogCallback($callback) |
| 514 | 514 | { |
| 515 | 515 | if(!is_callable($callback)) { |
@@ -530,22 +530,22 @@ discard block |
||
| 530 | 530 | } |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | - /** |
|
| 534 | - * Retrieves information about the file, and adds it |
|
| 535 | - * to be committed later if it not versioned yet. |
|
| 536 | - * |
|
| 537 | - * @param string $path |
|
| 538 | - * @return SVNHelper_Target_File |
|
| 539 | - */ |
|
| 533 | + /** |
|
| 534 | + * Retrieves information about the file, and adds it |
|
| 535 | + * to be committed later if it not versioned yet. |
|
| 536 | + * |
|
| 537 | + * @param string $path |
|
| 538 | + * @return SVNHelper_Target_File |
|
| 539 | + */ |
|
| 540 | 540 | public function addFile($path) |
| 541 | 541 | { |
| 542 | 542 | return $this->getFile($path)->runAdd(); |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - /** |
|
| 546 | - * Commits all changes in the repository. |
|
| 547 | - * @param string $message The commit message to log. |
|
| 548 | - */ |
|
| 545 | + /** |
|
| 546 | + * Commits all changes in the repository. |
|
| 547 | + * @param string $message The commit message to log. |
|
| 548 | + */ |
|
| 549 | 549 | public function runCommit($message) |
| 550 | 550 | { |
| 551 | 551 | $this->createCommit($this->getFolder($this->path), $message)->execute(); |
@@ -177,12 +177,12 @@ discard block |
||
| 177 | 177 | return $this->applyValidations($value); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Runs the value through all validations that were added. |
|
| 182 | - * |
|
| 183 | - * @param mixed $value |
|
| 184 | - * @return mixed |
|
| 185 | - */ |
|
| 180 | + /** |
|
| 181 | + * Runs the value through all validations that were added. |
|
| 182 | + * |
|
| 183 | + * @param mixed $value |
|
| 184 | + * @return mixed |
|
| 185 | + */ |
|
| 186 | 186 | protected function applyValidations($value, bool $subval=false) |
| 187 | 187 | { |
| 188 | 188 | // go through all enqueued validations in turn, each time |
@@ -195,17 +195,17 @@ discard block |
||
| 195 | 195 | return $value; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Validates the specified value using the validation type. Returns |
|
| 200 | - * the validated value. |
|
| 201 | - * |
|
| 202 | - * @param mixed $value |
|
| 203 | - * @param string $type |
|
| 204 | - * @param array<string,mixed> $params |
|
| 205 | - * @param bool $subval Whether this is a subvalue in a list |
|
| 206 | - * @throws Request_Exception |
|
| 207 | - * @return mixed |
|
| 208 | - */ |
|
| 198 | + /** |
|
| 199 | + * Validates the specified value using the validation type. Returns |
|
| 200 | + * the validated value. |
|
| 201 | + * |
|
| 202 | + * @param mixed $value |
|
| 203 | + * @param string $type |
|
| 204 | + * @param array<string,mixed> $params |
|
| 205 | + * @param bool $subval Whether this is a subvalue in a list |
|
| 206 | + * @throws Request_Exception |
|
| 207 | + * @return mixed |
|
| 208 | + */ |
|
| 209 | 209 | protected function validateType($value, string $type, array $params, bool $subval) |
| 210 | 210 | { |
| 211 | 211 | $class = Request_Param_Validator::class.'_'.ucfirst($type); |
@@ -270,13 +270,13 @@ discard block |
||
| 270 | 270 | return $this->setValidation(self::VALIDATION_TYPE_URL); |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - /** |
|
| 274 | - * Sets the variable to contain a comma-separated list of integer IDs. |
|
| 275 | - * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
| 276 | - * <code>145</code>. |
|
| 277 | - * |
|
| 278 | - * @return $this |
|
| 279 | - */ |
|
| 273 | + /** |
|
| 274 | + * Sets the variable to contain a comma-separated list of integer IDs. |
|
| 275 | + * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
| 276 | + * <code>145</code>. |
|
| 277 | + * |
|
| 278 | + * @return $this |
|
| 279 | + */ |
|
| 280 | 280 | public function setIDList() : self |
| 281 | 281 | { |
| 282 | 282 | $this->valueType = self::VALUE_TYPE_LIST; |
@@ -286,13 +286,13 @@ discard block |
||
| 286 | 286 | return $this; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * Sets the variable to be an alias, as defined by the |
|
| 291 | - * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
| 292 | - * |
|
| 293 | - * @return $this |
|
| 294 | - * @see RegexHelper::REGEX_ALIAS |
|
| 295 | - */ |
|
| 289 | + /** |
|
| 290 | + * Sets the variable to be an alias, as defined by the |
|
| 291 | + * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
| 292 | + * |
|
| 293 | + * @return $this |
|
| 294 | + * @see RegexHelper::REGEX_ALIAS |
|
| 295 | + */ |
|
| 296 | 296 | public function setAlias() : self |
| 297 | 297 | { |
| 298 | 298 | return $this->setRegex(RegexHelper::REGEX_ALIAS); |
@@ -333,12 +333,12 @@ discard block |
||
| 333 | 333 | return $this->setValidation(self::VALIDATION_TYPE_ALPHA); |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * Sets the parameter value as a string containing lowercase |
|
| 338 | - * and/or uppercase letters, as well as numbers. |
|
| 339 | - * |
|
| 340 | - * @return $this |
|
| 341 | - */ |
|
| 336 | + /** |
|
| 337 | + * Sets the parameter value as a string containing lowercase |
|
| 338 | + * and/or uppercase letters, as well as numbers. |
|
| 339 | + * |
|
| 340 | + * @return $this |
|
| 341 | + */ |
|
| 342 | 342 | public function setAlnum() : self |
| 343 | 343 | { |
| 344 | 344 | return $this->setValidation(self::VALIDATION_TYPE_ALNUM); |
@@ -396,11 +396,11 @@ discard block |
||
| 396 | 396 | ); |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - /** |
|
| 400 | - * Whether the parameter is a list of values. |
|
| 401 | - * |
|
| 402 | - * @return bool |
|
| 403 | - */ |
|
| 399 | + /** |
|
| 400 | + * Whether the parameter is a list of values. |
|
| 401 | + * |
|
| 402 | + * @return bool |
|
| 403 | + */ |
|
| 404 | 404 | public function isList() : bool |
| 405 | 405 | { |
| 406 | 406 | return $this->valueType === self::VALUE_TYPE_LIST; |
@@ -442,28 +442,28 @@ discard block |
||
| 442 | 442 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => false)); |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - /** |
|
| 446 | - * The parameter is a string boolean representation. This means |
|
| 447 | - * it can be any of the following: "yes", "true", "no", "false". |
|
| 448 | - * The value is automatically converted to a boolean when retrieving |
|
| 449 | - * the parameter. |
|
| 450 | - * |
|
| 451 | - * @return $this |
|
| 452 | - */ |
|
| 445 | + /** |
|
| 446 | + * The parameter is a string boolean representation. This means |
|
| 447 | + * it can be any of the following: "yes", "true", "no", "false". |
|
| 448 | + * The value is automatically converted to a boolean when retrieving |
|
| 449 | + * the parameter. |
|
| 450 | + * |
|
| 451 | + * @return $this |
|
| 452 | + */ |
|
| 453 | 453 | public function setBoolean() : self |
| 454 | 454 | { |
| 455 | 455 | return $this->addClassFilter('Boolean'); |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | - /** |
|
| 459 | - * Validates the request parameter as an MD5 string, |
|
| 460 | - * so that only values resembling md5 values are accepted. |
|
| 461 | - * |
|
| 462 | - * NOTE: This can only guarantee the format, not whether |
|
| 463 | - * it is an actual valid hash of something. |
|
| 464 | - * |
|
| 465 | - * @return $this |
|
| 466 | - */ |
|
| 458 | + /** |
|
| 459 | + * Validates the request parameter as an MD5 string, |
|
| 460 | + * so that only values resembling md5 values are accepted. |
|
| 461 | + * |
|
| 462 | + * NOTE: This can only guarantee the format, not whether |
|
| 463 | + * it is an actual valid hash of something. |
|
| 464 | + * |
|
| 465 | + * @return $this |
|
| 466 | + */ |
|
| 467 | 467 | public function setMD5() : self |
| 468 | 468 | { |
| 469 | 469 | return $this->setRegex(RegexHelper::REGEX_MD5); |
@@ -503,14 +503,14 @@ discard block |
||
| 503 | 503 | return $this; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - /** |
|
| 507 | - * Retrieves the value of the request parameter, |
|
| 508 | - * applying all filters (if any) and validation |
|
| 509 | - * (if any). |
|
| 510 | - * |
|
| 511 | - * @param mixed $default |
|
| 512 | - * @return mixed |
|
| 513 | - */ |
|
| 506 | + /** |
|
| 507 | + * Retrieves the value of the request parameter, |
|
| 508 | + * applying all filters (if any) and validation |
|
| 509 | + * (if any). |
|
| 510 | + * |
|
| 511 | + * @param mixed $default |
|
| 512 | + * @return mixed |
|
| 513 | + */ |
|
| 514 | 514 | public function get($default=null) |
| 515 | 515 | { |
| 516 | 516 | $value = $this->request->getParam($this->paramName); |
@@ -523,17 +523,17 @@ discard block |
||
| 523 | 523 | |
| 524 | 524 | // region: Filtering |
| 525 | 525 | |
| 526 | - /** |
|
| 527 | - * Filters the specified value by going through all available |
|
| 528 | - * filters, if any. If none have been set, the value is simply |
|
| 529 | - * passed through. |
|
| 530 | - * |
|
| 531 | - * @param mixed $value |
|
| 532 | - * @return mixed |
|
| 533 | - * |
|
| 534 | - * @see RequestParam::applyFilter_callback() |
|
| 535 | - * @see RequestParam::applyFilter_class() |
|
| 536 | - */ |
|
| 526 | + /** |
|
| 527 | + * Filters the specified value by going through all available |
|
| 528 | + * filters, if any. If none have been set, the value is simply |
|
| 529 | + * passed through. |
|
| 530 | + * |
|
| 531 | + * @param mixed $value |
|
| 532 | + * @return mixed |
|
| 533 | + * |
|
| 534 | + * @see RequestParam::applyFilter_callback() |
|
| 535 | + * @see RequestParam::applyFilter_class() |
|
| 536 | + */ |
|
| 537 | 537 | protected function filter($value) |
| 538 | 538 | { |
| 539 | 539 | foreach ($this->filters as $filter) |
@@ -622,12 +622,12 @@ discard block |
||
| 622 | 622 | return $this; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - /** |
|
| 626 | - * Adds a filter that trims whitespace from the request |
|
| 627 | - * parameter using the PHP <code>trim</code> function. |
|
| 628 | - * |
|
| 629 | - * @return $this |
|
| 630 | - */ |
|
| 625 | + /** |
|
| 626 | + * Adds a filter that trims whitespace from the request |
|
| 627 | + * parameter using the PHP <code>trim</code> function. |
|
| 628 | + * |
|
| 629 | + * @return $this |
|
| 630 | + */ |
|
| 631 | 631 | public function addFilterTrim() : self |
| 632 | 632 | { |
| 633 | 633 | // to guarantee we only work with strings |
@@ -636,13 +636,13 @@ discard block |
||
| 636 | 636 | return $this->addCallbackFilter('trim'); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - /** |
|
| 640 | - * Converts the value to a string, even if it is not |
|
| 641 | - * a string value. Complex types like arrays and objects |
|
| 642 | - * are converted to an empty string. |
|
| 643 | - * |
|
| 644 | - * @return $this |
|
| 645 | - */ |
|
| 639 | + /** |
|
| 640 | + * Converts the value to a string, even if it is not |
|
| 641 | + * a string value. Complex types like arrays and objects |
|
| 642 | + * are converted to an empty string. |
|
| 643 | + * |
|
| 644 | + * @return $this |
|
| 645 | + */ |
|
| 646 | 646 | public function addStringFilter() : self |
| 647 | 647 | { |
| 648 | 648 | return $this->addClassFilter('String'); |
@@ -694,12 +694,12 @@ discard block |
||
| 694 | 694 | return $this->addCallbackFilter('strip_tags', array($allowedTags)); |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - /** |
|
| 698 | - * Adds a filter that strips all whitespace from the |
|
| 699 | - * request parameter, from spaces to tabs and newlines. |
|
| 700 | - * |
|
| 701 | - * @return $this |
|
| 702 | - */ |
|
| 697 | + /** |
|
| 698 | + * Adds a filter that strips all whitespace from the |
|
| 699 | + * request parameter, from spaces to tabs and newlines. |
|
| 700 | + * |
|
| 701 | + * @return $this |
|
| 702 | + */ |
|
| 703 | 703 | public function addStripWhitespaceFilter() : self |
| 704 | 704 | { |
| 705 | 705 | // to ensure we only work with strings. |
@@ -708,14 +708,14 @@ discard block |
||
| 708 | 708 | return $this->addClassFilter('StripWhitespace'); |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | - /** |
|
| 712 | - * Adds a filter that transforms comma separated values |
|
| 713 | - * into an array of values. |
|
| 714 | - * |
|
| 715 | - * @param bool $trimEntries Trim whitespace from each entry? |
|
| 716 | - * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
| 717 | - * @return $this |
|
| 718 | - */ |
|
| 711 | + /** |
|
| 712 | + * Adds a filter that transforms comma separated values |
|
| 713 | + * into an array of values. |
|
| 714 | + * |
|
| 715 | + * @param bool $trimEntries Trim whitespace from each entry? |
|
| 716 | + * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
| 717 | + * @return $this |
|
| 718 | + */ |
|
| 719 | 719 | public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : self |
| 720 | 720 | { |
| 721 | 721 | $this->setArray(); |
@@ -746,12 +746,12 @@ discard block |
||
| 746 | 746 | ); |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | - /** |
|
| 750 | - * Adds a filter that encodes all HTML special characters |
|
| 751 | - * using the PHP <code>htmlspecialchars</code> function. |
|
| 752 | - * |
|
| 753 | - * @return $this |
|
| 754 | - */ |
|
| 749 | + /** |
|
| 750 | + * Adds a filter that encodes all HTML special characters |
|
| 751 | + * using the PHP <code>htmlspecialchars</code> function. |
|
| 752 | + * |
|
| 753 | + * @return $this |
|
| 754 | + */ |
|
| 755 | 755 | public function addHTMLSpecialcharsFilter() : self |
| 756 | 756 | { |
| 757 | 757 | return $this->addCallbackFilter('htmlspecialchars', array(ENT_QUOTES, 'UTF-8')); |
@@ -764,14 +764,14 @@ discard block |
||
| 764 | 764 | return $this->paramName; |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | - /** |
|
| 768 | - * Marks this request parameter as required. To use this feature, |
|
| 769 | - * you have to call the request's {@link Request::validate()} |
|
| 770 | - * method. |
|
| 771 | - * |
|
| 772 | - * @return RequestParam |
|
| 773 | - * @see Request::validate() |
|
| 774 | - */ |
|
| 767 | + /** |
|
| 768 | + * Marks this request parameter as required. To use this feature, |
|
| 769 | + * you have to call the request's {@link Request::validate()} |
|
| 770 | + * method. |
|
| 771 | + * |
|
| 772 | + * @return RequestParam |
|
| 773 | + * @see Request::validate() |
|
| 774 | + */ |
|
| 775 | 775 | public function makeRequired() : RequestParam |
| 776 | 776 | { |
| 777 | 777 | $this->required = true; |
@@ -56,12 +56,12 @@ discard block |
||
| 56 | 56 | $this->init(); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Can be extended in a subclass, to avoid |
|
| 61 | - * redefining the constructor. |
|
| 62 | - * |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 59 | + /** |
|
| 60 | + * Can be extended in a subclass, to avoid |
|
| 61 | + * redefining the constructor. |
|
| 62 | + * |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | 65 | protected function init() : void |
| 66 | 66 | { |
| 67 | 67 | |
@@ -126,30 +126,30 @@ discard block |
||
| 126 | 126 | return $this->buildURL($params, $dispatcher); |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Retrieves the name of the current dispatcher script / page. |
|
| 131 | - * This is made to be extended and implemented in a subclass. |
|
| 132 | - * |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 129 | + /** |
|
| 130 | + * Retrieves the name of the current dispatcher script / page. |
|
| 131 | + * This is made to be extended and implemented in a subclass. |
|
| 132 | + * |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | 135 | public function getDispatcher() : string |
| 136 | 136 | { |
| 137 | 137 | return ''; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Filters and retrieves the current request variables |
|
| 142 | - * to be used to build a URL to refresh the current page. |
|
| 143 | - * |
|
| 144 | - * For further customization options, use the |
|
| 145 | - * {@see Request::createRefreshParams()} method. |
|
| 146 | - * |
|
| 147 | - * @param array<string,mixed> $params Key => value pairs of parameters to always include in the result. |
|
| 148 | - * @param string[] $exclude Names of parameters to exclude from the result. |
|
| 149 | - * @return array<string,mixed> |
|
| 150 | - * |
|
| 151 | - * @see Request::createRefreshParams() |
|
| 152 | - */ |
|
| 140 | + /** |
|
| 141 | + * Filters and retrieves the current request variables |
|
| 142 | + * to be used to build a URL to refresh the current page. |
|
| 143 | + * |
|
| 144 | + * For further customization options, use the |
|
| 145 | + * {@see Request::createRefreshParams()} method. |
|
| 146 | + * |
|
| 147 | + * @param array<string,mixed> $params Key => value pairs of parameters to always include in the result. |
|
| 148 | + * @param string[] $exclude Names of parameters to exclude from the result. |
|
| 149 | + * @return array<string,mixed> |
|
| 150 | + * |
|
| 151 | + * @see Request::createRefreshParams() |
|
| 152 | + */ |
|
| 153 | 153 | public function getRefreshParams(array $params = array(), array $exclude = array()) : array |
| 154 | 154 | { |
| 155 | 155 | return $this->createRefreshParams() |
@@ -158,13 +158,13 @@ discard block |
||
| 158 | 158 | ->getParams(); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - /** |
|
| 162 | - * Creates an instance of the helper that can be used to |
|
| 163 | - * retrieve the request's parameters collection, with the |
|
| 164 | - * possibility to exclude and override some by rules. |
|
| 165 | - * |
|
| 166 | - * @return Request_RefreshParams |
|
| 167 | - */ |
|
| 161 | + /** |
|
| 162 | + * Creates an instance of the helper that can be used to |
|
| 163 | + * retrieve the request's parameters collection, with the |
|
| 164 | + * possibility to exclude and override some by rules. |
|
| 165 | + * |
|
| 166 | + * @return Request_RefreshParams |
|
| 167 | + */ |
|
| 168 | 168 | public function createRefreshParams() : Request_RefreshParams |
| 169 | 169 | { |
| 170 | 170 | return new Request_RefreshParams(); |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | return $url; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * Retrieves the base URL of the application. |
|
| 205 | - * @return string |
|
| 206 | - */ |
|
| 203 | + /** |
|
| 204 | + * Retrieves the base URL of the application. |
|
| 205 | + * @return string |
|
| 206 | + */ |
|
| 207 | 207 | public function getBaseURL() : string |
| 208 | 208 | { |
| 209 | 209 | return $this->baseURL; |
@@ -233,13 +233,13 @@ discard block |
||
| 233 | 233 | return $this->knownParams[$name]; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Retrieves a previously registered parameter instance. |
|
| 238 | - * |
|
| 239 | - * @param string $name |
|
| 240 | - * @return RequestParam |
|
| 241 | - *@throws Request_Exception |
|
| 242 | - */ |
|
| 236 | + /** |
|
| 237 | + * Retrieves a previously registered parameter instance. |
|
| 238 | + * |
|
| 239 | + * @param string $name |
|
| 240 | + * @return RequestParam |
|
| 241 | + *@throws Request_Exception |
|
| 242 | + */ |
|
| 243 | 243 | public function getRegisteredParam(string $name) : RequestParam |
| 244 | 244 | { |
| 245 | 245 | if(isset($this->knownParams[$name])) { |
@@ -256,48 +256,48 @@ discard block |
||
| 256 | 256 | ); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Checks whether a parameter with the specified name |
|
| 261 | - * has been registered. |
|
| 262 | - * |
|
| 263 | - * @param string $name |
|
| 264 | - * @return bool |
|
| 265 | - */ |
|
| 259 | + /** |
|
| 260 | + * Checks whether a parameter with the specified name |
|
| 261 | + * has been registered. |
|
| 262 | + * |
|
| 263 | + * @param string $name |
|
| 264 | + * @return bool |
|
| 265 | + */ |
|
| 266 | 266 | public function hasRegisteredParam(string $name) : bool |
| 267 | 267 | { |
| 268 | 268 | return isset($this->knownParams[$name]); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Retrieves an indexed array with accept mime types |
|
| 273 | - * that the client sent, in the order of preference |
|
| 274 | - * the client specified. |
|
| 275 | - * |
|
| 276 | - * Example: |
|
| 277 | - * |
|
| 278 | - * array( |
|
| 279 | - * 'text/html', |
|
| 280 | - * 'application/xhtml+xml', |
|
| 281 | - * 'image/webp' |
|
| 282 | - * ... |
|
| 283 | - * ) |
|
| 284 | - * |
|
| 285 | - * @return string[] |
|
| 286 | - * @see Request::parseAcceptHeaders() |
|
| 287 | - */ |
|
| 271 | + /** |
|
| 272 | + * Retrieves an indexed array with accept mime types |
|
| 273 | + * that the client sent, in the order of preference |
|
| 274 | + * the client specified. |
|
| 275 | + * |
|
| 276 | + * Example: |
|
| 277 | + * |
|
| 278 | + * array( |
|
| 279 | + * 'text/html', |
|
| 280 | + * 'application/xhtml+xml', |
|
| 281 | + * 'image/webp' |
|
| 282 | + * ... |
|
| 283 | + * ) |
|
| 284 | + * |
|
| 285 | + * @return string[] |
|
| 286 | + * @see Request::parseAcceptHeaders() |
|
| 287 | + */ |
|
| 288 | 288 | public static function getAcceptHeaders() : array |
| 289 | 289 | { |
| 290 | 290 | return self::parseAcceptHeaders()->getMimeStrings(); |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Returns an instance of the "accept" headers parser, |
|
| 295 | - * to access information on the browser's accepted |
|
| 296 | - * mime types. |
|
| 297 | - * |
|
| 298 | - * @return Request_AcceptHeaders |
|
| 299 | - * @see Request::getAcceptHeaders() |
|
| 300 | - */ |
|
| 293 | + /** |
|
| 294 | + * Returns an instance of the "accept" headers parser, |
|
| 295 | + * to access information on the browser's accepted |
|
| 296 | + * mime types. |
|
| 297 | + * |
|
| 298 | + * @return Request_AcceptHeaders |
|
| 299 | + * @see Request::getAcceptHeaders() |
|
| 300 | + */ |
|
| 301 | 301 | public static function parseAcceptHeaders() : Request_AcceptHeaders |
| 302 | 302 | { |
| 303 | 303 | static $accept; |
@@ -341,14 +341,14 @@ discard block |
||
| 341 | 341 | return $this->getParam($name) !== null; |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - /** |
|
| 345 | - * Removes a single parameter from the request. |
|
| 346 | - * If the parameter has been registered, also |
|
| 347 | - * removes the registration info. |
|
| 348 | - * |
|
| 349 | - * @param string $name |
|
| 350 | - * @return Request |
|
| 351 | - */ |
|
| 344 | + /** |
|
| 345 | + * Removes a single parameter from the request. |
|
| 346 | + * If the parameter has been registered, also |
|
| 347 | + * removes the registration info. |
|
| 348 | + * |
|
| 349 | + * @param string $name |
|
| 350 | + * @return Request |
|
| 351 | + */ |
|
| 352 | 352 | public function removeParam(string $name) : Request |
| 353 | 353 | { |
| 354 | 354 | if(isset($_REQUEST[$name])) { |
@@ -362,12 +362,12 @@ discard block |
||
| 362 | 362 | return $this; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * Removes several parameters from the request. |
|
| 367 | - * |
|
| 368 | - * @param string[] $names |
|
| 369 | - * @return Request |
|
| 370 | - */ |
|
| 365 | + /** |
|
| 366 | + * Removes several parameters from the request. |
|
| 367 | + * |
|
| 368 | + * @param string[] $names |
|
| 369 | + * @return Request |
|
| 370 | + */ |
|
| 371 | 371 | public function removeParams(array $names) : Request |
| 372 | 372 | { |
| 373 | 373 | foreach($names as $name) { |
@@ -563,11 +563,11 @@ discard block |
||
| 563 | 563 | exit; |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - /** |
|
| 567 | - * Sends HTML to the browser with the correct headers. |
|
| 568 | - * |
|
| 569 | - * @param string $html |
|
| 570 | - */ |
|
| 566 | + /** |
|
| 567 | + * Sends HTML to the browser with the correct headers. |
|
| 568 | + * |
|
| 569 | + * @param string $html |
|
| 570 | + */ |
|
| 571 | 571 | public static function sendHTML(string $html) : void |
| 572 | 572 | { |
| 573 | 573 | header('Cache-Control: no-cache, must-revalidate'); |
@@ -588,16 +588,16 @@ discard block |
||
| 588 | 588 | exit; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - /** |
|
| 592 | - * Creates a new instance of the URL comparer, which can check |
|
| 593 | - * whether the specified URLs match, regardless of the order in |
|
| 594 | - * which the query parameters are, if any. |
|
| 595 | - * |
|
| 596 | - * @param string $sourceURL |
|
| 597 | - * @param string $targetURL |
|
| 598 | - * @param string[] $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
| 599 | - * @return Request_URLComparer |
|
| 600 | - */ |
|
| 591 | + /** |
|
| 592 | + * Creates a new instance of the URL comparer, which can check |
|
| 593 | + * whether the specified URLs match, regardless of the order in |
|
| 594 | + * which the query parameters are, if any. |
|
| 595 | + * |
|
| 596 | + * @param string $sourceURL |
|
| 597 | + * @param string $targetURL |
|
| 598 | + * @param string[] $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
| 599 | + * @return Request_URLComparer |
|
| 600 | + */ |
|
| 601 | 601 | public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
| 602 | 602 | { |
| 603 | 603 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
@@ -606,10 +606,10 @@ discard block |
||
| 606 | 606 | return $comparer; |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | - /** |
|
| 610 | - * Retrieves the full URL that was used to access the current page. |
|
| 611 | - * @return string |
|
| 612 | - */ |
|
| 609 | + /** |
|
| 610 | + * Retrieves the full URL that was used to access the current page. |
|
| 611 | + * @return string |
|
| 612 | + */ |
|
| 613 | 613 | public function getCurrentURL() : string |
| 614 | 614 | { |
| 615 | 615 | return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
@@ -44,20 +44,20 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | protected FolderInfo $path; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var string[] |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var string[] |
|
| 49 | + */ |
|
| 50 | 50 | protected array $found = array(); |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * The path must exist when the class is instantiated: its |
|
| 54 | - * real path will be determined to work with. |
|
| 55 | - * |
|
| 56 | - * @param string|PathInfoInterface|SplFileInfo $path The absolute path to the target folder. |
|
| 57 | - * |
|
| 58 | - * @throws FileHelper_Exception |
|
| 59 | - * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 60 | - */ |
|
| 52 | + /** |
|
| 53 | + * The path must exist when the class is instantiated: its |
|
| 54 | + * real path will be determined to work with. |
|
| 55 | + * |
|
| 56 | + * @param string|PathInfoInterface|SplFileInfo $path The absolute path to the target folder. |
|
| 57 | + * |
|
| 58 | + * @throws FileHelper_Exception |
|
| 59 | + * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 60 | + */ |
|
| 61 | 61 | public function __construct($path) |
| 62 | 62 | { |
| 63 | 63 | $this->path = AbstractPathInfo::resolveType($path)->requireExists()->requireIsFolder(); |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | ); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Enables extension stripping, to return file names without extension. |
|
| 80 | - * |
|
| 81 | - * @return FileFinder |
|
| 82 | - */ |
|
| 78 | + /** |
|
| 79 | + * Enables extension stripping, to return file names without extension. |
|
| 80 | + * |
|
| 81 | + * @return FileFinder |
|
| 82 | + */ |
|
| 83 | 83 | public function stripExtensions() : FileFinder |
| 84 | 84 | { |
| 85 | 85 | return $this->setOption('strip-extensions', true); |
@@ -96,46 +96,46 @@ discard block |
||
| 96 | 96 | return $this->setOption('recursive', $enabled); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Retrieves all extensions that were added to |
|
| 101 | - * the list of included extensions. |
|
| 102 | - * |
|
| 103 | - * @return string[] |
|
| 104 | - */ |
|
| 99 | + /** |
|
| 100 | + * Retrieves all extensions that were added to |
|
| 101 | + * the list of included extensions. |
|
| 102 | + * |
|
| 103 | + * @return string[] |
|
| 104 | + */ |
|
| 105 | 105 | public function getIncludeExtensions() : array |
| 106 | 106 | { |
| 107 | 107 | return $this->getArrayOption(self::OPTION_INCLUDE_EXTENSIONS); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Includes a single extension in the file search: only |
|
| 112 | - * files with this extension will be used in the results. |
|
| 113 | - * |
|
| 114 | - * NOTE: Included extensions take precedence before excluded |
|
| 115 | - * extensions. If any excluded extensions are specified, they |
|
| 116 | - * will be ignored. |
|
| 117 | - * |
|
| 118 | - * @param string $extension Extension name, without dot (`php` for example). |
|
| 119 | - * @return FileFinder |
|
| 120 | - * @see FileFinder::includeExtensions() |
|
| 121 | - */ |
|
| 110 | + /** |
|
| 111 | + * Includes a single extension in the file search: only |
|
| 112 | + * files with this extension will be used in the results. |
|
| 113 | + * |
|
| 114 | + * NOTE: Included extensions take precedence before excluded |
|
| 115 | + * extensions. If any excluded extensions are specified, they |
|
| 116 | + * will be ignored. |
|
| 117 | + * |
|
| 118 | + * @param string $extension Extension name, without dot (`php` for example). |
|
| 119 | + * @return FileFinder |
|
| 120 | + * @see FileFinder::includeExtensions() |
|
| 121 | + */ |
|
| 122 | 122 | public function includeExtension(string $extension) : FileFinder |
| 123 | 123 | { |
| 124 | 124 | return $this->includeExtensions(array($extension)); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Includes several extensions in the file search: only |
|
| 129 | - * files with these extensions wil be used in the results. |
|
| 130 | - * |
|
| 131 | - * NOTE: Included extensions take precedence before excluded |
|
| 132 | - * extensions. If any excluded extensions are specified, they |
|
| 133 | - * will be ignored. |
|
| 134 | - * |
|
| 135 | - * @param string[] $extensions Extension names, without dot (`php` for example). |
|
| 136 | - * @return FileFinder |
|
| 137 | - * @see FileFinder::includeExtension() |
|
| 138 | - */ |
|
| 127 | + /** |
|
| 128 | + * Includes several extensions in the file search: only |
|
| 129 | + * files with these extensions wil be used in the results. |
|
| 130 | + * |
|
| 131 | + * NOTE: Included extensions take precedence before excluded |
|
| 132 | + * extensions. If any excluded extensions are specified, they |
|
| 133 | + * will be ignored. |
|
| 134 | + * |
|
| 135 | + * @param string[] $extensions Extension names, without dot (`php` for example). |
|
| 136 | + * @return FileFinder |
|
| 137 | + * @see FileFinder::includeExtension() |
|
| 138 | + */ |
|
| 139 | 139 | public function includeExtensions(array $extensions) : FileFinder |
| 140 | 140 | { |
| 141 | 141 | $items = $this->getIncludeExtensions(); |
@@ -146,37 +146,37 @@ discard block |
||
| 146 | 146 | return $this; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Retrieves a list of all extensions currently set as |
|
| 151 | - * excluded from the search. |
|
| 152 | - * |
|
| 153 | - * @return string[] |
|
| 154 | - */ |
|
| 149 | + /** |
|
| 150 | + * Retrieves a list of all extensions currently set as |
|
| 151 | + * excluded from the search. |
|
| 152 | + * |
|
| 153 | + * @return string[] |
|
| 154 | + */ |
|
| 155 | 155 | public function getExcludeExtensions() : array |
| 156 | 156 | { |
| 157 | 157 | return $this->getArrayOption(self::OPTION_EXCLUDE_EXTENSIONS); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * Excludes a single extension from the search. |
|
| 162 | - * |
|
| 163 | - * @param string $extension Extension name, without dot (`php` for example). |
|
| 164 | - * @return FileFinder |
|
| 165 | - * @see FileFinder::excludeExtensions() |
|
| 166 | - */ |
|
| 160 | + /** |
|
| 161 | + * Excludes a single extension from the search. |
|
| 162 | + * |
|
| 163 | + * @param string $extension Extension name, without dot (`php` for example). |
|
| 164 | + * @return FileFinder |
|
| 165 | + * @see FileFinder::excludeExtensions() |
|
| 166 | + */ |
|
| 167 | 167 | public function excludeExtension(string $extension) : FileFinder |
| 168 | 168 | { |
| 169 | 169 | return $this->excludeExtensions(array($extension)); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Add several extensions to the list of extensions to |
|
| 174 | - * exclude from the file search. |
|
| 175 | - * |
|
| 176 | - * @param string[] $extensions Extension names, without dot (`php` for example). |
|
| 177 | - * @return FileFinder |
|
| 178 | - * @see FileFinder::excludeExtension() |
|
| 179 | - */ |
|
| 172 | + /** |
|
| 173 | + * Add several extensions to the list of extensions to |
|
| 174 | + * exclude from the file search. |
|
| 175 | + * |
|
| 176 | + * @param string[] $extensions Extension names, without dot (`php` for example). |
|
| 177 | + * @return FileFinder |
|
| 178 | + * @see FileFinder::excludeExtension() |
|
| 179 | + */ |
|
| 180 | 180 | public function excludeExtensions(array $extensions) : FileFinder |
| 181 | 181 | { |
| 182 | 182 | $items = $this->getExcludeExtensions(); |
@@ -187,52 +187,52 @@ discard block |
||
| 187 | 187 | return $this; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * In this mode, the entire path to the file will be stripped, |
|
| 192 | - * leaving only the file name in the files list. |
|
| 193 | - * |
|
| 194 | - * @return FileFinder |
|
| 195 | - */ |
|
| 190 | + /** |
|
| 191 | + * In this mode, the entire path to the file will be stripped, |
|
| 192 | + * leaving only the file name in the files list. |
|
| 193 | + * |
|
| 194 | + * @return FileFinder |
|
| 195 | + */ |
|
| 196 | 196 | public function setPathmodeStrip() : FileFinder |
| 197 | 197 | { |
| 198 | 198 | return $this->setPathmode(self::PATH_MODE_STRIP); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * In this mode, only the path relative to the source folder |
|
| 203 | - * will be included in the files list. |
|
| 204 | - * |
|
| 205 | - * @return FileFinder |
|
| 206 | - */ |
|
| 201 | + /** |
|
| 202 | + * In this mode, only the path relative to the source folder |
|
| 203 | + * will be included in the files list. |
|
| 204 | + * |
|
| 205 | + * @return FileFinder |
|
| 206 | + */ |
|
| 207 | 207 | public function setPathmodeRelative() : FileFinder |
| 208 | 208 | { |
| 209 | 209 | return $this->setPathmode(self::PATH_MODE_RELATIVE); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * In this mode, the full, absolute paths to the files will |
|
| 214 | - * be included in the files list. |
|
| 215 | - * |
|
| 216 | - * @return FileFinder |
|
| 217 | - */ |
|
| 212 | + /** |
|
| 213 | + * In this mode, the full, absolute paths to the files will |
|
| 214 | + * be included in the files list. |
|
| 215 | + * |
|
| 216 | + * @return FileFinder |
|
| 217 | + */ |
|
| 218 | 218 | public function setPathmodeAbsolute() : FileFinder |
| 219 | 219 | { |
| 220 | 220 | return $this->setPathmode(self::PATH_MODE_ABSOLUTE); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * This sets a character or string to replace the slashes |
|
| 225 | - * in the paths with. |
|
| 226 | - * |
|
| 227 | - * This is used for example in the `getPHPClassNames()` |
|
| 228 | - * method, to return files from subfolders as class names |
|
| 229 | - * using the "_" character: |
|
| 230 | - * |
|
| 231 | - * Subfolder/To/File.php => Subfolder_To_File.php |
|
| 232 | - * |
|
| 233 | - * @param string $character |
|
| 234 | - * @return FileFinder |
|
| 235 | - */ |
|
| 223 | + /** |
|
| 224 | + * This sets a character or string to replace the slashes |
|
| 225 | + * in the paths with. |
|
| 226 | + * |
|
| 227 | + * This is used for example in the `getPHPClassNames()` |
|
| 228 | + * method, to return files from subfolders as class names |
|
| 229 | + * using the "_" character: |
|
| 230 | + * |
|
| 231 | + * Subfolder/To/File.php => Subfolder_To_File.php |
|
| 232 | + * |
|
| 233 | + * @param string $character |
|
| 234 | + * @return FileFinder |
|
| 235 | + */ |
|
| 236 | 236 | public function setSlashReplacement(string $character) : FileFinder |
| 237 | 237 | { |
| 238 | 238 | return $this->setOption('slash-replacement', $character); |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | return $this->setOption(self::OPTION_PATHMODE, $mode); |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * Retrieves a list of all matching file names/paths, |
|
| 260 | - * depending on the selected options. |
|
| 261 | - * |
|
| 262 | - * @return string[] |
|
| 263 | - */ |
|
| 258 | + /** |
|
| 259 | + * Retrieves a list of all matching file names/paths, |
|
| 260 | + * depending on the selected options. |
|
| 261 | + * |
|
| 262 | + * @return string[] |
|
| 263 | + */ |
|
| 264 | 264 | public function getAll() : array |
| 265 | 265 | { |
| 266 | 266 | $this->find((string)$this->path, true); |
@@ -268,24 +268,24 @@ discard block |
||
| 268 | 268 | return $this->found; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Retrieves only PHP files. Can be combined with other |
|
| 273 | - * options like enabling recursion into sub-folders. |
|
| 274 | - * |
|
| 275 | - * @return string[] |
|
| 276 | - */ |
|
| 271 | + /** |
|
| 272 | + * Retrieves only PHP files. Can be combined with other |
|
| 273 | + * options like enabling recursion into sub-folders. |
|
| 274 | + * |
|
| 275 | + * @return string[] |
|
| 276 | + */ |
|
| 277 | 277 | public function getPHPFiles() : array |
| 278 | 278 | { |
| 279 | 279 | $this->includeExtensions(array('php')); |
| 280 | 280 | return $this->getAll(); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * Generates PHP class names from file paths: it replaces |
|
| 285 | - * slashes with underscores, and removes file extensions. |
|
| 286 | - * |
|
| 287 | - * @return string[] An array of PHP file names without extension. |
|
| 288 | - */ |
|
| 283 | + /** |
|
| 284 | + * Generates PHP class names from file paths: it replaces |
|
| 285 | + * slashes with underscores, and removes file extensions. |
|
| 286 | + * |
|
| 287 | + * @return string[] An array of PHP file names without extension. |
|
| 288 | + */ |
|
| 289 | 289 | public function getPHPClassNames() : array |
| 290 | 290 | { |
| 291 | 291 | $this->includeExtensions(array('php')); |
@@ -356,13 +356,13 @@ discard block |
||
| 356 | 356 | return $path; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - /** |
|
| 360 | - * Checks whether the specified extension is allowed |
|
| 361 | - * with the current settings. |
|
| 362 | - * |
|
| 363 | - * @param string $extension |
|
| 364 | - * @return bool |
|
| 365 | - */ |
|
| 359 | + /** |
|
| 360 | + * Checks whether the specified extension is allowed |
|
| 361 | + * with the current settings. |
|
| 362 | + * |
|
| 363 | + * @param string $extension |
|
| 364 | + * @return bool |
|
| 365 | + */ |
|
| 366 | 366 | protected function filterExclusion(string $extension) : bool |
| 367 | 367 | { |
| 368 | 368 | $include = $this->getOption(self::OPTION_INCLUDE_EXTENSIONS); |
@@ -382,12 +382,12 @@ discard block |
||
| 382 | 382 | return true; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - /** |
|
| 386 | - * Adjusts the path according to the selected path mode. |
|
| 387 | - * |
|
| 388 | - * @param string $path |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 385 | + /** |
|
| 386 | + * Adjusts the path according to the selected path mode. |
|
| 387 | + * |
|
| 388 | + * @param string $path |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | 391 | protected function filterPath(string $path) : string |
| 392 | 392 | { |
| 393 | 393 | switch($this->getStringOption(self::OPTION_PATHMODE)) |
@@ -61,13 +61,13 @@ discard block |
||
| 61 | 61 | return ConvertHelper_String::tabs2spaces($string, $tabSize); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Converts spaces to tabs in the specified string. |
|
| 66 | - * |
|
| 67 | - * @param string $string |
|
| 68 | - * @param int $tabSize The amount of spaces per tab in the source string. |
|
| 69 | - * @return string |
|
| 70 | - */ |
|
| 64 | + /** |
|
| 65 | + * Converts spaces to tabs in the specified string. |
|
| 66 | + * |
|
| 67 | + * @param string $string |
|
| 68 | + * @param int $tabSize The amount of spaces per tab in the source string. |
|
| 69 | + * @return string |
|
| 70 | + */ |
|
| 71 | 71 | public static function spaces2tabs(string $string, int $tabSize=4) : string |
| 72 | 72 | { |
| 73 | 73 | return ConvertHelper_String::spaces2tabs($string, $tabSize); |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | return ConvertHelper_String::hidden2visible($string); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Converts the specified amount of seconds into |
|
| 90 | - * a human-readable string split in months, weeks, |
|
| 91 | - * days, hours, minutes and seconds. |
|
| 92 | - * |
|
| 93 | - * @param float $seconds |
|
| 94 | - * @return string |
|
| 95 | - */ |
|
| 88 | + /** |
|
| 89 | + * Converts the specified amount of seconds into |
|
| 90 | + * a human-readable string split in months, weeks, |
|
| 91 | + * days, hours, minutes and seconds. |
|
| 92 | + * |
|
| 93 | + * @param float $seconds |
|
| 94 | + * @return string |
|
| 95 | + */ |
|
| 96 | 96 | public static function time2string($seconds) : string |
| 97 | 97 | { |
| 98 | 98 | $converter = new ConvertHelper_TimeConverter($seconds); |
@@ -116,85 +116,85 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public static function duration2string($datefrom, $dateto = -1) : string |
| 118 | 118 | { |
| 119 | - return ConvertHelper_DurationConverter::toString($datefrom, $dateto); |
|
| 119 | + return ConvertHelper_DurationConverter::toString($datefrom, $dateto); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Adds HTML syntax highlighting to the specified SQL string. |
|
| 124 | - * |
|
| 125 | - * @param string $sql |
|
| 126 | - * @return string |
|
| 127 | - * @deprecated Use the Highlighter class directly instead. |
|
| 128 | - * @see Highlighter::sql() |
|
| 129 | - */ |
|
| 122 | + /** |
|
| 123 | + * Adds HTML syntax highlighting to the specified SQL string. |
|
| 124 | + * |
|
| 125 | + * @param string $sql |
|
| 126 | + * @return string |
|
| 127 | + * @deprecated Use the Highlighter class directly instead. |
|
| 128 | + * @see Highlighter::sql() |
|
| 129 | + */ |
|
| 130 | 130 | public static function highlight_sql(string $sql) : string |
| 131 | 131 | { |
| 132 | 132 | return Highlighter::sql($sql); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Adds HTML syntax highlighting to the specified XML code. |
|
| 137 | - * |
|
| 138 | - * @param string $xml The XML to highlight. |
|
| 139 | - * @param bool $formatSource Whether to format the source with indentation to make it readable. |
|
| 140 | - * @return string |
|
| 141 | - * @deprecated Use the Highlighter class directly instead. |
|
| 142 | - * @see Highlighter::xml() |
|
| 143 | - */ |
|
| 135 | + /** |
|
| 136 | + * Adds HTML syntax highlighting to the specified XML code. |
|
| 137 | + * |
|
| 138 | + * @param string $xml The XML to highlight. |
|
| 139 | + * @param bool $formatSource Whether to format the source with indentation to make it readable. |
|
| 140 | + * @return string |
|
| 141 | + * @deprecated Use the Highlighter class directly instead. |
|
| 142 | + * @see Highlighter::xml() |
|
| 143 | + */ |
|
| 144 | 144 | public static function highlight_xml(string $xml, bool $formatSource=false) : string |
| 145 | 145 | { |
| 146 | 146 | return Highlighter::xml($xml, $formatSource); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * @param string $phpCode |
|
| 151 | - * @return string |
|
| 152 | - * @deprecated Use the Highlighter class directly instead. |
|
| 153 | - * @see Highlighter::php() |
|
| 154 | - */ |
|
| 149 | + /** |
|
| 150 | + * @param string $phpCode |
|
| 151 | + * @return string |
|
| 152 | + * @deprecated Use the Highlighter class directly instead. |
|
| 153 | + * @see Highlighter::php() |
|
| 154 | + */ |
|
| 155 | 155 | public static function highlight_php(string $phpCode) : string |
| 156 | 156 | { |
| 157 | 157 | return Highlighter::php($phpCode); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * Converts a number of bytes to a human-readable form, |
|
| 162 | - * e.g. xx Kb / xx Mb / xx Gb |
|
| 163 | - * |
|
| 164 | - * @param int $bytes The amount of bytes to convert. |
|
| 165 | - * @param int $precision The amount of decimals |
|
| 166 | - * @param int $base The base to calculate with: Base 10 is default (=1000 Bytes in a KB), Base 2 is mainly used for Windows memory (=1024 Bytes in a KB). |
|
| 167 | - * @return string |
|
| 168 | - * |
|
| 169 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 170 | - */ |
|
| 160 | + /** |
|
| 161 | + * Converts a number of bytes to a human-readable form, |
|
| 162 | + * e.g. xx Kb / xx Mb / xx Gb |
|
| 163 | + * |
|
| 164 | + * @param int $bytes The amount of bytes to convert. |
|
| 165 | + * @param int $precision The amount of decimals |
|
| 166 | + * @param int $base The base to calculate with: Base 10 is default (=1000 Bytes in a KB), Base 2 is mainly used for Windows memory (=1024 Bytes in a KB). |
|
| 167 | + * @return string |
|
| 168 | + * |
|
| 169 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 170 | + */ |
|
| 171 | 171 | public static function bytes2readable(int $bytes, int $precision = 1, int $base = ConvertHelper_StorageSizeEnum::BASE_10) : string |
| 172 | 172 | { |
| 173 | 173 | return self::parseBytes($bytes)->toString($precision, $base); |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Parses a number of bytes, and creates a converter instance which |
|
| 178 | - * allows doing common operations with it. |
|
| 179 | - * |
|
| 180 | - * @param int $bytes |
|
| 181 | - * @return ConvertHelper_ByteConverter |
|
| 182 | - */ |
|
| 176 | + /** |
|
| 177 | + * Parses a number of bytes, and creates a converter instance which |
|
| 178 | + * allows doing common operations with it. |
|
| 179 | + * |
|
| 180 | + * @param int $bytes |
|
| 181 | + * @return ConvertHelper_ByteConverter |
|
| 182 | + */ |
|
| 183 | 183 | public static function parseBytes(int $bytes) : ConvertHelper_ByteConverter |
| 184 | 184 | { |
| 185 | 185 | return new ConvertHelper_ByteConverter($bytes); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Cuts a text to the specified length if it is longer than the |
|
| 190 | - * target length. Appends a text to signify it has been cut at |
|
| 191 | - * the end of the string. |
|
| 192 | - * |
|
| 193 | - * @param string $text |
|
| 194 | - * @param int $targetLength |
|
| 195 | - * @param string $append |
|
| 196 | - * @return string |
|
| 197 | - */ |
|
| 188 | + /** |
|
| 189 | + * Cuts a text to the specified length if it is longer than the |
|
| 190 | + * target length. Appends a text to signify it has been cut at |
|
| 191 | + * the end of the string. |
|
| 192 | + * |
|
| 193 | + * @param string $text |
|
| 194 | + * @param int $targetLength |
|
| 195 | + * @param string $append |
|
| 196 | + * @return string |
|
| 197 | + */ |
|
| 198 | 198 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
| 199 | 199 | { |
| 200 | 200 | return ConvertHelper_String::cutText($text, $targetLength, $append); |
@@ -218,14 +218,14 @@ discard block |
||
| 218 | 218 | return $info->toString(); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Pretty `print_r`. |
|
| 223 | - * |
|
| 224 | - * @param mixed $var The variable to dump. |
|
| 225 | - * @param bool $return Whether to return the dumped code. |
|
| 226 | - * @param bool $html Whether to style the dump as HTML. |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 221 | + /** |
|
| 222 | + * Pretty `print_r`. |
|
| 223 | + * |
|
| 224 | + * @param mixed $var The variable to dump. |
|
| 225 | + * @param bool $return Whether to return the dumped code. |
|
| 226 | + * @param bool $html Whether to style the dump as HTML. |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | 229 | public static function print_r($var, bool $return=false, bool $html=true) : string |
| 230 | 230 | { |
| 231 | 231 | $result = parseVariable($var)->enableType()->toString(); |
@@ -246,29 +246,29 @@ discard block |
||
| 246 | 246 | return $result; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * Converts a string, number or boolean value to a boolean value. |
|
| 251 | - * |
|
| 252 | - * @param mixed $string |
|
| 253 | - * @throws ConvertHelper_Exception |
|
| 254 | - * @return bool |
|
| 255 | - * |
|
| 256 | - * @see ConvertHelper::ERROR_INVALID_BOOLEAN_STRING |
|
| 257 | - */ |
|
| 249 | + /** |
|
| 250 | + * Converts a string, number or boolean value to a boolean value. |
|
| 251 | + * |
|
| 252 | + * @param mixed $string |
|
| 253 | + * @throws ConvertHelper_Exception |
|
| 254 | + * @return bool |
|
| 255 | + * |
|
| 256 | + * @see ConvertHelper::ERROR_INVALID_BOOLEAN_STRING |
|
| 257 | + */ |
|
| 258 | 258 | public static function string2bool($string) : bool |
| 259 | 259 | { |
| 260 | 260 | return ConvertHelper_Bool::fromString($string); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Whether the specified string is a boolean string or boolean value. |
|
| 265 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 266 | - * |
|
| 267 | - * @param mixed $string |
|
| 268 | - * @return bool |
|
| 269 | - * @deprecated |
|
| 270 | - * @see ConvertHelper::isBoolean() |
|
| 271 | - */ |
|
| 263 | + /** |
|
| 264 | + * Whether the specified string is a boolean string or boolean value. |
|
| 265 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 266 | + * |
|
| 267 | + * @param mixed $string |
|
| 268 | + * @return bool |
|
| 269 | + * @deprecated |
|
| 270 | + * @see ConvertHelper::isBoolean() |
|
| 271 | + */ |
|
| 272 | 272 | public static function isBooleanString($string) : bool |
| 273 | 273 | { |
| 274 | 274 | return self::isBoolean($string); |
@@ -338,36 +338,36 @@ discard block |
||
| 338 | 338 | return ConvertHelper_String::transliterate($string, $spaceChar, $lowercase); |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Retrieves the HEX character codes for all control |
|
| 343 | - * characters that the {@link stripControlCharacters()} |
|
| 344 | - * method will remove. |
|
| 345 | - * |
|
| 346 | - * @return string[] |
|
| 347 | - */ |
|
| 341 | + /** |
|
| 342 | + * Retrieves the HEX character codes for all control |
|
| 343 | + * characters that the {@link stripControlCharacters()} |
|
| 344 | + * method will remove. |
|
| 345 | + * |
|
| 346 | + * @return string[] |
|
| 347 | + */ |
|
| 348 | 348 | public static function getControlCharactersAsHex() : array |
| 349 | 349 | { |
| 350 | 350 | return self::createControlCharacters()->getCharsAsHex(); |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - /** |
|
| 354 | - * Retrieves an array of all control characters that |
|
| 355 | - * the {@link stripControlCharacters()} method will |
|
| 356 | - * remove, as the actual UTF-8 characters. |
|
| 357 | - * |
|
| 358 | - * @return string[] |
|
| 359 | - */ |
|
| 353 | + /** |
|
| 354 | + * Retrieves an array of all control characters that |
|
| 355 | + * the {@link stripControlCharacters()} method will |
|
| 356 | + * remove, as the actual UTF-8 characters. |
|
| 357 | + * |
|
| 358 | + * @return string[] |
|
| 359 | + */ |
|
| 360 | 360 | public static function getControlCharactersAsUTF8() : array |
| 361 | 361 | { |
| 362 | 362 | return self::createControlCharacters()->getCharsAsUTF8(); |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * Retrieves all control characters as JSON encoded |
|
| 367 | - * characters, e.g. "\u200b". |
|
| 368 | - * |
|
| 369 | - * @return string[] |
|
| 370 | - */ |
|
| 365 | + /** |
|
| 366 | + * Retrieves all control characters as JSON encoded |
|
| 367 | + * characters, e.g. "\u200b". |
|
| 368 | + * |
|
| 369 | + * @return string[] |
|
| 370 | + */ |
|
| 371 | 371 | public static function getControlCharactersAsJSON() : array |
| 372 | 372 | { |
| 373 | 373 | return self::createControlCharacters()->getCharsAsJSON(); |
@@ -388,31 +388,31 @@ discard block |
||
| 388 | 388 | return self::createControlCharacters()->stripControlCharacters($string); |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | - /** |
|
| 392 | - * Creates the control characters class, used to |
|
| 393 | - * work with control characters in strings. |
|
| 394 | - * |
|
| 395 | - * @return ConvertHelper_ControlCharacters |
|
| 396 | - */ |
|
| 391 | + /** |
|
| 392 | + * Creates the control characters class, used to |
|
| 393 | + * work with control characters in strings. |
|
| 394 | + * |
|
| 395 | + * @return ConvertHelper_ControlCharacters |
|
| 396 | + */ |
|
| 397 | 397 | public static function createControlCharacters() : ConvertHelper_ControlCharacters |
| 398 | 398 | { |
| 399 | 399 | return new ConvertHelper_ControlCharacters(); |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - /** |
|
| 403 | - * Converts a unicode character to the PHP notation. |
|
| 404 | - * |
|
| 405 | - * Example: |
|
| 406 | - * |
|
| 407 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 408 | - * |
|
| 409 | - * Returns |
|
| 410 | - * |
|
| 411 | - * <pre>\x0</pre> |
|
| 412 | - * |
|
| 413 | - * @param string $unicodeChar |
|
| 414 | - * @return string |
|
| 415 | - */ |
|
| 402 | + /** |
|
| 403 | + * Converts a unicode character to the PHP notation. |
|
| 404 | + * |
|
| 405 | + * Example: |
|
| 406 | + * |
|
| 407 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 408 | + * |
|
| 409 | + * Returns |
|
| 410 | + * |
|
| 411 | + * <pre>\x0</pre> |
|
| 412 | + * |
|
| 413 | + * @param string $unicodeChar |
|
| 414 | + * @return string |
|
| 415 | + */ |
|
| 416 | 416 | public static function unicodeChar2php(string $unicodeChar) : string |
| 417 | 417 | { |
| 418 | 418 | $unicodeChar = json_decode($unicodeChar); |
@@ -526,138 +526,138 @@ discard block |
||
| 526 | 526 | return ConvertHelper_Bool::toStringStrict($boolean, $yesNo); |
| 527 | 527 | } |
| 528 | 528 | |
| 529 | - /** |
|
| 530 | - * Converts an associative array with attribute name > value pairs |
|
| 531 | - * to an attribute string that can be used in an HTML tag. Empty |
|
| 532 | - * attribute values are ignored. |
|
| 533 | - * |
|
| 534 | - * Example: |
|
| 535 | - * |
|
| 536 | - * array2attributeString(array( |
|
| 537 | - * 'id' => 45, |
|
| 538 | - * 'href' => 'http://www.mistralys.com' |
|
| 539 | - * )); |
|
| 540 | - * |
|
| 541 | - * Result: |
|
| 542 | - * |
|
| 543 | - * id="45" href="http://www.mistralys.com" |
|
| 544 | - * |
|
| 545 | - * @param array<string,mixed> $array |
|
| 546 | - * @return string |
|
| 547 | - */ |
|
| 529 | + /** |
|
| 530 | + * Converts an associative array with attribute name > value pairs |
|
| 531 | + * to an attribute string that can be used in an HTML tag. Empty |
|
| 532 | + * attribute values are ignored. |
|
| 533 | + * |
|
| 534 | + * Example: |
|
| 535 | + * |
|
| 536 | + * array2attributeString(array( |
|
| 537 | + * 'id' => 45, |
|
| 538 | + * 'href' => 'http://www.mistralys.com' |
|
| 539 | + * )); |
|
| 540 | + * |
|
| 541 | + * Result: |
|
| 542 | + * |
|
| 543 | + * id="45" href="http://www.mistralys.com" |
|
| 544 | + * |
|
| 545 | + * @param array<string,mixed> $array |
|
| 546 | + * @return string |
|
| 547 | + */ |
|
| 548 | 548 | public static function array2attributeString(array $array) : string |
| 549 | 549 | { |
| 550 | 550 | return ConvertHelper_Array::toAttributeString($array); |
| 551 | 551 | } |
| 552 | 552 | |
| 553 | - /** |
|
| 554 | - * Converts a string, so it can safely be used in a javascript |
|
| 555 | - * statement in an HTML tag: uses single quotes around the string |
|
| 556 | - * and encodes all special characters as needed. |
|
| 557 | - * |
|
| 558 | - * @param string $string |
|
| 559 | - * @return string |
|
| 560 | - * @deprecated Use the JSHelper class instead. |
|
| 561 | - * @see JSHelper::phpVariable2AttributeJS() |
|
| 562 | - */ |
|
| 553 | + /** |
|
| 554 | + * Converts a string, so it can safely be used in a javascript |
|
| 555 | + * statement in an HTML tag: uses single quotes around the string |
|
| 556 | + * and encodes all special characters as needed. |
|
| 557 | + * |
|
| 558 | + * @param string $string |
|
| 559 | + * @return string |
|
| 560 | + * @deprecated Use the JSHelper class instead. |
|
| 561 | + * @see JSHelper::phpVariable2AttributeJS() |
|
| 562 | + */ |
|
| 563 | 563 | public static function string2attributeJS(string $string) : string |
| 564 | 564 | { |
| 565 | 565 | return JSHelper::phpVariable2AttributeJS($string); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - /** |
|
| 569 | - * Checks if the specified string is a boolean value, which |
|
| 570 | - * includes string representations of boolean values, like |
|
| 571 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 572 | - * or <code>false</code>. |
|
| 573 | - * |
|
| 574 | - * @param mixed $value |
|
| 575 | - * @return boolean |
|
| 576 | - */ |
|
| 568 | + /** |
|
| 569 | + * Checks if the specified string is a boolean value, which |
|
| 570 | + * includes string representations of boolean values, like |
|
| 571 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 572 | + * or <code>false</code>. |
|
| 573 | + * |
|
| 574 | + * @param mixed $value |
|
| 575 | + * @return boolean |
|
| 576 | + */ |
|
| 577 | 577 | public static function isBoolean($value) : bool |
| 578 | 578 | { |
| 579 | 579 | return ConvertHelper_Bool::isBoolean($value); |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - /** |
|
| 583 | - * Converts an associative array to an HTML style attribute value string. |
|
| 584 | - * |
|
| 585 | - * @param array<string,mixed> $subject |
|
| 586 | - * @return string |
|
| 587 | - */ |
|
| 582 | + /** |
|
| 583 | + * Converts an associative array to an HTML style attribute value string. |
|
| 584 | + * |
|
| 585 | + * @param array<string,mixed> $subject |
|
| 586 | + * @return string |
|
| 587 | + */ |
|
| 588 | 588 | public static function array2styleString(array $subject) : string |
| 589 | 589 | { |
| 590 | 590 | return ConvertHelper_Array::toStyleString($subject); |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | - /** |
|
| 594 | - * Converts a DateTime object to a timestamp, which |
|
| 595 | - * is PHP 5.2 compatible. |
|
| 596 | - * |
|
| 597 | - * @param DateTime $date |
|
| 598 | - * @return integer |
|
| 599 | - */ |
|
| 593 | + /** |
|
| 594 | + * Converts a DateTime object to a timestamp, which |
|
| 595 | + * is PHP 5.2 compatible. |
|
| 596 | + * |
|
| 597 | + * @param DateTime $date |
|
| 598 | + * @return integer |
|
| 599 | + */ |
|
| 600 | 600 | public static function date2timestamp(DateTime $date) : int |
| 601 | 601 | { |
| 602 | 602 | return ConvertHelper_Date::toTimestamp($date); |
| 603 | 603 | } |
| 604 | 604 | |
| 605 | - /** |
|
| 606 | - * Converts a timestamp into a DateTime instance. |
|
| 607 | - * @param int $timestamp |
|
| 608 | - * @return DateTime |
|
| 609 | - */ |
|
| 605 | + /** |
|
| 606 | + * Converts a timestamp into a DateTime instance. |
|
| 607 | + * @param int $timestamp |
|
| 608 | + * @return DateTime |
|
| 609 | + */ |
|
| 610 | 610 | public static function timestamp2date(int $timestamp) : DateTime |
| 611 | 611 | { |
| 612 | 612 | return ConvertHelper_Date::fromTimestamp($timestamp); |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - /** |
|
| 616 | - * Strips an absolute path to a file within the application |
|
| 617 | - * to make the path relative to the application root path. |
|
| 618 | - * |
|
| 619 | - * @param string $path |
|
| 620 | - * @return string |
|
| 621 | - * |
|
| 622 | - * @see FileHelper::relativizePath() |
|
| 623 | - * @see FileHelper::relativizePathByDepth() |
|
| 624 | - */ |
|
| 615 | + /** |
|
| 616 | + * Strips an absolute path to a file within the application |
|
| 617 | + * to make the path relative to the application root path. |
|
| 618 | + * |
|
| 619 | + * @param string $path |
|
| 620 | + * @return string |
|
| 621 | + * |
|
| 622 | + * @see FileHelper::relativizePath() |
|
| 623 | + * @see FileHelper::relativizePathByDepth() |
|
| 624 | + */ |
|
| 625 | 625 | public static function fileRelativize(string $path) : string |
| 626 | 626 | { |
| 627 | 627 | return FileHelper::relativizePathByDepth($path); |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | /** |
| 631 | - * Converts a PHP regex to a javascript RegExp object statement. |
|
| 632 | - * |
|
| 633 | - * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
| 634 | - * More details are available on its usage there. |
|
| 635 | - * |
|
| 636 | - * @param string $regex A PHP preg regex |
|
| 637 | - * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
| 638 | - * @return string Depending on the specified return type. |
|
| 639 | - * |
|
| 640 | - * @see JSHelper::buildRegexStatement() |
|
| 641 | - */ |
|
| 631 | + * Converts a PHP regex to a javascript RegExp object statement. |
|
| 632 | + * |
|
| 633 | + * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
| 634 | + * More details are available on its usage there. |
|
| 635 | + * |
|
| 636 | + * @param string $regex A PHP preg regex |
|
| 637 | + * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
| 638 | + * @return string Depending on the specified return type. |
|
| 639 | + * |
|
| 640 | + * @see JSHelper::buildRegexStatement() |
|
| 641 | + */ |
|
| 642 | 642 | public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) : string |
| 643 | 643 | { |
| 644 | 644 | return JSHelper::buildRegexStatement($regex, $statementType); |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - /** |
|
| 648 | - * Converts the specified variable to JSON. Works just |
|
| 649 | - * like the native `json_encode` method, except that it |
|
| 650 | - * will trigger an exception on failure, which has the |
|
| 651 | - * json error details included in its developer details. |
|
| 652 | - * |
|
| 653 | - * @param mixed $variable |
|
| 654 | - * @param int $options JSON encode options. |
|
| 655 | - * @param int $depth |
|
| 656 | - * @return string |
|
| 657 | - * |
|
| 658 | - * @throws ConvertHelper_Exception |
|
| 659 | - * @see ConvertHelper::ERROR_JSON_ENCODE_FAILED |
|
| 660 | - */ |
|
| 647 | + /** |
|
| 648 | + * Converts the specified variable to JSON. Works just |
|
| 649 | + * like the native `json_encode` method, except that it |
|
| 650 | + * will trigger an exception on failure, which has the |
|
| 651 | + * json error details included in its developer details. |
|
| 652 | + * |
|
| 653 | + * @param mixed $variable |
|
| 654 | + * @param int $options JSON encode options. |
|
| 655 | + * @param int $depth |
|
| 656 | + * @return string |
|
| 657 | + * |
|
| 658 | + * @throws ConvertHelper_Exception |
|
| 659 | + * @see ConvertHelper::ERROR_JSON_ENCODE_FAILED |
|
| 660 | + */ |
|
| 661 | 661 | public static function var2json($variable, int $options=0, int $depth=512) : string |
| 662 | 662 | { |
| 663 | 663 | $result = json_encode($variable, $options, $depth); |
@@ -692,12 +692,12 @@ discard block |
||
| 692 | 692 | ->toString(); |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | - /** |
|
| 696 | - * Strips all known UTF byte order marks from the specified string. |
|
| 697 | - * |
|
| 698 | - * @param string $string |
|
| 699 | - * @return string |
|
| 700 | - */ |
|
| 695 | + /** |
|
| 696 | + * Strips all known UTF byte order marks from the specified string. |
|
| 697 | + * |
|
| 698 | + * @param string $string |
|
| 699 | + * @return string |
|
| 700 | + */ |
|
| 701 | 701 | public static function stripUTFBom(string $string) : string |
| 702 | 702 | { |
| 703 | 703 | $boms = FileHelper::createUnicodeHandling()->getUTFBOMs(); |
@@ -716,69 +716,69 @@ discard block |
||
| 716 | 716 | return $string; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - /** |
|
| 720 | - * Converts a string to valid utf8, regardless |
|
| 721 | - * of the string's encoding(s). |
|
| 722 | - * |
|
| 723 | - * @param string $string |
|
| 724 | - * @return string |
|
| 725 | - */ |
|
| 719 | + /** |
|
| 720 | + * Converts a string to valid utf8, regardless |
|
| 721 | + * of the string's encoding(s). |
|
| 722 | + * |
|
| 723 | + * @param string $string |
|
| 724 | + * @return string |
|
| 725 | + */ |
|
| 726 | 726 | public static function string2utf8(string $string) : string |
| 727 | 727 | { |
| 728 | 728 | return ConvertHelper_String::toUtf8($string); |
| 729 | 729 | } |
| 730 | 730 | |
| 731 | - /** |
|
| 732 | - * Checks whether the specified string is an ASCII |
|
| 733 | - * string, without any special or UTF8 characters. |
|
| 734 | - * Note: empty strings and NULL are considered ASCII. |
|
| 735 | - * Any variable types other than strings are not. |
|
| 736 | - * |
|
| 737 | - * @param string|float|int|NULL $string |
|
| 738 | - * @return boolean |
|
| 739 | - */ |
|
| 731 | + /** |
|
| 732 | + * Checks whether the specified string is an ASCII |
|
| 733 | + * string, without any special or UTF8 characters. |
|
| 734 | + * Note: empty strings and NULL are considered ASCII. |
|
| 735 | + * Any variable types other than strings are not. |
|
| 736 | + * |
|
| 737 | + * @param string|float|int|NULL $string |
|
| 738 | + * @return boolean |
|
| 739 | + */ |
|
| 740 | 740 | public static function isStringASCII($string) : bool |
| 741 | 741 | { |
| 742 | 742 | return ConvertHelper_String::isASCII(strval($string)); |
| 743 | 743 | } |
| 744 | 744 | |
| 745 | - /** |
|
| 746 | - * Adds HTML syntax highlighting to an URL. |
|
| 747 | - * |
|
| 748 | - * NOTE: Includes the necessary CSS styles. When |
|
| 749 | - * highlighting several URLs in the same page, |
|
| 750 | - * prefer using the `parseURL` function instead. |
|
| 751 | - * |
|
| 752 | - * @param string $url |
|
| 753 | - * @return string |
|
| 754 | - * @deprecated Use the Highlighter class directly instead. |
|
| 755 | - * @see Highlighter |
|
| 756 | - */ |
|
| 745 | + /** |
|
| 746 | + * Adds HTML syntax highlighting to an URL. |
|
| 747 | + * |
|
| 748 | + * NOTE: Includes the necessary CSS styles. When |
|
| 749 | + * highlighting several URLs in the same page, |
|
| 750 | + * prefer using the `parseURL` function instead. |
|
| 751 | + * |
|
| 752 | + * @param string $url |
|
| 753 | + * @return string |
|
| 754 | + * @deprecated Use the Highlighter class directly instead. |
|
| 755 | + * @see Highlighter |
|
| 756 | + */ |
|
| 757 | 757 | public static function highlight_url(string $url) : string |
| 758 | 758 | { |
| 759 | 759 | return Highlighter::url($url); |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - /** |
|
| 763 | - * Calculates a percentage match of the source string with the target string. |
|
| 764 | - * |
|
| 765 | - * Options are: |
|
| 766 | - * |
|
| 767 | - * - maxLevenshtein, default: 10 |
|
| 768 | - * Any levenshtein results above this value are ignored. |
|
| 769 | - * |
|
| 770 | - * - precision, default: 1 |
|
| 771 | - * The precision of the percentage float value |
|
| 772 | - * |
|
| 773 | - * @param string $source |
|
| 774 | - * @param string $target |
|
| 775 | - * @param array<string,mixed> $options |
|
| 776 | - * @return float |
|
| 777 | - * |
|
| 778 | - * @see ConvertHelper_TextComparer |
|
| 779 | - * @see ConvertHelper_TextComparer::OPTION_MAX_LEVENSHTEIN_DISTANCE |
|
| 780 | - * @see ConvertHelper_TextComparer::OPTION_PRECISION |
|
| 781 | - */ |
|
| 762 | + /** |
|
| 763 | + * Calculates a percentage match of the source string with the target string. |
|
| 764 | + * |
|
| 765 | + * Options are: |
|
| 766 | + * |
|
| 767 | + * - maxLevenshtein, default: 10 |
|
| 768 | + * Any levenshtein results above this value are ignored. |
|
| 769 | + * |
|
| 770 | + * - precision, default: 1 |
|
| 771 | + * The precision of the percentage float value |
|
| 772 | + * |
|
| 773 | + * @param string $source |
|
| 774 | + * @param string $target |
|
| 775 | + * @param array<string,mixed> $options |
|
| 776 | + * @return float |
|
| 777 | + * |
|
| 778 | + * @see ConvertHelper_TextComparer |
|
| 779 | + * @see ConvertHelper_TextComparer::OPTION_MAX_LEVENSHTEIN_DISTANCE |
|
| 780 | + * @see ConvertHelper_TextComparer::OPTION_PRECISION |
|
| 781 | + */ |
|
| 782 | 782 | public static function matchString(string $source, string $target, array $options=array()) : float |
| 783 | 783 | { |
| 784 | 784 | return (new ConvertHelper_TextComparer()) |
@@ -786,109 +786,109 @@ discard block |
||
| 786 | 786 | ->match($source, $target); |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | - /** |
|
| 790 | - * Converts a date interval to a human-readable string with |
|
| 791 | - * all necessary time components, e.g. "1 year, 2 months and 4 days". |
|
| 792 | - * |
|
| 793 | - * @param DateInterval $interval |
|
| 794 | - * @return string |
|
| 795 | - * @see ConvertHelper_IntervalConverter |
|
| 796 | - * |
|
| 797 | - * @throws ConvertHelper_Exception |
|
| 798 | - * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
| 799 | - */ |
|
| 789 | + /** |
|
| 790 | + * Converts a date interval to a human-readable string with |
|
| 791 | + * all necessary time components, e.g. "1 year, 2 months and 4 days". |
|
| 792 | + * |
|
| 793 | + * @param DateInterval $interval |
|
| 794 | + * @return string |
|
| 795 | + * @see ConvertHelper_IntervalConverter |
|
| 796 | + * |
|
| 797 | + * @throws ConvertHelper_Exception |
|
| 798 | + * @see ConvertHelper_IntervalConverter::ERROR_MISSING_TRANSLATION |
|
| 799 | + */ |
|
| 800 | 800 | public static function interval2string(DateInterval $interval) : string |
| 801 | 801 | { |
| 802 | 802 | return (new ConvertHelper_IntervalConverter()) |
| 803 | 803 | ->toString($interval); |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - /** |
|
| 807 | - * Converts an interval to its total amount of days. |
|
| 808 | - * @param DateInterval $interval |
|
| 809 | - * @return int |
|
| 810 | - */ |
|
| 806 | + /** |
|
| 807 | + * Converts an interval to its total amount of days. |
|
| 808 | + * @param DateInterval $interval |
|
| 809 | + * @return int |
|
| 810 | + */ |
|
| 811 | 811 | public static function interval2days(DateInterval $interval) : int |
| 812 | 812 | { |
| 813 | 813 | return ConvertHelper_DateInterval::toDays($interval); |
| 814 | 814 | } |
| 815 | 815 | |
| 816 | - /** |
|
| 817 | - * Converts an interval to its total amount of hours. |
|
| 818 | - * @param DateInterval $interval |
|
| 819 | - * @return int |
|
| 820 | - */ |
|
| 816 | + /** |
|
| 817 | + * Converts an interval to its total amount of hours. |
|
| 818 | + * @param DateInterval $interval |
|
| 819 | + * @return int |
|
| 820 | + */ |
|
| 821 | 821 | public static function interval2hours(DateInterval $interval) : int |
| 822 | 822 | { |
| 823 | 823 | return ConvertHelper_DateInterval::toHours($interval); |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | - /** |
|
| 827 | - * Converts an interval to its total amount of minutes. |
|
| 828 | - * @param DateInterval $interval |
|
| 829 | - * @return int |
|
| 830 | - */ |
|
| 826 | + /** |
|
| 827 | + * Converts an interval to its total amount of minutes. |
|
| 828 | + * @param DateInterval $interval |
|
| 829 | + * @return int |
|
| 830 | + */ |
|
| 831 | 831 | public static function interval2minutes(DateInterval $interval) : int |
| 832 | 832 | { |
| 833 | 833 | return ConvertHelper_DateInterval::toMinutes($interval); |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | - /** |
|
| 837 | - * Converts an interval to its total amount of seconds. |
|
| 838 | - * @param DateInterval $interval |
|
| 839 | - * @return int |
|
| 840 | - */ |
|
| 836 | + /** |
|
| 837 | + * Converts an interval to its total amount of seconds. |
|
| 838 | + * @param DateInterval $interval |
|
| 839 | + * @return int |
|
| 840 | + */ |
|
| 841 | 841 | public static function interval2seconds(DateInterval $interval) : int |
| 842 | 842 | { |
| 843 | 843 | return ConvertHelper_DateInterval::toSeconds($interval); |
| 844 | 844 | } |
| 845 | 845 | |
| 846 | - /** |
|
| 847 | - * Calculates the total amount of days / hours / minutes or seconds |
|
| 848 | - * of a date interval object (depending on the specified units), and |
|
| 849 | - * returns the total amount. |
|
| 850 | - * |
|
| 851 | - * @param DateInterval $interval |
|
| 852 | - * @param string $unit What total value to calculate. |
|
| 853 | - * @return integer |
|
| 854 | - * |
|
| 855 | - * @see ConvertHelper::INTERVAL_SECONDS |
|
| 856 | - * @see ConvertHelper::INTERVAL_MINUTES |
|
| 857 | - * @see ConvertHelper::INTERVAL_HOURS |
|
| 858 | - * @see ConvertHelper::INTERVAL_DAYS |
|
| 859 | - */ |
|
| 846 | + /** |
|
| 847 | + * Calculates the total amount of days / hours / minutes or seconds |
|
| 848 | + * of a date interval object (depending on the specified units), and |
|
| 849 | + * returns the total amount. |
|
| 850 | + * |
|
| 851 | + * @param DateInterval $interval |
|
| 852 | + * @param string $unit What total value to calculate. |
|
| 853 | + * @return integer |
|
| 854 | + * |
|
| 855 | + * @see ConvertHelper::INTERVAL_SECONDS |
|
| 856 | + * @see ConvertHelper::INTERVAL_MINUTES |
|
| 857 | + * @see ConvertHelper::INTERVAL_HOURS |
|
| 858 | + * @see ConvertHelper::INTERVAL_DAYS |
|
| 859 | + */ |
|
| 860 | 860 | public static function interval2total(DateInterval $interval, string $unit=self::INTERVAL_SECONDS) : int |
| 861 | 861 | { |
| 862 | 862 | return ConvertHelper_DateInterval::toTotal($interval, $unit); |
| 863 | 863 | } |
| 864 | 864 | |
| 865 | - /** |
|
| 866 | - * Converts a date to the corresponding day name. |
|
| 867 | - * |
|
| 868 | - * @param DateTime $date |
|
| 869 | - * @param bool $short |
|
| 870 | - * @return string|NULL |
|
| 871 | - */ |
|
| 865 | + /** |
|
| 866 | + * Converts a date to the corresponding day name. |
|
| 867 | + * |
|
| 868 | + * @param DateTime $date |
|
| 869 | + * @param bool $short |
|
| 870 | + * @return string|NULL |
|
| 871 | + */ |
|
| 872 | 872 | public static function date2dayName(DateTime $date, bool $short=false) : ?string |
| 873 | 873 | { |
| 874 | 874 | return ConvertHelper_Date::toDayName($date, $short); |
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - /** |
|
| 878 | - * Retrieves a list of english day names. |
|
| 879 | - * @return string[] |
|
| 880 | - */ |
|
| 877 | + /** |
|
| 878 | + * Retrieves a list of english day names. |
|
| 879 | + * @return string[] |
|
| 880 | + */ |
|
| 881 | 881 | public static function getDayNamesInvariant() : array |
| 882 | 882 | { |
| 883 | 883 | return ConvertHelper_Date::getDayNamesInvariant(); |
| 884 | 884 | } |
| 885 | 885 | |
| 886 | - /** |
|
| 887 | - * Retrieves the day names list for the current locale. |
|
| 888 | - * |
|
| 889 | - * @param bool $short |
|
| 890 | - * @return string[] |
|
| 891 | - */ |
|
| 886 | + /** |
|
| 887 | + * Retrieves the day names list for the current locale. |
|
| 888 | + * |
|
| 889 | + * @param bool $short |
|
| 890 | + * @return string[] |
|
| 891 | + */ |
|
| 892 | 892 | public static function getDayNames(bool $short=false) : array |
| 893 | 893 | { |
| 894 | 894 | return ConvertHelper_Date::getDayNames($short); |
@@ -907,16 +907,16 @@ discard block |
||
| 907 | 907 | return ConvertHelper_Array::implodeWithAnd($list, $sep, $conjunction); |
| 908 | 908 | } |
| 909 | 909 | |
| 910 | - /** |
|
| 911 | - * Splits a string into an array of all characters it is composed of. |
|
| 912 | - * Unicode character safe. |
|
| 913 | - * |
|
| 914 | - * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 915 | - * characters. |
|
| 916 | - * |
|
| 917 | - * @param string $string |
|
| 918 | - * @return string[] |
|
| 919 | - */ |
|
| 910 | + /** |
|
| 911 | + * Splits a string into an array of all characters it is composed of. |
|
| 912 | + * Unicode character safe. |
|
| 913 | + * |
|
| 914 | + * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 915 | + * characters. |
|
| 916 | + * |
|
| 917 | + * @param string $string |
|
| 918 | + * @return string[] |
|
| 919 | + */ |
|
| 920 | 920 | public static function string2array(string $string) : array |
| 921 | 921 | { |
| 922 | 922 | return ConvertHelper_String::toArray($string); |
@@ -927,53 +927,53 @@ discard block |
||
| 927 | 927 | return new WordSplitter($string); |
| 928 | 928 | } |
| 929 | 929 | |
| 930 | - /** |
|
| 931 | - * Checks whether the specified string contains HTML code. |
|
| 932 | - * |
|
| 933 | - * @param string $string |
|
| 934 | - * @return boolean |
|
| 935 | - */ |
|
| 930 | + /** |
|
| 931 | + * Checks whether the specified string contains HTML code. |
|
| 932 | + * |
|
| 933 | + * @param string $string |
|
| 934 | + * @return boolean |
|
| 935 | + */ |
|
| 936 | 936 | public static function isStringHTML(string $string) : bool |
| 937 | 937 | { |
| 938 | 938 | return ConvertHelper_String::isHTML($string); |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | - /** |
|
| 942 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 943 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 944 | - * are not calculated correctly. |
|
| 945 | - * |
|
| 946 | - * @param string $str |
|
| 947 | - * @param int $width |
|
| 948 | - * @param string $break |
|
| 949 | - * @param bool $cut |
|
| 950 | - * @return string |
|
| 951 | - */ |
|
| 941 | + /** |
|
| 942 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 943 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 944 | + * are not calculated correctly. |
|
| 945 | + * |
|
| 946 | + * @param string $str |
|
| 947 | + * @param int $width |
|
| 948 | + * @param string $break |
|
| 949 | + * @param bool $cut |
|
| 950 | + * @return string |
|
| 951 | + */ |
|
| 952 | 952 | public static function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false) : string |
| 953 | 953 | { |
| 954 | 954 | return ConvertHelper_String::wordwrap($str, $width, $break, $cut); |
| 955 | 955 | } |
| 956 | 956 | |
| 957 | - /** |
|
| 958 | - * Calculates the byte length of a string, taking into |
|
| 959 | - * account any unicode characters. |
|
| 960 | - * |
|
| 961 | - * @param string $string |
|
| 962 | - * @return int |
|
| 963 | - */ |
|
| 957 | + /** |
|
| 958 | + * Calculates the byte length of a string, taking into |
|
| 959 | + * account any unicode characters. |
|
| 960 | + * |
|
| 961 | + * @param string $string |
|
| 962 | + * @return int |
|
| 963 | + */ |
|
| 964 | 964 | public static function string2bytes(string $string): int |
| 965 | 965 | { |
| 966 | 966 | return ConvertHelper_String::toBytes($string); |
| 967 | 967 | } |
| 968 | 968 | |
| 969 | - /** |
|
| 970 | - * Creates a short, 8-character long hash for the specified string. |
|
| 971 | - * |
|
| 972 | - * WARNING: Not cryptographically safe. |
|
| 973 | - * |
|
| 974 | - * @param string $string |
|
| 975 | - * @return string |
|
| 976 | - */ |
|
| 969 | + /** |
|
| 970 | + * Creates a short, 8-character long hash for the specified string. |
|
| 971 | + * |
|
| 972 | + * WARNING: Not cryptographically safe. |
|
| 973 | + * |
|
| 974 | + * @param string $string |
|
| 975 | + * @return string |
|
| 976 | + */ |
|
| 977 | 977 | public static function string2shortHash(string $string) : string |
| 978 | 978 | { |
| 979 | 979 | return ConvertHelper_String::toShortHash($string); |
@@ -1019,88 +1019,88 @@ discard block |
||
| 1019 | 1019 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | - /** |
|
| 1023 | - * Parses the specified query string like the native |
|
| 1024 | - * function <code>parse_str</code>, without the key |
|
| 1025 | - * naming limitations. |
|
| 1026 | - * |
|
| 1027 | - * Using parse_str, dots or spaces in key names are |
|
| 1028 | - * replaced by underscores. This method keeps all names |
|
| 1029 | - * intact. |
|
| 1030 | - * |
|
| 1031 | - * It still uses the parse_str implementation as it |
|
| 1032 | - * is tested and tried, but fixes the parameter names |
|
| 1033 | - * after parsing, as needed. |
|
| 1034 | - * |
|
| 1035 | - * @param string $queryString |
|
| 1036 | - * @return array<string,string> |
|
| 1037 | - * @see ConvertHelper_QueryParser |
|
| 1038 | - */ |
|
| 1022 | + /** |
|
| 1023 | + * Parses the specified query string like the native |
|
| 1024 | + * function <code>parse_str</code>, without the key |
|
| 1025 | + * naming limitations. |
|
| 1026 | + * |
|
| 1027 | + * Using parse_str, dots or spaces in key names are |
|
| 1028 | + * replaced by underscores. This method keeps all names |
|
| 1029 | + * intact. |
|
| 1030 | + * |
|
| 1031 | + * It still uses the parse_str implementation as it |
|
| 1032 | + * is tested and tried, but fixes the parameter names |
|
| 1033 | + * after parsing, as needed. |
|
| 1034 | + * |
|
| 1035 | + * @param string $queryString |
|
| 1036 | + * @return array<string,string> |
|
| 1037 | + * @see ConvertHelper_QueryParser |
|
| 1038 | + */ |
|
| 1039 | 1039 | public static function parseQueryString(string $queryString) : array |
| 1040 | 1040 | { |
| 1041 | 1041 | $parser = new ConvertHelper_QueryParser(); |
| 1042 | 1042 | return $parser->parse($queryString); |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | - /** |
|
| 1046 | - * Searches for needle in the specified string, and returns a list |
|
| 1047 | - * of all occurrences, including the matched string. The matched |
|
| 1048 | - * string is useful when doing a case-insensitive search, as it |
|
| 1049 | - * shows the exact matched case of needle. |
|
| 1050 | - * |
|
| 1051 | - * @param string $needle |
|
| 1052 | - * @param string $haystack |
|
| 1053 | - * @param bool $caseInsensitive |
|
| 1054 | - * @return ConvertHelper_StringMatch[] |
|
| 1055 | - */ |
|
| 1045 | + /** |
|
| 1046 | + * Searches for needle in the specified string, and returns a list |
|
| 1047 | + * of all occurrences, including the matched string. The matched |
|
| 1048 | + * string is useful when doing a case-insensitive search, as it |
|
| 1049 | + * shows the exact matched case of needle. |
|
| 1050 | + * |
|
| 1051 | + * @param string $needle |
|
| 1052 | + * @param string $haystack |
|
| 1053 | + * @param bool $caseInsensitive |
|
| 1054 | + * @return ConvertHelper_StringMatch[] |
|
| 1055 | + */ |
|
| 1056 | 1056 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false): array |
| 1057 | 1057 | { |
| 1058 | 1058 | return ConvertHelper_String::findString($needle, $haystack, $caseInsensitive); |
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | - /** |
|
| 1062 | - * Like explode, but trims all entries, and removes |
|
| 1063 | - * empty entries from the resulting array. |
|
| 1064 | - * |
|
| 1065 | - * @param string $delimiter |
|
| 1066 | - * @param string $string |
|
| 1067 | - * @return string[] |
|
| 1068 | - */ |
|
| 1061 | + /** |
|
| 1062 | + * Like explode, but trims all entries, and removes |
|
| 1063 | + * empty entries from the resulting array. |
|
| 1064 | + * |
|
| 1065 | + * @param string $delimiter |
|
| 1066 | + * @param string $string |
|
| 1067 | + * @return string[] |
|
| 1068 | + */ |
|
| 1069 | 1069 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1070 | 1070 | { |
| 1071 | 1071 | return ConvertHelper_String::explodeTrim($delimiter, $string); |
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | - /** |
|
| 1075 | - * Detects the most used end-of-line character in the subject string. |
|
| 1076 | - * |
|
| 1077 | - * @param string $subjectString The string to check. |
|
| 1078 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1079 | - */ |
|
| 1074 | + /** |
|
| 1075 | + * Detects the most used end-of-line character in the subject string. |
|
| 1076 | + * |
|
| 1077 | + * @param string $subjectString The string to check. |
|
| 1078 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1079 | + */ |
|
| 1080 | 1080 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1081 | 1081 | { |
| 1082 | 1082 | return ConvertHelper_EOL::detect($subjectString); |
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | - /** |
|
| 1086 | - * Removes the specified keys from the target array, |
|
| 1087 | - * if they exist. |
|
| 1088 | - * |
|
| 1089 | - * @param array<string|int,mixed> $array |
|
| 1090 | - * @param string[] $keys |
|
| 1091 | - */ |
|
| 1085 | + /** |
|
| 1086 | + * Removes the specified keys from the target array, |
|
| 1087 | + * if they exist. |
|
| 1088 | + * |
|
| 1089 | + * @param array<string|int,mixed> $array |
|
| 1090 | + * @param string[] $keys |
|
| 1091 | + */ |
|
| 1092 | 1092 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1093 | 1093 | { |
| 1094 | 1094 | ConvertHelper_Array::removeKeys($array, $keys); |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | - /** |
|
| 1098 | - * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1099 | - * Accepts both positive and negative integers. |
|
| 1100 | - * |
|
| 1101 | - * @param mixed $value |
|
| 1102 | - * @return bool |
|
| 1103 | - */ |
|
| 1097 | + /** |
|
| 1098 | + * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1099 | + * Accepts both positive and negative integers. |
|
| 1100 | + * |
|
| 1101 | + * @param mixed $value |
|
| 1102 | + * @return bool |
|
| 1103 | + */ |
|
| 1104 | 1104 | public static function isInteger($value) : bool |
| 1105 | 1105 | { |
| 1106 | 1106 | if(is_int($value)) { |
@@ -1120,52 +1120,52 @@ discard block |
||
| 1120 | 1120 | return false; |
| 1121 | 1121 | } |
| 1122 | 1122 | |
| 1123 | - /** |
|
| 1124 | - * Converts an amount of seconds to a DateInterval object. |
|
| 1125 | - * |
|
| 1126 | - * @param int $seconds |
|
| 1127 | - * @return DateInterval |
|
| 1128 | - * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
| 1129 | - * |
|
| 1130 | - * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
| 1131 | - */ |
|
| 1123 | + /** |
|
| 1124 | + * Converts an amount of seconds to a DateInterval object. |
|
| 1125 | + * |
|
| 1126 | + * @param int $seconds |
|
| 1127 | + * @return DateInterval |
|
| 1128 | + * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
| 1129 | + * |
|
| 1130 | + * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
| 1131 | + */ |
|
| 1132 | 1132 | public static function seconds2interval(int $seconds) : DateInterval |
| 1133 | 1133 | { |
| 1134 | 1134 | return ConvertHelper_DateInterval::fromSeconds($seconds)->getInterval(); |
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | - /** |
|
| 1138 | - * Converts a size string like "50 MB" to the corresponding byte size. |
|
| 1139 | - * It is case-insensitive, ignores spaces, and supports both traditional |
|
| 1140 | - * "MB" and "MiB" notations. |
|
| 1141 | - * |
|
| 1142 | - * @param string $size |
|
| 1143 | - * @return int |
|
| 1144 | - */ |
|
| 1137 | + /** |
|
| 1138 | + * Converts a size string like "50 MB" to the corresponding byte size. |
|
| 1139 | + * It is case-insensitive, ignores spaces, and supports both traditional |
|
| 1140 | + * "MB" and "MiB" notations. |
|
| 1141 | + * |
|
| 1142 | + * @param string $size |
|
| 1143 | + * @return int |
|
| 1144 | + */ |
|
| 1145 | 1145 | public static function size2bytes(string $size) : int |
| 1146 | 1146 | { |
| 1147 | 1147 | return self::parseSize($size)->toBytes(); |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - /** |
|
| 1151 | - * Parses a size string like "50 MB" and returns a size notation instance |
|
| 1152 | - * that has utility methods to access information on it, and convert it. |
|
| 1153 | - * |
|
| 1154 | - * @param string $size |
|
| 1155 | - * @return ConvertHelper_SizeNotation |
|
| 1156 | - */ |
|
| 1150 | + /** |
|
| 1151 | + * Parses a size string like "50 MB" and returns a size notation instance |
|
| 1152 | + * that has utility methods to access information on it, and convert it. |
|
| 1153 | + * |
|
| 1154 | + * @param string $size |
|
| 1155 | + * @return ConvertHelper_SizeNotation |
|
| 1156 | + */ |
|
| 1157 | 1157 | public static function parseSize(string $size) : ConvertHelper_SizeNotation |
| 1158 | 1158 | { |
| 1159 | 1159 | return new ConvertHelper_SizeNotation($size); |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | - /** |
|
| 1163 | - * Creates a URL finder instance, which can be used to find |
|
| 1164 | - * URLs in a string - be it plain text, or HTML. |
|
| 1165 | - * |
|
| 1166 | - * @param string $subject |
|
| 1167 | - * @return ConvertHelper_URLFinder |
|
| 1168 | - */ |
|
| 1162 | + /** |
|
| 1163 | + * Creates a URL finder instance, which can be used to find |
|
| 1164 | + * URLs in a string - be it plain text, or HTML. |
|
| 1165 | + * |
|
| 1166 | + * @param string $subject |
|
| 1167 | + * @return ConvertHelper_URLFinder |
|
| 1168 | + */ |
|
| 1169 | 1169 | public static function createURLFinder(string $subject) : ConvertHelper_URLFinder |
| 1170 | 1170 | { |
| 1171 | 1171 | return new ConvertHelper_URLFinder($subject); |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | protected ?string $details = null; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param string $message |
|
| 30 | - * @param string|NULL $details |
|
| 31 | - * @param int|NULL $code |
|
| 32 | - * @param Throwable|NULL $previous |
|
| 33 | - */ |
|
| 28 | + /** |
|
| 29 | + * @param string $message |
|
| 30 | + * @param string|NULL $details |
|
| 31 | + * @param int|NULL $code |
|
| 32 | + * @param Throwable|NULL $previous |
|
| 33 | + */ |
|
| 34 | 34 | public function __construct(string $message, ?string $details=null, ?int $code=null, ?Throwable $previous=null) |
| 35 | 35 | { |
| 36 | 36 | if(defined('APP_UTILS_TESTSUITE') && APP_UTILS_TESTSUITE === 'true') |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | if($code === null) |
| 42 | 42 | { |
| 43 | - $code = 0; |
|
| 43 | + $code = 0; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | parent::__construct($message, (int)$code, $previous); |
@@ -48,18 +48,18 @@ discard block |
||
| 48 | 48 | $this->details = $details; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Retrieves the detailed error description, if any. |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 51 | + /** |
|
| 52 | + * Retrieves the detailed error description, if any. |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | 55 | public function getDetails() : string |
| 56 | 56 | { |
| 57 | 57 | return $this->details ?? ''; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Displays pertinent information on the exception. |
|
| 62 | - */ |
|
| 60 | + /** |
|
| 61 | + * Displays pertinent information on the exception. |
|
| 62 | + */ |
|
| 63 | 63 | public function display() : void |
| 64 | 64 | { |
| 65 | 65 | if(!headers_sent()) { |
@@ -69,20 +69,20 @@ discard block |
||
| 69 | 69 | echo $this->getInfo(); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Retrieves information on the exception that can be |
|
| 74 | - * easily accessed. |
|
| 75 | - * |
|
| 76 | - * @return ConvertHelper_ThrowableInfo |
|
| 77 | - */ |
|
| 72 | + /** |
|
| 73 | + * Retrieves information on the exception that can be |
|
| 74 | + * easily accessed. |
|
| 75 | + * |
|
| 76 | + * @return ConvertHelper_ThrowableInfo |
|
| 77 | + */ |
|
| 78 | 78 | public function getInfo() : ConvertHelper_ThrowableInfo |
| 79 | 79 | { |
| 80 | 80 | return ConvertHelper::throwable2info($this); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Dumps a current PHP function trace, as a text only string. |
|
| 85 | - */ |
|
| 83 | + /** |
|
| 84 | + * Dumps a current PHP function trace, as a text only string. |
|
| 85 | + */ |
|
| 86 | 86 | public static function dumpTraceAsString() : void |
| 87 | 87 | { |
| 88 | 88 | try |
@@ -95,9 +95,9 @@ discard block |
||
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Dumps a current PHP function trace, with HTML styling. |
|
| 100 | - */ |
|
| 98 | + /** |
|
| 99 | + * Dumps a current PHP function trace, with HTML styling. |
|
| 100 | + */ |
|
| 101 | 101 | public static function dumpTraceAsHTML() : void |
| 102 | 102 | { |
| 103 | 103 | try |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Creates an exception info instance from a throwable instance. |
|
| 117 | - * |
|
| 118 | - * @param Throwable $e |
|
| 119 | - * @return ConvertHelper_ThrowableInfo |
|
| 120 | - * @see ConvertHelper::throwable2info() |
|
| 121 | - */ |
|
| 115 | + /** |
|
| 116 | + * Creates an exception info instance from a throwable instance. |
|
| 117 | + * |
|
| 118 | + * @param Throwable $e |
|
| 119 | + * @return ConvertHelper_ThrowableInfo |
|
| 120 | + * @see ConvertHelper::throwable2info() |
|
| 121 | + */ |
|
| 122 | 122 | public static function createInfo(Throwable $e) : ConvertHelper_ThrowableInfo |
| 123 | 123 | { |
| 124 | 124 | return ConvertHelper::throwable2info($e); |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | self::TYPE_TRAIT |
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param PHPFile $path The path to the PHP file to parse. |
|
| 53 | - * @throws FileHelper_Exception |
|
| 54 | - * @see FileHelper::findPHPClasses() |
|
| 55 | - */ |
|
| 51 | + /** |
|
| 52 | + * @param PHPFile $path The path to the PHP file to parse. |
|
| 53 | + * @throws FileHelper_Exception |
|
| 54 | + * @see FileHelper::findPHPClasses() |
|
| 55 | + */ |
|
| 56 | 56 | public function __construct(PHPFile $path) |
| 57 | 57 | { |
| 58 | 58 | $this->file = $path |
@@ -62,58 +62,58 @@ discard block |
||
| 62 | 62 | $this->parseFile(); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * The name of the namespace of the classes in the file, if any. |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 65 | + /** |
|
| 66 | + * The name of the namespace of the classes in the file, if any. |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | 69 | public function getNamespace() : string |
| 70 | 70 | { |
| 71 | 71 | return $this->namespace; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Whether the file contains a namespace. |
|
| 76 | - * @return bool |
|
| 77 | - */ |
|
| 74 | + /** |
|
| 75 | + * Whether the file contains a namespace. |
|
| 76 | + * @return bool |
|
| 77 | + */ |
|
| 78 | 78 | public function hasNamespace() : bool |
| 79 | 79 | { |
| 80 | 80 | return !empty($this->namespace); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * The absolute path to the file. |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 83 | + /** |
|
| 84 | + * The absolute path to the file. |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | 87 | public function getPath() : string |
| 88 | 88 | { |
| 89 | 89 | return $this->file->getPath(); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Whether any classes were found in the file. |
|
| 94 | - * @return bool |
|
| 95 | - */ |
|
| 92 | + /** |
|
| 93 | + * Whether any classes were found in the file. |
|
| 94 | + * @return bool |
|
| 95 | + */ |
|
| 96 | 96 | public function hasClasses() : bool |
| 97 | 97 | { |
| 98 | 98 | return !empty($this->classes); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * The names of the classes that were found in the file (with namespace if any). |
|
| 103 | - * @return string[] |
|
| 104 | - */ |
|
| 101 | + /** |
|
| 102 | + * The names of the classes that were found in the file (with namespace if any). |
|
| 103 | + * @return string[] |
|
| 104 | + */ |
|
| 105 | 105 | public function getClassNames() : array |
| 106 | 106 | { |
| 107 | 107 | return array_keys($this->classes); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Retrieves all classes that were detected in the file, |
|
| 112 | - * which can be used to retrieve more information about |
|
| 113 | - * them. |
|
| 114 | - * |
|
| 115 | - * @return FileHelper_PHPClassInfo_Class[] |
|
| 116 | - */ |
|
| 110 | + /** |
|
| 111 | + * Retrieves all classes that were detected in the file, |
|
| 112 | + * which can be used to retrieve more information about |
|
| 113 | + * them. |
|
| 114 | + * |
|
| 115 | + * @return FileHelper_PHPClassInfo_Class[] |
|
| 116 | + */ |
|
| 117 | 117 | public function getClasses() : array |
| 118 | 118 | { |
| 119 | 119 | return array_values($this->classes); |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | $this->classes[$class->getNameNS()] = $class; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Strips all whitespace from the string, replacing it with |
|
| 190 | - * regular spaces (newlines, tabs, etc.). |
|
| 191 | - * |
|
| 192 | - * @param string $string |
|
| 193 | - * @return string |
|
| 194 | - */ |
|
| 188 | + /** |
|
| 189 | + * Strips all whitespace from the string, replacing it with |
|
| 190 | + * regular spaces (newlines, tabs, etc.). |
|
| 191 | + * |
|
| 192 | + * @param string $string |
|
| 193 | + * @return string |
|
| 194 | + */ |
|
| 195 | 195 | protected function stripWhitespace(string $string) : string |
| 196 | 196 | { |
| 197 | 197 | return preg_replace('/\s/', ' ', $string); |
@@ -33,22 +33,22 @@ discard block |
||
| 33 | 33 | $this->parse(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Retrieves an indexed array with accept mime types |
|
| 38 | - * that the client sent, in the order of preference |
|
| 39 | - * the client specified. |
|
| 40 | - * |
|
| 41 | - * Example: |
|
| 42 | - * |
|
| 43 | - * array( |
|
| 44 | - * 'text/html', |
|
| 45 | - * 'application/xhtml+xml', |
|
| 46 | - * 'image/webp' |
|
| 47 | - * ... |
|
| 48 | - * ) |
|
| 49 | - * |
|
| 50 | - * @return string[] |
|
| 51 | - */ |
|
| 36 | + /** |
|
| 37 | + * Retrieves an indexed array with accept mime types |
|
| 38 | + * that the client sent, in the order of preference |
|
| 39 | + * the client specified. |
|
| 40 | + * |
|
| 41 | + * Example: |
|
| 42 | + * |
|
| 43 | + * array( |
|
| 44 | + * 'text/html', |
|
| 45 | + * 'application/xhtml+xml', |
|
| 46 | + * 'image/webp' |
|
| 47 | + * ... |
|
| 48 | + * ) |
|
| 49 | + * |
|
| 50 | + * @return string[] |
|
| 51 | + */ |
|
| 52 | 52 | public function getMimeStrings() : array |
| 53 | 53 | { |
| 54 | 54 | $result = array(); |
@@ -61,9 +61,9 @@ discard block |
||
| 61 | 61 | return $result; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Checks that an "Accept" header string exists, and tries to parse it. |
|
| 66 | - */ |
|
| 64 | + /** |
|
| 65 | + * Checks that an "Accept" header string exists, and tries to parse it. |
|
| 66 | + */ |
|
| 67 | 67 | protected function parse() : void |
| 68 | 68 | { |
| 69 | 69 | // we may be in a CLI environment where the headers |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | $this->headers = $this->parseHeader($_SERVER['HTTP_ACCEPT']); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Splits the "Accept" header string and parses the mime types. |
|
| 80 | - * |
|
| 81 | - * @param string $acceptHeader |
|
| 82 | - * @return AcceptHeader[] |
|
| 83 | - */ |
|
| 78 | + /** |
|
| 79 | + * Splits the "Accept" header string and parses the mime types. |
|
| 80 | + * |
|
| 81 | + * @param string $acceptHeader |
|
| 82 | + * @return AcceptHeader[] |
|
| 83 | + */ |
|
| 84 | 84 | protected function parseHeader(string $acceptHeader) : array |
| 85 | 85 | { |
| 86 | 86 | $tokens = preg_split('/\s*,\s*/', $acceptHeader); |
@@ -97,13 +97,13 @@ discard block |
||
| 97 | 97 | return $accept; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Parses a single mime type entry. |
|
| 102 | - * |
|
| 103 | - * @param int $i The position in the "Accept" string |
|
| 104 | - * @param string $mime The mime type |
|
| 105 | - * @return AcceptHeader |
|
| 106 | - */ |
|
| 100 | + /** |
|
| 101 | + * Parses a single mime type entry. |
|
| 102 | + * |
|
| 103 | + * @param int $i The position in the "Accept" string |
|
| 104 | + * @param string $mime The mime type |
|
| 105 | + * @return AcceptHeader |
|
| 106 | + */ |
|
| 107 | 107 | protected function parseEntry(int $i, string $mime) : AcceptHeader |
| 108 | 108 | { |
| 109 | 109 | $quality = 0; |