@@ -23,24 +23,24 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class URLInfo_Parser |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | 29 | protected $url; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var bool |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var bool |
|
| 33 | + */ |
|
| 34 | 34 | protected $isValid = false; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 36 | + /** |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | 39 | protected $info; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var array|NULL |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var array|NULL |
|
| 43 | + */ |
|
| 44 | 44 | protected $error; |
| 45 | 45 | |
| 46 | 46 | /** |
@@ -56,25 +56,25 @@ discard block |
||
| 56 | 56 | 'file' |
| 57 | 57 | ); |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Stores a list of all unicode characters in the URL |
|
| 61 | - * that have been filtered out before parsing it with |
|
| 62 | - * parse_url. |
|
| 63 | - * |
|
| 64 | - * @var string[]string |
|
| 65 | - */ |
|
| 59 | + /** |
|
| 60 | + * Stores a list of all unicode characters in the URL |
|
| 61 | + * that have been filtered out before parsing it with |
|
| 62 | + * parse_url. |
|
| 63 | + * |
|
| 64 | + * @var string[]string |
|
| 65 | + */ |
|
| 66 | 66 | protected $unicodeChars = array(); |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @var bool |
|
| 70 | - */ |
|
| 68 | + /** |
|
| 69 | + * @var bool |
|
| 70 | + */ |
|
| 71 | 71 | protected $encodeUTF = false; |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * |
|
| 75 | - * @param string $url The target URL. |
|
| 76 | - * @param bool $encodeUTF Whether to URL encode any plain text unicode characters. |
|
| 77 | - */ |
|
| 73 | + /** |
|
| 74 | + * |
|
| 75 | + * @param string $url The target URL. |
|
| 76 | + * @param bool $encodeUTF Whether to URL encode any plain text unicode characters. |
|
| 77 | + */ |
|
| 78 | 78 | public function __construct(string $url, bool $encodeUTF) |
| 79 | 79 | { |
| 80 | 80 | $this->url = $url; |
@@ -87,12 +87,12 @@ discard block |
||
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Retrieves the array as parsed by PHP's parse_url, |
|
| 92 | - * filtered and adjusted as necessary. |
|
| 93 | - * |
|
| 94 | - * @return array |
|
| 95 | - */ |
|
| 90 | + /** |
|
| 91 | + * Retrieves the array as parsed by PHP's parse_url, |
|
| 92 | + * filtered and adjusted as necessary. |
|
| 93 | + * |
|
| 94 | + * @return array |
|
| 95 | + */ |
|
| 96 | 96 | public function getInfo() : array |
| 97 | 97 | { |
| 98 | 98 | return $this->info; |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Finds any non-url encoded unicode characters in |
|
| 119 | - * the URL, and encodes them before the URL is |
|
| 120 | - * passed to parse_url. |
|
| 121 | - */ |
|
| 117 | + /** |
|
| 118 | + * Finds any non-url encoded unicode characters in |
|
| 119 | + * the URL, and encodes them before the URL is |
|
| 120 | + * passed to parse_url. |
|
| 121 | + */ |
|
| 122 | 122 | protected function filterUnicodeChars() : void |
| 123 | 123 | { |
| 124 | 124 | $chars = \AppUtils\ConvertHelper::string2array($this->url); |
@@ -236,11 +236,11 @@ discard block |
||
| 236 | 236 | return false; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Goes through all information in the parse_url result |
|
| 241 | - * array, and attempts to fix any user errors in formatting |
|
| 242 | - * that can be recovered from, mostly regarding stray spaces. |
|
| 243 | - */ |
|
| 239 | + /** |
|
| 240 | + * Goes through all information in the parse_url result |
|
| 241 | + * array, and attempts to fix any user errors in formatting |
|
| 242 | + * that can be recovered from, mostly regarding stray spaces. |
|
| 243 | + */ |
|
| 244 | 244 | protected function filterParsed() |
| 245 | 245 | { |
| 246 | 246 | $this->info['params'] = array(); |
@@ -269,13 +269,13 @@ discard block |
||
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Recursively goes through the array, and converts all previously |
|
| 274 | - * URL encoded characters with their unicode character counterparts. |
|
| 275 | - * |
|
| 276 | - * @param array $subject |
|
| 277 | - * @return array |
|
| 278 | - */ |
|
| 272 | + /** |
|
| 273 | + * Recursively goes through the array, and converts all previously |
|
| 274 | + * URL encoded characters with their unicode character counterparts. |
|
| 275 | + * |
|
| 276 | + * @param array $subject |
|
| 277 | + * @return array |
|
| 278 | + */ |
|
| 279 | 279 | protected function restoreUnicodeChars(array $subject) : array |
| 280 | 280 | { |
| 281 | 281 | $result = array(); |
@@ -299,13 +299,13 @@ discard block |
||
| 299 | 299 | return $result; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - /** |
|
| 303 | - * Replaces all URL encoded unicode characters |
|
| 304 | - * in the string with the unicode character. |
|
| 305 | - * |
|
| 306 | - * @param string $string |
|
| 307 | - * @return string |
|
| 308 | - */ |
|
| 302 | + /** |
|
| 303 | + * Replaces all URL encoded unicode characters |
|
| 304 | + * in the string with the unicode character. |
|
| 305 | + * |
|
| 306 | + * @param string $string |
|
| 307 | + * @return string |
|
| 308 | + */ |
|
| 309 | 309 | protected function restoreUnicodeChar(string $string) : string |
| 310 | 310 | { |
| 311 | 311 | if(strstr($string, '%')) |
@@ -363,21 +363,21 @@ discard block |
||
| 363 | 363 | ); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * Checks whether the URL that was parsed is valid. |
|
| 368 | - * @return bool |
|
| 369 | - */ |
|
| 366 | + /** |
|
| 367 | + * Checks whether the URL that was parsed is valid. |
|
| 368 | + * @return bool |
|
| 369 | + */ |
|
| 370 | 370 | public function isValid() : bool |
| 371 | 371 | { |
| 372 | 372 | return $this->isValid; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * If the validation failed, retrieves the validation |
|
| 377 | - * error message. |
|
| 378 | - * |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 375 | + /** |
|
| 376 | + * If the validation failed, retrieves the validation |
|
| 377 | + * error message. |
|
| 378 | + * |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | 381 | public function getErrorMessage() : string |
| 382 | 382 | { |
| 383 | 383 | if(isset($this->error)) { |
@@ -387,12 +387,12 @@ discard block |
||
| 387 | 387 | return ''; |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - /** |
|
| 391 | - * If the validation failed, retrieves the validation |
|
| 392 | - * error code. |
|
| 393 | - * |
|
| 394 | - * @return int |
|
| 395 | - */ |
|
| 390 | + /** |
|
| 391 | + * If the validation failed, retrieves the validation |
|
| 392 | + * error code. |
|
| 393 | + * |
|
| 394 | + * @return int |
|
| 395 | + */ |
|
| 396 | 396 | public function getErrorCode() : int |
| 397 | 397 | { |
| 398 | 398 | if(isset($this->error)) { |
@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | const ERROR_MALFORMATTED_STRING = 53801; |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var string[] |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var string[] |
|
| 27 | + */ |
|
| 28 | 28 | protected static $controlChars = array( |
| 29 | 29 | '0000-0008', // control chars |
| 30 | 30 | '000E-000F', // control chars |
@@ -32,19 +32,19 @@ discard block |
||
| 32 | 32 | '2000-200F', // non-breaking space and co |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var string|NULL |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var string|NULL |
|
| 37 | + */ |
|
| 38 | 38 | protected static $controlCharsRegex; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string[] |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var string[] |
|
| 42 | + */ |
|
| 43 | 43 | protected static $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string[]|NULL |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string[]|NULL |
|
| 47 | + */ |
|
| 48 | 48 | protected static $charsAsHex; |
| 49 | 49 | |
| 50 | 50 | public function __construct() |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Retrieves the HEX character codes for all control |
|
| 72 | - * characters that the {@link stripControlCharacters()} |
|
| 73 | - * method will remove. |
|
| 74 | - * |
|
| 75 | - * @return string[] |
|
| 76 | - */ |
|
| 70 | + /** |
|
| 71 | + * Retrieves the HEX character codes for all control |
|
| 72 | + * characters that the {@link stripControlCharacters()} |
|
| 73 | + * method will remove. |
|
| 74 | + * |
|
| 75 | + * @return string[] |
|
| 76 | + */ |
|
| 77 | 77 | public function getCharsAsHex() : array |
| 78 | 78 | { |
| 79 | 79 | if (isset(self::$charsAsHex)) |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | return $stack; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Retrieves an array of all control characters that |
|
| 125 | - * the {@link stripControlCharacters()} method will |
|
| 126 | - * remove, as the actual UTF-8 characters. |
|
| 127 | - * |
|
| 128 | - * @return string[] |
|
| 129 | - */ |
|
| 123 | + /** |
|
| 124 | + * Retrieves an array of all control characters that |
|
| 125 | + * the {@link stripControlCharacters()} method will |
|
| 126 | + * remove, as the actual UTF-8 characters. |
|
| 127 | + * |
|
| 128 | + * @return string[] |
|
| 129 | + */ |
|
| 130 | 130 | public function getCharsAsUTF8() : array |
| 131 | 131 | { |
| 132 | 132 | $chars = $this->getCharsAsHex(); |
@@ -139,12 +139,12 @@ discard block |
||
| 139 | 139 | return $result; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Retrieves all control characters as JSON encoded |
|
| 144 | - * characters, e.g. "\u200b". |
|
| 145 | - * |
|
| 146 | - * @return string[] |
|
| 147 | - */ |
|
| 142 | + /** |
|
| 143 | + * Retrieves all control characters as JSON encoded |
|
| 144 | + * characters, e.g. "\u200b". |
|
| 145 | + * |
|
| 146 | + * @return string[] |
|
| 147 | + */ |
|
| 148 | 148 | public function getCharsAsJSON() : array |
| 149 | 149 | { |
| 150 | 150 | $chars = $this->getCharsAsHex(); |
@@ -157,17 +157,17 @@ discard block |
||
| 157 | 157 | return $result; |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * Removes all control characters from the specified string |
|
| 162 | - * that can cause problems in some cases, like creating |
|
| 163 | - * valid XML documents. This includes invisible non-breaking |
|
| 164 | - * spaces. |
|
| 165 | - * |
|
| 166 | - * @param string $string |
|
| 167 | - * @return string |
|
| 168 | - * @see https://stackoverflow.com/a/8171868/2298192 |
|
| 169 | - * @see https://unicode-table.com/en |
|
| 170 | - */ |
|
| 160 | + /** |
|
| 161 | + * Removes all control characters from the specified string |
|
| 162 | + * that can cause problems in some cases, like creating |
|
| 163 | + * valid XML documents. This includes invisible non-breaking |
|
| 164 | + * spaces. |
|
| 165 | + * |
|
| 166 | + * @param string $string |
|
| 167 | + * @return string |
|
| 168 | + * @see https://stackoverflow.com/a/8171868/2298192 |
|
| 169 | + * @see https://unicode-table.com/en |
|
| 170 | + */ |
|
| 171 | 171 | public function stripControlCharacters(string $string) : string |
| 172 | 172 | { |
| 173 | 173 | if(empty($string)) |
@@ -22,19 +22,19 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | const ERROR_NO_BOUNDARIES_SPECIFIED = 44401; |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var RequestHelper |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var RequestHelper |
|
| 27 | + */ |
|
| 28 | 28 | protected $helper; |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * @var RequestHelper_Boundaries_Boundary[] |
|
| 32 | - */ |
|
| 30 | + /** |
|
| 31 | + * @var RequestHelper_Boundaries_Boundary[] |
|
| 32 | + */ |
|
| 33 | 33 | protected $boundaries = array(); |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var integer |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var integer |
|
| 37 | + */ |
|
| 38 | 38 | protected $contentLength = 0; |
| 39 | 39 | |
| 40 | 40 | public function __construct(RequestHelper $helper) |
@@ -42,31 +42,31 @@ discard block |
||
| 42 | 42 | $this->helper = $helper; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Retrieves the string that is used to separate mime boundaries in the body. |
|
| 47 | - * |
|
| 48 | - * @return string |
|
| 49 | - */ |
|
| 45 | + /** |
|
| 46 | + * Retrieves the string that is used to separate mime boundaries in the body. |
|
| 47 | + * |
|
| 48 | + * @return string |
|
| 49 | + */ |
|
| 50 | 50 | public function getMimeBoundary() : string |
| 51 | 51 | { |
| 52 | 52 | return $this->helper->getMimeBoundary(); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Retrieves the end of line character(s) used in the body. |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 55 | + /** |
|
| 56 | + * Retrieves the end of line character(s) used in the body. |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | 60 | public function getEOL() : string |
| 61 | 61 | { |
| 62 | 62 | return $this->helper->getEOL(); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Retrieves the total content length of all boundary contents. |
|
| 67 | - * |
|
| 68 | - * @return int |
|
| 69 | - */ |
|
| 65 | + /** |
|
| 66 | + * Retrieves the total content length of all boundary contents. |
|
| 67 | + * |
|
| 68 | + * @return int |
|
| 69 | + */ |
|
| 70 | 70 | public function getContentLength() : int |
| 71 | 71 | { |
| 72 | 72 | // this must use strlen, and not mb_strlen: the content length |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | return strlen($this->render()); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Adds a file to be sent with the request. |
|
| 80 | - * |
|
| 81 | - * @param string $varName The variable name to send the file in |
|
| 82 | - * @param string $fileName The name of the file as it should be received at the destination |
|
| 83 | - * @param string $content The raw content of the file |
|
| 84 | - * @param string $contentType The content type, use the constants to specify this |
|
| 85 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 86 | - */ |
|
| 78 | + /** |
|
| 79 | + * Adds a file to be sent with the request. |
|
| 80 | + * |
|
| 81 | + * @param string $varName The variable name to send the file in |
|
| 82 | + * @param string $fileName The name of the file as it should be received at the destination |
|
| 83 | + * @param string $content The raw content of the file |
|
| 84 | + * @param string $contentType The content type, use the constants to specify this |
|
| 85 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 86 | + */ |
|
| 87 | 87 | public function addFile(string $varName, string $fileName, string $content, string $contentType = '', string $encoding = '') : RequestHelper_Boundaries |
| 88 | 88 | { |
| 89 | 89 | if(empty($contentType)) |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | return $this->addBoundary($boundary); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Adds arbitrary content. |
|
| 112 | - * |
|
| 113 | - * @param string $varName |
|
| 114 | - * @param string $content |
|
| 115 | - * @param string $contentType |
|
| 116 | - */ |
|
| 110 | + /** |
|
| 111 | + * Adds arbitrary content. |
|
| 112 | + * |
|
| 113 | + * @param string $varName |
|
| 114 | + * @param string $content |
|
| 115 | + * @param string $contentType |
|
| 116 | + */ |
|
| 117 | 117 | public function addContent(string $varName, string $content, string $contentType) : RequestHelper_Boundaries |
| 118 | 118 | { |
| 119 | 119 | $content = ConvertHelper::string2utf8($content); |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | return $this->addBoundary($boundary); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Adds a variable to be sent with the request. If it |
|
| 132 | - * already exists, its value is overwritten. |
|
| 133 | - * |
|
| 134 | - * @param string $name |
|
| 135 | - * @param string $value |
|
| 136 | - */ |
|
| 130 | + /** |
|
| 131 | + * Adds a variable to be sent with the request. If it |
|
| 132 | + * already exists, its value is overwritten. |
|
| 133 | + * |
|
| 134 | + * @param string $name |
|
| 135 | + * @param string $value |
|
| 136 | + */ |
|
| 137 | 137 | public function addVariable(string $name, string $value) : RequestHelper_Boundaries |
| 138 | 138 | { |
| 139 | 139 | $boundary = $this->createBoundary($value) |
@@ -149,11 +149,11 @@ discard block |
||
| 149 | 149 | return $this; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - /** |
|
| 153 | - * Renders the response body with all mime boundaries. |
|
| 154 | - * |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 152 | + /** |
|
| 153 | + * Renders the response body with all mime boundaries. |
|
| 154 | + * |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | 157 | public function render() : string |
| 158 | 158 | { |
| 159 | 159 | if(empty($this->boundaries)) |
@@ -37,25 +37,25 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | const ERROR_INVALID_SERIALIZED_DATA = 56301; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | 43 | protected $string; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var mixed |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var mixed |
|
| 47 | + */ |
|
| 48 | 48 | protected $value; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | 53 | protected $type; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @param mixed $value |
|
| 57 | - * @param array|null $serialized |
|
| 58 | - */ |
|
| 55 | + /** |
|
| 56 | + * @param mixed $value |
|
| 57 | + * @param array|null $serialized |
|
| 58 | + */ |
|
| 59 | 59 | public function __construct($value, $serialized=null) |
| 60 | 60 | { |
| 61 | 61 | if(is_array($serialized)) |
@@ -68,40 +68,40 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Creates a new variable info instance from a PHP variable |
|
| 73 | - * of any type. |
|
| 74 | - * |
|
| 75 | - * @param mixed $variable |
|
| 76 | - * @return VariableInfo |
|
| 77 | - */ |
|
| 71 | + /** |
|
| 72 | + * Creates a new variable info instance from a PHP variable |
|
| 73 | + * of any type. |
|
| 74 | + * |
|
| 75 | + * @param mixed $variable |
|
| 76 | + * @return VariableInfo |
|
| 77 | + */ |
|
| 78 | 78 | public static function fromVariable($variable) : VariableInfo |
| 79 | 79 | { |
| 80 | 80 | return new VariableInfo($variable); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Restores a variable info instance using a previously serialized |
|
| 85 | - * array using the serialize() method. |
|
| 86 | - * |
|
| 87 | - * @param array $serialized |
|
| 88 | - * @return VariableInfo |
|
| 89 | - * @see VariableInfo::serialize() |
|
| 90 | - */ |
|
| 83 | + /** |
|
| 84 | + * Restores a variable info instance using a previously serialized |
|
| 85 | + * array using the serialize() method. |
|
| 86 | + * |
|
| 87 | + * @param array $serialized |
|
| 88 | + * @return VariableInfo |
|
| 89 | + * @see VariableInfo::serialize() |
|
| 90 | + */ |
|
| 91 | 91 | public static function fromSerialized(array $serialized) : VariableInfo |
| 92 | 92 | { |
| 93 | 93 | return new VariableInfo(null, $serialized); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Parses a previously serialized data set to restore the |
|
| 98 | - * variable information from it. |
|
| 99 | - * |
|
| 100 | - * @param array $serialized |
|
| 101 | - * @throws BaseException |
|
| 102 | - * |
|
| 103 | - * @see VariableInfo::ERROR_INVALID_SERIALIZED_DATA |
|
| 104 | - */ |
|
| 96 | + /** |
|
| 97 | + * Parses a previously serialized data set to restore the |
|
| 98 | + * variable information from it. |
|
| 99 | + * |
|
| 100 | + * @param array $serialized |
|
| 101 | + * @throws BaseException |
|
| 102 | + * |
|
| 103 | + * @see VariableInfo::ERROR_INVALID_SERIALIZED_DATA |
|
| 104 | + */ |
|
| 105 | 105 | protected function parseSerialized(array $serialized) : void |
| 106 | 106 | { |
| 107 | 107 | if(!isset($serialized['string']) || !isset($serialized['type']) || !isset($serialized['options'])) |
@@ -136,12 +136,12 @@ discard block |
||
| 136 | 136 | return $this->value; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * The variable type - this is the same string that |
|
| 141 | - * is returned by the PHP function `gettype`. |
|
| 142 | - * |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 139 | + /** |
|
| 140 | + * The variable type - this is the same string that |
|
| 141 | + * is returned by the PHP function `gettype`. |
|
| 142 | + * |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | 145 | public function getType() : string |
| 146 | 146 | { |
| 147 | 147 | return $this->type; |
@@ -155,13 +155,13 @@ discard block |
||
| 155 | 155 | ); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Whether to prepend the variable type before the value, |
|
| 160 | - * like the var_dump function. Example: <code>string "Some text"</code>. |
|
| 161 | - * |
|
| 162 | - * @param bool $enable |
|
| 163 | - * @return VariableInfo |
|
| 164 | - */ |
|
| 158 | + /** |
|
| 159 | + * Whether to prepend the variable type before the value, |
|
| 160 | + * like the var_dump function. Example: <code>string "Some text"</code>. |
|
| 161 | + * |
|
| 162 | + * @param bool $enable |
|
| 163 | + * @return VariableInfo |
|
| 164 | + */ |
|
| 165 | 165 | public function enableType(bool $enable=true) : VariableInfo |
| 166 | 166 | { |
| 167 | 167 | return $this->setOption('prepend-type', $enable); |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | return str_replace("\t", str_repeat(' ', $tabSize), $string); |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Converts spaces to tabs in the specified string. |
|
| 63 | - * |
|
| 64 | - * @param string $string |
|
| 65 | - * @param int $tabSize The amount of spaces per tab in the source string. |
|
| 66 | - * @return string |
|
| 67 | - */ |
|
| 61 | + /** |
|
| 62 | + * Converts spaces to tabs in the specified string. |
|
| 63 | + * |
|
| 64 | + * @param string $string |
|
| 65 | + * @param int $tabSize The amount of spaces per tab in the source string. |
|
| 66 | + * @return string |
|
| 67 | + */ |
|
| 68 | 68 | public static function spaces2tabs(string $string, int $tabSize=4) : string |
| 69 | 69 | { |
| 70 | 70 | return str_replace(str_repeat(' ', $tabSize), "\t", $string); |
@@ -77,14 +77,14 @@ discard block |
||
| 77 | 77 | return $converter->convert($string); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Converts the specified amount of seconds into |
|
| 82 | - * a human readable string split in months, weeks, |
|
| 83 | - * days, hours, minutes and seconds. |
|
| 84 | - * |
|
| 85 | - * @param float $seconds |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 80 | + /** |
|
| 81 | + * Converts the specified amount of seconds into |
|
| 82 | + * a human readable string split in months, weeks, |
|
| 83 | + * days, hours, minutes and seconds. |
|
| 84 | + * |
|
| 85 | + * @param float $seconds |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | 88 | public static function time2string($seconds) |
| 89 | 89 | { |
| 90 | 90 | static $units = null; |
@@ -156,41 +156,41 @@ discard block |
||
| 156 | 156 | return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Converts a timestamp into an easily understandable |
|
| 161 | - * format, e.g. "2 hours", "1 day", "3 months" |
|
| 162 | - * |
|
| 163 | - * If you set the date to parameter, the difference |
|
| 164 | - * will be calculated between the two dates and not |
|
| 165 | - * the current time. |
|
| 166 | - * |
|
| 167 | - * @param integer|\DateTime $datefrom |
|
| 168 | - * @param integer|\DateTime $dateto |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 159 | + /** |
|
| 160 | + * Converts a timestamp into an easily understandable |
|
| 161 | + * format, e.g. "2 hours", "1 day", "3 months" |
|
| 162 | + * |
|
| 163 | + * If you set the date to parameter, the difference |
|
| 164 | + * will be calculated between the two dates and not |
|
| 165 | + * the current time. |
|
| 166 | + * |
|
| 167 | + * @param integer|\DateTime $datefrom |
|
| 168 | + * @param integer|\DateTime $dateto |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | 171 | public static function duration2string($datefrom, $dateto = -1) : string |
| 172 | 172 | { |
| 173 | - $converter = new ConvertHelper_DurationConverter(); |
|
| 173 | + $converter = new ConvertHelper_DurationConverter(); |
|
| 174 | 174 | |
| 175 | - if($datefrom instanceof \DateTime) |
|
| 176 | - { |
|
| 177 | - $converter->setDateFrom($datefrom); |
|
| 178 | - } |
|
| 179 | - else |
|
| 180 | - { |
|
| 181 | - $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
| 182 | - } |
|
| 175 | + if($datefrom instanceof \DateTime) |
|
| 176 | + { |
|
| 177 | + $converter->setDateFrom($datefrom); |
|
| 178 | + } |
|
| 179 | + else |
|
| 180 | + { |
|
| 181 | + $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - if($dateto instanceof \DateTime) |
|
| 185 | - { |
|
| 186 | - $converter->setDateTo($dateto); |
|
| 187 | - } |
|
| 188 | - else if($dateto > 0) |
|
| 189 | - { |
|
| 190 | - $converter->setDateTo(self::timestamp2date($dateto)); |
|
| 191 | - } |
|
| 184 | + if($dateto instanceof \DateTime) |
|
| 185 | + { |
|
| 186 | + $converter->setDateTo($dateto); |
|
| 187 | + } |
|
| 188 | + else if($dateto > 0) |
|
| 189 | + { |
|
| 190 | + $converter->setDateTo(self::timestamp2date($dateto)); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - return $converter->convert(); |
|
| 193 | + return $converter->convert(); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -229,44 +229,44 @@ discard block |
||
| 229 | 229 | return $geshi->parse_code(); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Converts a number of bytes to a human readable form, |
|
| 234 | - * e.g. xx Kb / xx Mb / xx Gb |
|
| 235 | - * |
|
| 236 | - * @param int $bytes The amount of bytes to convert. |
|
| 237 | - * @param int $precision The amount of decimals |
|
| 238 | - * @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). |
|
| 239 | - * @return string |
|
| 240 | - * |
|
| 241 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 242 | - */ |
|
| 232 | + /** |
|
| 233 | + * Converts a number of bytes to a human readable form, |
|
| 234 | + * e.g. xx Kb / xx Mb / xx Gb |
|
| 235 | + * |
|
| 236 | + * @param int $bytes The amount of bytes to convert. |
|
| 237 | + * @param int $precision The amount of decimals |
|
| 238 | + * @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). |
|
| 239 | + * @return string |
|
| 240 | + * |
|
| 241 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 242 | + */ |
|
| 243 | 243 | public static function bytes2readable(int $bytes, int $precision = 1, int $base = ConvertHelper_StorageSizeEnum::BASE_10) : string |
| 244 | 244 | { |
| 245 | 245 | return self::parseBytes($bytes)->toString($precision, $base); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * Parses a number of bytes, and creates a converter instance which |
|
| 250 | - * allows doing common operations with it. |
|
| 251 | - * |
|
| 252 | - * @param int $bytes |
|
| 253 | - * @return ConvertHelper_ByteConverter |
|
| 254 | - */ |
|
| 248 | + /** |
|
| 249 | + * Parses a number of bytes, and creates a converter instance which |
|
| 250 | + * allows doing common operations with it. |
|
| 251 | + * |
|
| 252 | + * @param int $bytes |
|
| 253 | + * @return ConvertHelper_ByteConverter |
|
| 254 | + */ |
|
| 255 | 255 | public static function parseBytes(int $bytes) : ConvertHelper_ByteConverter |
| 256 | 256 | { |
| 257 | 257 | return new ConvertHelper_ByteConverter($bytes); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - /** |
|
| 261 | - * Cuts a text to the specified length if it is longer than the |
|
| 262 | - * target length. Appends a text to signify it has been cut at |
|
| 263 | - * the end of the string. |
|
| 264 | - * |
|
| 265 | - * @param string $text |
|
| 266 | - * @param int $targetLength |
|
| 267 | - * @param string $append |
|
| 268 | - * @return string |
|
| 269 | - */ |
|
| 260 | + /** |
|
| 261 | + * Cuts a text to the specified length if it is longer than the |
|
| 262 | + * target length. Appends a text to signify it has been cut at |
|
| 263 | + * the end of the string. |
|
| 264 | + * |
|
| 265 | + * @param string $text |
|
| 266 | + * @param int $targetLength |
|
| 267 | + * @param string $append |
|
| 268 | + * @return string |
|
| 269 | + */ |
|
| 270 | 270 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
| 271 | 271 | { |
| 272 | 272 | $length = mb_strlen($text); |
@@ -290,14 +290,14 @@ discard block |
||
| 290 | 290 | return $info->toString(); |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Pretty print_r. |
|
| 295 | - * |
|
| 296 | - * @param mixed $var The variable to dump. |
|
| 297 | - * @param bool $return Whether to return the dumped code. |
|
| 298 | - * @param bool $html Whether to style the dump as HTML. |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 293 | + /** |
|
| 294 | + * Pretty print_r. |
|
| 295 | + * |
|
| 296 | + * @param mixed $var The variable to dump. |
|
| 297 | + * @param bool $return Whether to return the dumped code. |
|
| 298 | + * @param bool $html Whether to style the dump as HTML. |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | 301 | public static function print_r($var, bool $return=false, bool $html=true) : string |
| 302 | 302 | { |
| 303 | 303 | $result = parseVariable($var)->enableType()->toString(); |
@@ -327,15 +327,15 @@ discard block |
||
| 327 | 327 | 'no' => false |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | - /** |
|
| 331 | - * Converts a string, number or boolean value to a boolean value. |
|
| 332 | - * |
|
| 333 | - * @param mixed $string |
|
| 334 | - * @throws ConvertHelper_Exception |
|
| 335 | - * @return bool |
|
| 336 | - * |
|
| 337 | - * @see ConvertHelper::ERROR_INVALID_BOOLEAN_STRING |
|
| 338 | - */ |
|
| 330 | + /** |
|
| 331 | + * Converts a string, number or boolean value to a boolean value. |
|
| 332 | + * |
|
| 333 | + * @param mixed $string |
|
| 334 | + * @throws ConvertHelper_Exception |
|
| 335 | + * @return bool |
|
| 336 | + * |
|
| 337 | + * @see ConvertHelper::ERROR_INVALID_BOOLEAN_STRING |
|
| 338 | + */ |
|
| 339 | 339 | public static function string2bool($string) : bool |
| 340 | 340 | { |
| 341 | 341 | if($string === '' || $string === null || !is_scalar($string)) |
@@ -363,27 +363,27 @@ discard block |
||
| 363 | 363 | ); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * Whether the specified string is a boolean string or boolean value. |
|
| 368 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 369 | - * |
|
| 370 | - * @param mixed $string |
|
| 371 | - * @return bool |
|
| 372 | - * @deprecated |
|
| 373 | - * @see ConvertHelper::isBoolean() |
|
| 374 | - */ |
|
| 366 | + /** |
|
| 367 | + * Whether the specified string is a boolean string or boolean value. |
|
| 368 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 369 | + * |
|
| 370 | + * @param mixed $string |
|
| 371 | + * @return bool |
|
| 372 | + * @deprecated |
|
| 373 | + * @see ConvertHelper::isBoolean() |
|
| 374 | + */ |
|
| 375 | 375 | public static function isBooleanString($string) : bool |
| 376 | 376 | { |
| 377 | 377 | return self::isBoolean($string); |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 382 | - * |
|
| 383 | - * @param string $text |
|
| 384 | - * @return string |
|
| 385 | - * @deprecated |
|
| 386 | - */ |
|
| 380 | + /** |
|
| 381 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 382 | + * |
|
| 383 | + * @param string $text |
|
| 384 | + * @return string |
|
| 385 | + * @deprecated |
|
| 386 | + */ |
|
| 387 | 387 | public static function text_makeXMLCompliant($text) |
| 388 | 388 | { |
| 389 | 389 | return XMLHelper::string2xml($text); |
@@ -485,80 +485,80 @@ discard block |
||
| 485 | 485 | return $translit->convert($string); |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - /** |
|
| 489 | - * Retrieves the HEX character codes for all control |
|
| 490 | - * characters that the {@link stripControlCharacters()} |
|
| 491 | - * method will remove. |
|
| 492 | - * |
|
| 493 | - * @return string[] |
|
| 494 | - */ |
|
| 488 | + /** |
|
| 489 | + * Retrieves the HEX character codes for all control |
|
| 490 | + * characters that the {@link stripControlCharacters()} |
|
| 491 | + * method will remove. |
|
| 492 | + * |
|
| 493 | + * @return string[] |
|
| 494 | + */ |
|
| 495 | 495 | public static function getControlCharactersAsHex() |
| 496 | 496 | { |
| 497 | 497 | return self::createControlCharacters()->getCharsAsHex(); |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - /** |
|
| 501 | - * Retrieves an array of all control characters that |
|
| 502 | - * the {@link stripControlCharacters()} method will |
|
| 503 | - * remove, as the actual UTF-8 characters. |
|
| 504 | - * |
|
| 505 | - * @return string[] |
|
| 506 | - */ |
|
| 500 | + /** |
|
| 501 | + * Retrieves an array of all control characters that |
|
| 502 | + * the {@link stripControlCharacters()} method will |
|
| 503 | + * remove, as the actual UTF-8 characters. |
|
| 504 | + * |
|
| 505 | + * @return string[] |
|
| 506 | + */ |
|
| 507 | 507 | public static function getControlCharactersAsUTF8() |
| 508 | 508 | { |
| 509 | 509 | return self::createControlCharacters()->getCharsAsUTF8(); |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - /** |
|
| 513 | - * Retrieves all control characters as JSON encoded |
|
| 514 | - * characters, e.g. "\u200b". |
|
| 515 | - * |
|
| 516 | - * @return string[] |
|
| 517 | - */ |
|
| 512 | + /** |
|
| 513 | + * Retrieves all control characters as JSON encoded |
|
| 514 | + * characters, e.g. "\u200b". |
|
| 515 | + * |
|
| 516 | + * @return string[] |
|
| 517 | + */ |
|
| 518 | 518 | public static function getControlCharactersAsJSON() |
| 519 | 519 | { |
| 520 | 520 | return self::createControlCharacters()->getCharsAsJSON(); |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - /** |
|
| 524 | - * Removes all control characters from the specified string |
|
| 525 | - * that can cause problems in some cases, like creating |
|
| 526 | - * valid XML documents. This includes invisible non-breaking |
|
| 527 | - * spaces. |
|
| 528 | - * |
|
| 529 | - * @param string $string |
|
| 530 | - * @return string |
|
| 531 | - */ |
|
| 523 | + /** |
|
| 524 | + * Removes all control characters from the specified string |
|
| 525 | + * that can cause problems in some cases, like creating |
|
| 526 | + * valid XML documents. This includes invisible non-breaking |
|
| 527 | + * spaces. |
|
| 528 | + * |
|
| 529 | + * @param string $string |
|
| 530 | + * @return string |
|
| 531 | + */ |
|
| 532 | 532 | public static function stripControlCharacters(string $string) : string |
| 533 | 533 | { |
| 534 | 534 | return self::createControlCharacters()->stripControlCharacters($string); |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - /** |
|
| 538 | - * Creates the control characters class, used to |
|
| 539 | - * work with control characters in strings. |
|
| 540 | - * |
|
| 541 | - * @return ConvertHelper_ControlCharacters |
|
| 542 | - */ |
|
| 537 | + /** |
|
| 538 | + * Creates the control characters class, used to |
|
| 539 | + * work with control characters in strings. |
|
| 540 | + * |
|
| 541 | + * @return ConvertHelper_ControlCharacters |
|
| 542 | + */ |
|
| 543 | 543 | public static function createControlCharacters() : ConvertHelper_ControlCharacters |
| 544 | 544 | { |
| 545 | 545 | return new ConvertHelper_ControlCharacters(); |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - /** |
|
| 549 | - * Converts a unicode character to the PHPO notation. |
|
| 550 | - * |
|
| 551 | - * Example: |
|
| 552 | - * |
|
| 553 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 554 | - * |
|
| 555 | - * Returns |
|
| 556 | - * |
|
| 557 | - * <pre>\x0</pre> |
|
| 558 | - * |
|
| 559 | - * @param string $unicodeChar |
|
| 560 | - * @return string |
|
| 561 | - */ |
|
| 548 | + /** |
|
| 549 | + * Converts a unicode character to the PHPO notation. |
|
| 550 | + * |
|
| 551 | + * Example: |
|
| 552 | + * |
|
| 553 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 554 | + * |
|
| 555 | + * Returns |
|
| 556 | + * |
|
| 557 | + * <pre>\x0</pre> |
|
| 558 | + * |
|
| 559 | + * @param string $unicodeChar |
|
| 560 | + * @return string |
|
| 561 | + */ |
|
| 562 | 562 | public static function unicodeChar2php(string $unicodeChar) : string |
| 563 | 563 | { |
| 564 | 564 | $unicodeChar = json_decode($unicodeChar); |
@@ -684,25 +684,25 @@ discard block |
||
| 684 | 684 | return 'false'; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | - /** |
|
| 688 | - * Converts an associative array with attribute name > value pairs |
|
| 689 | - * to an attribute string that can be used in an HTML tag. Empty |
|
| 690 | - * attribute values are ignored. |
|
| 691 | - * |
|
| 692 | - * Example: |
|
| 693 | - * |
|
| 694 | - * array2attributeString(array( |
|
| 695 | - * 'id' => 45, |
|
| 696 | - * 'href' => 'http://www.mistralys.com' |
|
| 697 | - * )); |
|
| 698 | - * |
|
| 699 | - * Result: |
|
| 700 | - * |
|
| 701 | - * id="45" href="http://www.mistralys.com" |
|
| 702 | - * |
|
| 703 | - * @param array $array |
|
| 704 | - * @return string |
|
| 705 | - */ |
|
| 687 | + /** |
|
| 688 | + * Converts an associative array with attribute name > value pairs |
|
| 689 | + * to an attribute string that can be used in an HTML tag. Empty |
|
| 690 | + * attribute values are ignored. |
|
| 691 | + * |
|
| 692 | + * Example: |
|
| 693 | + * |
|
| 694 | + * array2attributeString(array( |
|
| 695 | + * 'id' => 45, |
|
| 696 | + * 'href' => 'http://www.mistralys.com' |
|
| 697 | + * )); |
|
| 698 | + * |
|
| 699 | + * Result: |
|
| 700 | + * |
|
| 701 | + * id="45" href="http://www.mistralys.com" |
|
| 702 | + * |
|
| 703 | + * @param array $array |
|
| 704 | + * @return string |
|
| 705 | + */ |
|
| 706 | 706 | public static function array2attributeString($array) |
| 707 | 707 | { |
| 708 | 708 | $tokens = array(); |
@@ -721,14 +721,14 @@ discard block |
||
| 721 | 721 | return ' '.implode(' ', $tokens); |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | - /** |
|
| 725 | - * Converts a string so it can safely be used in a javascript |
|
| 726 | - * statement in an HTML tag: uses single quotes around the string |
|
| 727 | - * and encodes all special characters as needed. |
|
| 728 | - * |
|
| 729 | - * @param string $string |
|
| 730 | - * @return string |
|
| 731 | - */ |
|
| 724 | + /** |
|
| 725 | + * Converts a string so it can safely be used in a javascript |
|
| 726 | + * statement in an HTML tag: uses single quotes around the string |
|
| 727 | + * and encodes all special characters as needed. |
|
| 728 | + * |
|
| 729 | + * @param string $string |
|
| 730 | + * @return string |
|
| 731 | + */ |
|
| 732 | 732 | public static function string2attributeJS($string, $quoted=true) |
| 733 | 733 | { |
| 734 | 734 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -739,15 +739,15 @@ discard block |
||
| 739 | 739 | return $converted; |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | - /** |
|
| 743 | - * Checks if the specified string is a boolean value, which |
|
| 744 | - * includes string representations of boolean values, like |
|
| 745 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 746 | - * or <code>false</code>. |
|
| 747 | - * |
|
| 748 | - * @param mixed $value |
|
| 749 | - * @return boolean |
|
| 750 | - */ |
|
| 742 | + /** |
|
| 743 | + * Checks if the specified string is a boolean value, which |
|
| 744 | + * includes string representations of boolean values, like |
|
| 745 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 746 | + * or <code>false</code>. |
|
| 747 | + * |
|
| 748 | + * @param mixed $value |
|
| 749 | + * @return boolean |
|
| 750 | + */ |
|
| 751 | 751 | public static function isBoolean($value) : bool |
| 752 | 752 | { |
| 753 | 753 | if(is_bool($value)) { |
@@ -761,12 +761,12 @@ discard block |
||
| 761 | 761 | return array_key_exists($value, self::$booleanStrings); |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | - /** |
|
| 765 | - * Converts an associative array to an HTML style attribute value string. |
|
| 766 | - * |
|
| 767 | - * @param array $subject |
|
| 768 | - * @return string |
|
| 769 | - */ |
|
| 764 | + /** |
|
| 765 | + * Converts an associative array to an HTML style attribute value string. |
|
| 766 | + * |
|
| 767 | + * @param array $subject |
|
| 768 | + * @return string |
|
| 769 | + */ |
|
| 770 | 770 | public static function array2styleString(array $subject) : string |
| 771 | 771 | { |
| 772 | 772 | $tokens = array(); |
@@ -777,23 +777,23 @@ discard block |
||
| 777 | 777 | return implode(';', $tokens); |
| 778 | 778 | } |
| 779 | 779 | |
| 780 | - /** |
|
| 781 | - * Converts a DateTime object to a timestamp, which |
|
| 782 | - * is PHP 5.2 compatible. |
|
| 783 | - * |
|
| 784 | - * @param \DateTime $date |
|
| 785 | - * @return integer |
|
| 786 | - */ |
|
| 780 | + /** |
|
| 781 | + * Converts a DateTime object to a timestamp, which |
|
| 782 | + * is PHP 5.2 compatible. |
|
| 783 | + * |
|
| 784 | + * @param \DateTime $date |
|
| 785 | + * @return integer |
|
| 786 | + */ |
|
| 787 | 787 | public static function date2timestamp(\DateTime $date) : int |
| 788 | 788 | { |
| 789 | 789 | return (int)$date->format('U'); |
| 790 | 790 | } |
| 791 | 791 | |
| 792 | - /** |
|
| 793 | - * Converts a timestamp into a DateTime instance. |
|
| 794 | - * @param int $timestamp |
|
| 795 | - * @return \DateTime |
|
| 796 | - */ |
|
| 792 | + /** |
|
| 793 | + * Converts a timestamp into a DateTime instance. |
|
| 794 | + * @param int $timestamp |
|
| 795 | + * @return \DateTime |
|
| 796 | + */ |
|
| 797 | 797 | public static function timestamp2date(int $timestamp) : \DateTime |
| 798 | 798 | { |
| 799 | 799 | $date = new \DateTime(); |
@@ -801,50 +801,50 @@ discard block |
||
| 801 | 801 | return $date; |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | - /** |
|
| 805 | - * Strips an absolute path to a file within the application |
|
| 806 | - * to make the path relative to the application root path. |
|
| 807 | - * |
|
| 808 | - * @param string $path |
|
| 809 | - * @return string |
|
| 810 | - * |
|
| 811 | - * @see FileHelper::relativizePath() |
|
| 812 | - * @see FileHelper::relativizePathByDepth() |
|
| 813 | - */ |
|
| 804 | + /** |
|
| 805 | + * Strips an absolute path to a file within the application |
|
| 806 | + * to make the path relative to the application root path. |
|
| 807 | + * |
|
| 808 | + * @param string $path |
|
| 809 | + * @return string |
|
| 810 | + * |
|
| 811 | + * @see FileHelper::relativizePath() |
|
| 812 | + * @see FileHelper::relativizePathByDepth() |
|
| 813 | + */ |
|
| 814 | 814 | public static function fileRelativize(string $path) : string |
| 815 | 815 | { |
| 816 | 816 | return FileHelper::relativizePathByDepth($path); |
| 817 | 817 | } |
| 818 | 818 | |
| 819 | 819 | /** |
| 820 | - * Converts a PHP regex to a javascript RegExp object statement. |
|
| 821 | - * |
|
| 822 | - * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
| 823 | - * More details are available on its usage there. |
|
| 824 | - * |
|
| 825 | - * @param string $regex A PHP preg regex |
|
| 826 | - * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
| 827 | - * @return array|string Depending on the specified return type. |
|
| 828 | - * |
|
| 829 | - * @see JSHelper::buildRegexStatement() |
|
| 830 | - */ |
|
| 820 | + * Converts a PHP regex to a javascript RegExp object statement. |
|
| 821 | + * |
|
| 822 | + * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
| 823 | + * More details are available on its usage there. |
|
| 824 | + * |
|
| 825 | + * @param string $regex A PHP preg regex |
|
| 826 | + * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
| 827 | + * @return array|string Depending on the specified return type. |
|
| 828 | + * |
|
| 829 | + * @see JSHelper::buildRegexStatement() |
|
| 830 | + */ |
|
| 831 | 831 | public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) |
| 832 | 832 | { |
| 833 | 833 | return JSHelper::buildRegexStatement($regex, $statementType); |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | - /** |
|
| 837 | - * Converts the specified variable to JSON. Works just |
|
| 838 | - * like the native `json_encode` method, except that it |
|
| 839 | - * will trigger an exception on failure, which has the |
|
| 840 | - * json error details included in its developer details. |
|
| 841 | - * |
|
| 842 | - * @param mixed $variable |
|
| 843 | - * @param int $options JSON encode options. |
|
| 844 | - * @param int $depth |
|
| 845 | - * @throws ConvertHelper_Exception |
|
| 846 | - * @return string |
|
| 847 | - */ |
|
| 836 | + /** |
|
| 837 | + * Converts the specified variable to JSON. Works just |
|
| 838 | + * like the native `json_encode` method, except that it |
|
| 839 | + * will trigger an exception on failure, which has the |
|
| 840 | + * json error details included in its developer details. |
|
| 841 | + * |
|
| 842 | + * @param mixed $variable |
|
| 843 | + * @param int $options JSON encode options. |
|
| 844 | + * @param int $depth |
|
| 845 | + * @throws ConvertHelper_Exception |
|
| 846 | + * @return string |
|
| 847 | + */ |
|
| 848 | 848 | public static function var2json($variable, int $options=0, int $depth=512) : string |
| 849 | 849 | { |
| 850 | 850 | $result = json_encode($variable, $options, $depth); |
@@ -865,12 +865,12 @@ discard block |
||
| 865 | 865 | ); |
| 866 | 866 | } |
| 867 | 867 | |
| 868 | - /** |
|
| 869 | - * Strips all known UTF byte order marks from the specified string. |
|
| 870 | - * |
|
| 871 | - * @param string $string |
|
| 872 | - * @return string |
|
| 873 | - */ |
|
| 868 | + /** |
|
| 869 | + * Strips all known UTF byte order marks from the specified string. |
|
| 870 | + * |
|
| 871 | + * @param string $string |
|
| 872 | + * @return string |
|
| 873 | + */ |
|
| 874 | 874 | public static function stripUTFBom($string) |
| 875 | 875 | { |
| 876 | 876 | $boms = FileHelper::getUTFBOMs(); |
@@ -885,13 +885,13 @@ discard block |
||
| 885 | 885 | return $string; |
| 886 | 886 | } |
| 887 | 887 | |
| 888 | - /** |
|
| 889 | - * Converts a string to valid utf8, regardless |
|
| 890 | - * of the string's encoding(s). |
|
| 891 | - * |
|
| 892 | - * @param string $string |
|
| 893 | - * @return string |
|
| 894 | - */ |
|
| 888 | + /** |
|
| 889 | + * Converts a string to valid utf8, regardless |
|
| 890 | + * of the string's encoding(s). |
|
| 891 | + * |
|
| 892 | + * @param string $string |
|
| 893 | + * @return string |
|
| 894 | + */ |
|
| 895 | 895 | public static function string2utf8($string) |
| 896 | 896 | { |
| 897 | 897 | if(!self::isStringASCII($string)) { |
@@ -901,15 +901,15 @@ discard block |
||
| 901 | 901 | return $string; |
| 902 | 902 | } |
| 903 | 903 | |
| 904 | - /** |
|
| 905 | - * Checks whether the specified string is an ASCII |
|
| 906 | - * string, without any special or UTF8 characters. |
|
| 907 | - * Note: empty strings and NULL are considered ASCII. |
|
| 908 | - * Any variable types other than strings are not. |
|
| 909 | - * |
|
| 910 | - * @param mixed $string |
|
| 911 | - * @return boolean |
|
| 912 | - */ |
|
| 904 | + /** |
|
| 905 | + * Checks whether the specified string is an ASCII |
|
| 906 | + * string, without any special or UTF8 characters. |
|
| 907 | + * Note: empty strings and NULL are considered ASCII. |
|
| 908 | + * Any variable types other than strings are not. |
|
| 909 | + * |
|
| 910 | + * @param mixed $string |
|
| 911 | + * @return boolean |
|
| 912 | + */ |
|
| 913 | 913 | public static function isStringASCII($string) : bool |
| 914 | 914 | { |
| 915 | 915 | if($string === '' || $string === NULL) { |
@@ -934,22 +934,22 @@ discard block |
||
| 934 | 934 | return $url; |
| 935 | 935 | } |
| 936 | 936 | |
| 937 | - /** |
|
| 938 | - * Calculates a percentage match of the source string with the target string. |
|
| 939 | - * |
|
| 940 | - * Options are: |
|
| 941 | - * |
|
| 942 | - * - maxLevenshtein, default: 10 |
|
| 943 | - * Any levenshtein results above this value are ignored. |
|
| 944 | - * |
|
| 945 | - * - precision, default: 1 |
|
| 946 | - * The precision of the percentage float value |
|
| 947 | - * |
|
| 948 | - * @param string $source |
|
| 949 | - * @param string $target |
|
| 950 | - * @param array $options |
|
| 951 | - * @return float |
|
| 952 | - */ |
|
| 937 | + /** |
|
| 938 | + * Calculates a percentage match of the source string with the target string. |
|
| 939 | + * |
|
| 940 | + * Options are: |
|
| 941 | + * |
|
| 942 | + * - maxLevenshtein, default: 10 |
|
| 943 | + * Any levenshtein results above this value are ignored. |
|
| 944 | + * |
|
| 945 | + * - precision, default: 1 |
|
| 946 | + * The precision of the percentage float value |
|
| 947 | + * |
|
| 948 | + * @param string $source |
|
| 949 | + * @param string $target |
|
| 950 | + * @param array $options |
|
| 951 | + * @return float |
|
| 952 | + */ |
|
| 953 | 953 | public static function matchString($source, $target, $options=array()) |
| 954 | 954 | { |
| 955 | 955 | $defaults = array( |
@@ -973,14 +973,14 @@ discard block |
||
| 973 | 973 | return round(100 - $percent, $options['precision']); |
| 974 | 974 | } |
| 975 | 975 | |
| 976 | - /** |
|
| 977 | - * Converts a date interval to a human readable string with |
|
| 978 | - * all necessary time components, e.g. "1 year, 2 months and 4 days". |
|
| 979 | - * |
|
| 980 | - * @param \DateInterval $interval |
|
| 981 | - * @return string |
|
| 982 | - * @see ConvertHelper_IntervalConverter |
|
| 983 | - */ |
|
| 976 | + /** |
|
| 977 | + * Converts a date interval to a human readable string with |
|
| 978 | + * all necessary time components, e.g. "1 year, 2 months and 4 days". |
|
| 979 | + * |
|
| 980 | + * @param \DateInterval $interval |
|
| 981 | + * @return string |
|
| 982 | + * @see ConvertHelper_IntervalConverter |
|
| 983 | + */ |
|
| 984 | 984 | public static function interval2string(\DateInterval $interval) : string |
| 985 | 985 | { |
| 986 | 986 | $converter = new ConvertHelper_IntervalConverter(); |
@@ -995,60 +995,60 @@ discard block |
||
| 995 | 995 | |
| 996 | 996 | const INTERVAL_SECONDS = 'seconds'; |
| 997 | 997 | |
| 998 | - /** |
|
| 999 | - * Converts an interval to its total amount of days. |
|
| 1000 | - * @param \DateInterval $interval |
|
| 1001 | - * @return int |
|
| 1002 | - */ |
|
| 998 | + /** |
|
| 999 | + * Converts an interval to its total amount of days. |
|
| 1000 | + * @param \DateInterval $interval |
|
| 1001 | + * @return int |
|
| 1002 | + */ |
|
| 1003 | 1003 | public static function interval2days(\DateInterval $interval) : int |
| 1004 | 1004 | { |
| 1005 | 1005 | return self::interval2total($interval, self::INTERVAL_DAYS); |
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | - /** |
|
| 1009 | - * Converts an interval to its total amount of hours. |
|
| 1010 | - * @param \DateInterval $interval |
|
| 1011 | - * @return int |
|
| 1012 | - */ |
|
| 1008 | + /** |
|
| 1009 | + * Converts an interval to its total amount of hours. |
|
| 1010 | + * @param \DateInterval $interval |
|
| 1011 | + * @return int |
|
| 1012 | + */ |
|
| 1013 | 1013 | public static function interval2hours(\DateInterval $interval) : int |
| 1014 | 1014 | { |
| 1015 | 1015 | return self::interval2total($interval, self::INTERVAL_HOURS); |
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | - /** |
|
| 1019 | - * Converts an interval to its total amount of minutes. |
|
| 1020 | - * @param \DateInterval $interval |
|
| 1021 | - * @return int |
|
| 1022 | - */ |
|
| 1018 | + /** |
|
| 1019 | + * Converts an interval to its total amount of minutes. |
|
| 1020 | + * @param \DateInterval $interval |
|
| 1021 | + * @return int |
|
| 1022 | + */ |
|
| 1023 | 1023 | public static function interval2minutes(\DateInterval $interval) : int |
| 1024 | 1024 | { |
| 1025 | 1025 | return self::interval2total($interval, self::INTERVAL_MINUTES); |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | - /** |
|
| 1029 | - * Converts an interval to its total amount of seconds. |
|
| 1030 | - * @param \DateInterval $interval |
|
| 1031 | - * @return int |
|
| 1032 | - */ |
|
| 1028 | + /** |
|
| 1029 | + * Converts an interval to its total amount of seconds. |
|
| 1030 | + * @param \DateInterval $interval |
|
| 1031 | + * @return int |
|
| 1032 | + */ |
|
| 1033 | 1033 | public static function interval2seconds(\DateInterval $interval) : int |
| 1034 | 1034 | { |
| 1035 | 1035 | return self::interval2total($interval, self::INTERVAL_SECONDS); |
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | - /** |
|
| 1039 | - * Calculates the total amount of days / hours / minutes or seconds |
|
| 1040 | - * of a date interval object (depending in the specified units), and |
|
| 1041 | - * returns the total amount. |
|
| 1042 | - * |
|
| 1043 | - * @param \DateInterval $interval |
|
| 1044 | - * @param string $unit What total value to calculate. |
|
| 1045 | - * @return integer |
|
| 1046 | - * |
|
| 1047 | - * @see ConvertHelper::INTERVAL_SECONDS |
|
| 1048 | - * @see ConvertHelper::INTERVAL_MINUTES |
|
| 1049 | - * @see ConvertHelper::INTERVAL_HOURS |
|
| 1050 | - * @see ConvertHelper::INTERVAL_DAYS |
|
| 1051 | - */ |
|
| 1038 | + /** |
|
| 1039 | + * Calculates the total amount of days / hours / minutes or seconds |
|
| 1040 | + * of a date interval object (depending in the specified units), and |
|
| 1041 | + * returns the total amount. |
|
| 1042 | + * |
|
| 1043 | + * @param \DateInterval $interval |
|
| 1044 | + * @param string $unit What total value to calculate. |
|
| 1045 | + * @return integer |
|
| 1046 | + * |
|
| 1047 | + * @see ConvertHelper::INTERVAL_SECONDS |
|
| 1048 | + * @see ConvertHelper::INTERVAL_MINUTES |
|
| 1049 | + * @see ConvertHelper::INTERVAL_HOURS |
|
| 1050 | + * @see ConvertHelper::INTERVAL_DAYS |
|
| 1051 | + */ |
|
| 1052 | 1052 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int |
| 1053 | 1053 | { |
| 1054 | 1054 | $total = (int)$interval->format('%a'); |
@@ -1088,13 +1088,13 @@ discard block |
||
| 1088 | 1088 | 'Sunday' |
| 1089 | 1089 | ); |
| 1090 | 1090 | |
| 1091 | - /** |
|
| 1092 | - * Converts a date to the corresponding day name. |
|
| 1093 | - * |
|
| 1094 | - * @param \DateTime $date |
|
| 1095 | - * @param bool $short |
|
| 1096 | - * @return string|NULL |
|
| 1097 | - */ |
|
| 1091 | + /** |
|
| 1092 | + * Converts a date to the corresponding day name. |
|
| 1093 | + * |
|
| 1094 | + * @param \DateTime $date |
|
| 1095 | + * @param bool $short |
|
| 1096 | + * @return string|NULL |
|
| 1097 | + */ |
|
| 1098 | 1098 | public static function date2dayName(\DateTime $date, bool $short=false) |
| 1099 | 1099 | { |
| 1100 | 1100 | $day = $date->format('l'); |
@@ -1109,21 +1109,21 @@ discard block |
||
| 1109 | 1109 | return null; |
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | - /** |
|
| 1113 | - * Retrieves a list of english day names. |
|
| 1114 | - * @return string[] |
|
| 1115 | - */ |
|
| 1112 | + /** |
|
| 1113 | + * Retrieves a list of english day names. |
|
| 1114 | + * @return string[] |
|
| 1115 | + */ |
|
| 1116 | 1116 | public static function getDayNamesInvariant() |
| 1117 | 1117 | { |
| 1118 | 1118 | return self::$daysInvariant; |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - /** |
|
| 1122 | - * Retrieves the day names list for the current locale. |
|
| 1123 | - * |
|
| 1124 | - * @param bool $short |
|
| 1125 | - * @return array |
|
| 1126 | - */ |
|
| 1121 | + /** |
|
| 1122 | + * Retrieves the day names list for the current locale. |
|
| 1123 | + * |
|
| 1124 | + * @param bool $short |
|
| 1125 | + * @return array |
|
| 1126 | + */ |
|
| 1127 | 1127 | public static function getDayNames(bool $short=false) : array |
| 1128 | 1128 | { |
| 1129 | 1129 | if($short) { |
@@ -1183,16 +1183,16 @@ discard block |
||
| 1183 | 1183 | return $last; |
| 1184 | 1184 | } |
| 1185 | 1185 | |
| 1186 | - /** |
|
| 1187 | - * Splits a string into an array of all characters it is composed of. |
|
| 1188 | - * Unicode character safe. |
|
| 1189 | - * |
|
| 1190 | - * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1191 | - * characters. |
|
| 1192 | - * |
|
| 1193 | - * @param string $string |
|
| 1194 | - * @return array |
|
| 1195 | - */ |
|
| 1186 | + /** |
|
| 1187 | + * Splits a string into an array of all characters it is composed of. |
|
| 1188 | + * Unicode character safe. |
|
| 1189 | + * |
|
| 1190 | + * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1191 | + * characters. |
|
| 1192 | + * |
|
| 1193 | + * @param string $string |
|
| 1194 | + * @return array |
|
| 1195 | + */ |
|
| 1196 | 1196 | public static function string2array(string $string) : array |
| 1197 | 1197 | { |
| 1198 | 1198 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
@@ -1203,12 +1203,12 @@ discard block |
||
| 1203 | 1203 | return array(); |
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | - /** |
|
| 1207 | - * Checks whether the specified string contains HTML code. |
|
| 1208 | - * |
|
| 1209 | - * @param string $string |
|
| 1210 | - * @return boolean |
|
| 1211 | - */ |
|
| 1206 | + /** |
|
| 1207 | + * Checks whether the specified string contains HTML code. |
|
| 1208 | + * |
|
| 1209 | + * @param string $string |
|
| 1210 | + * @return boolean |
|
| 1211 | + */ |
|
| 1212 | 1212 | public static function isStringHTML(string $string) : bool |
| 1213 | 1213 | { |
| 1214 | 1214 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1223,17 +1223,17 @@ discard block |
||
| 1223 | 1223 | return false; |
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | - /** |
|
| 1227 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1228 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1229 | - * are not calculated correctly. |
|
| 1230 | - * |
|
| 1231 | - * @param string $str |
|
| 1232 | - * @param int $width |
|
| 1233 | - * @param string $break |
|
| 1234 | - * @param bool $cut |
|
| 1235 | - * @return string |
|
| 1236 | - */ |
|
| 1226 | + /** |
|
| 1227 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1228 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1229 | + * are not calculated correctly. |
|
| 1230 | + * |
|
| 1231 | + * @param string $str |
|
| 1232 | + * @param int $width |
|
| 1233 | + * @param string $break |
|
| 1234 | + * @param bool $cut |
|
| 1235 | + * @return string |
|
| 1236 | + */ |
|
| 1237 | 1237 | public static function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false) : string |
| 1238 | 1238 | { |
| 1239 | 1239 | $wrapper = new ConvertHelper_WordWrapper(); |
@@ -1245,27 +1245,27 @@ discard block |
||
| 1245 | 1245 | ->wrapText($str); |
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | - /** |
|
| 1249 | - * Calculates the byte length of a string, taking into |
|
| 1250 | - * account any unicode characters. |
|
| 1251 | - * |
|
| 1252 | - * @param string $string |
|
| 1253 | - * @return int |
|
| 1254 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1255 | - */ |
|
| 1248 | + /** |
|
| 1249 | + * Calculates the byte length of a string, taking into |
|
| 1250 | + * account any unicode characters. |
|
| 1251 | + * |
|
| 1252 | + * @param string $string |
|
| 1253 | + * @return int |
|
| 1254 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1255 | + */ |
|
| 1256 | 1256 | public static function string2bytes($string) |
| 1257 | 1257 | { |
| 1258 | 1258 | return mb_strlen($string, '8bit'); |
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | - /** |
|
| 1262 | - * Creates a short, 8-character long hash for the specified string. |
|
| 1263 | - * |
|
| 1264 | - * WARNING: Not cryptographically safe. |
|
| 1265 | - * |
|
| 1266 | - * @param string $string |
|
| 1267 | - * @return string |
|
| 1268 | - */ |
|
| 1261 | + /** |
|
| 1262 | + * Creates a short, 8-character long hash for the specified string. |
|
| 1263 | + * |
|
| 1264 | + * WARNING: Not cryptographically safe. |
|
| 1265 | + * |
|
| 1266 | + * @param string $string |
|
| 1267 | + * @return string |
|
| 1268 | + */ |
|
| 1269 | 1269 | public static function string2shortHash($string) |
| 1270 | 1270 | { |
| 1271 | 1271 | return hash('crc32', $string, false); |
@@ -1291,40 +1291,40 @@ discard block |
||
| 1291 | 1291 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
| 1292 | 1292 | } |
| 1293 | 1293 | |
| 1294 | - /** |
|
| 1295 | - * Parses the specified query string like the native |
|
| 1296 | - * function <code>parse_str</code>, without the key |
|
| 1297 | - * naming limitations. |
|
| 1298 | - * |
|
| 1299 | - * Using parse_str, dots or spaces in key names are |
|
| 1300 | - * replaced by underscores. This method keeps all names |
|
| 1301 | - * intact. |
|
| 1302 | - * |
|
| 1303 | - * It still uses the parse_str implementation as it |
|
| 1304 | - * is tested and tried, but fixes the parameter names |
|
| 1305 | - * after parsing, as needed. |
|
| 1306 | - * |
|
| 1307 | - * @param string $queryString |
|
| 1308 | - * @return array |
|
| 1309 | - * @see ConvertHelper_QueryParser |
|
| 1310 | - */ |
|
| 1294 | + /** |
|
| 1295 | + * Parses the specified query string like the native |
|
| 1296 | + * function <code>parse_str</code>, without the key |
|
| 1297 | + * naming limitations. |
|
| 1298 | + * |
|
| 1299 | + * Using parse_str, dots or spaces in key names are |
|
| 1300 | + * replaced by underscores. This method keeps all names |
|
| 1301 | + * intact. |
|
| 1302 | + * |
|
| 1303 | + * It still uses the parse_str implementation as it |
|
| 1304 | + * is tested and tried, but fixes the parameter names |
|
| 1305 | + * after parsing, as needed. |
|
| 1306 | + * |
|
| 1307 | + * @param string $queryString |
|
| 1308 | + * @return array |
|
| 1309 | + * @see ConvertHelper_QueryParser |
|
| 1310 | + */ |
|
| 1311 | 1311 | public static function parseQueryString(string $queryString) : array |
| 1312 | 1312 | { |
| 1313 | 1313 | $parser = new ConvertHelper_QueryParser(); |
| 1314 | 1314 | return $parser->parse($queryString); |
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | - /** |
|
| 1318 | - * Searches for needle in the specified string, and returns a list |
|
| 1319 | - * of all occurrences, including the matched string. The matched |
|
| 1320 | - * string is useful when doing a case insensitive search, as it |
|
| 1321 | - * shows the exact matched case of needle. |
|
| 1322 | - * |
|
| 1323 | - * @param string $needle |
|
| 1324 | - * @param string $haystack |
|
| 1325 | - * @param bool $caseInsensitive |
|
| 1326 | - * @return ConvertHelper_StringMatch[] |
|
| 1327 | - */ |
|
| 1317 | + /** |
|
| 1318 | + * Searches for needle in the specified string, and returns a list |
|
| 1319 | + * of all occurrences, including the matched string. The matched |
|
| 1320 | + * string is useful when doing a case insensitive search, as it |
|
| 1321 | + * shows the exact matched case of needle. |
|
| 1322 | + * |
|
| 1323 | + * @param string $needle |
|
| 1324 | + * @param string $haystack |
|
| 1325 | + * @param bool $caseInsensitive |
|
| 1326 | + * @return ConvertHelper_StringMatch[] |
|
| 1327 | + */ |
|
| 1328 | 1328 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
| 1329 | 1329 | { |
| 1330 | 1330 | if($needle === '') { |
@@ -1350,14 +1350,14 @@ discard block |
||
| 1350 | 1350 | return $positions; |
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | - /** |
|
| 1354 | - * Like explode, but trims all entries, and removes |
|
| 1355 | - * empty entries from the resulting array. |
|
| 1356 | - * |
|
| 1357 | - * @param string $delimiter |
|
| 1358 | - * @param string $string |
|
| 1359 | - * @return string[] |
|
| 1360 | - */ |
|
| 1353 | + /** |
|
| 1354 | + * Like explode, but trims all entries, and removes |
|
| 1355 | + * empty entries from the resulting array. |
|
| 1356 | + * |
|
| 1357 | + * @param string $delimiter |
|
| 1358 | + * @param string $string |
|
| 1359 | + * @return string[] |
|
| 1360 | + */ |
|
| 1361 | 1361 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1362 | 1362 | { |
| 1363 | 1363 | if(empty($string) || empty($delimiter)) { |
@@ -1379,12 +1379,12 @@ discard block |
||
| 1379 | 1379 | |
| 1380 | 1380 | protected static $eolChars; |
| 1381 | 1381 | |
| 1382 | - /** |
|
| 1383 | - * Detects the most used end-of-line character in the subject string. |
|
| 1384 | - * |
|
| 1385 | - * @param string $subjectString The string to check. |
|
| 1386 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1387 | - */ |
|
| 1382 | + /** |
|
| 1383 | + * Detects the most used end-of-line character in the subject string. |
|
| 1384 | + * |
|
| 1385 | + * @param string $subjectString The string to check. |
|
| 1386 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1387 | + */ |
|
| 1388 | 1388 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1389 | 1389 | { |
| 1390 | 1390 | if(empty($subjectString)) { |
@@ -1396,27 +1396,27 @@ discard block |
||
| 1396 | 1396 | $cr = chr((int)hexdec('0d')); |
| 1397 | 1397 | $lf = chr((int)hexdec('0a')); |
| 1398 | 1398 | |
| 1399 | - self::$eolChars = array( |
|
| 1400 | - array( |
|
| 1401 | - 'char' => $cr.$lf, |
|
| 1402 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1403 | - 'description' => t('Carriage return followed by a line feed'), |
|
| 1404 | - ), |
|
| 1405 | - array( |
|
| 1406 | - 'char' => $lf.$cr, |
|
| 1407 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1408 | - 'description' => t('Line feed followed by a carriage return'), |
|
| 1409 | - ), |
|
| 1410 | - array( |
|
| 1411 | - 'char' => $lf, |
|
| 1412 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1413 | - 'description' => t('Line feed'), |
|
| 1414 | - ), |
|
| 1415 | - array( |
|
| 1416 | - 'char' => $cr, |
|
| 1417 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1418 | - 'description' => t('Carriage Return'), |
|
| 1419 | - ), |
|
| 1399 | + self::$eolChars = array( |
|
| 1400 | + array( |
|
| 1401 | + 'char' => $cr.$lf, |
|
| 1402 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1403 | + 'description' => t('Carriage return followed by a line feed'), |
|
| 1404 | + ), |
|
| 1405 | + array( |
|
| 1406 | + 'char' => $lf.$cr, |
|
| 1407 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1408 | + 'description' => t('Line feed followed by a carriage return'), |
|
| 1409 | + ), |
|
| 1410 | + array( |
|
| 1411 | + 'char' => $lf, |
|
| 1412 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1413 | + 'description' => t('Line feed'), |
|
| 1414 | + ), |
|
| 1415 | + array( |
|
| 1416 | + 'char' => $cr, |
|
| 1417 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1418 | + 'description' => t('Carriage Return'), |
|
| 1419 | + ), |
|
| 1420 | 1420 | ); |
| 1421 | 1421 | } |
| 1422 | 1422 | |
@@ -1444,13 +1444,13 @@ discard block |
||
| 1444 | 1444 | ); |
| 1445 | 1445 | } |
| 1446 | 1446 | |
| 1447 | - /** |
|
| 1448 | - * Removes the specified keys from the target array, |
|
| 1449 | - * if they exist. |
|
| 1450 | - * |
|
| 1451 | - * @param array $array |
|
| 1452 | - * @param array $keys |
|
| 1453 | - */ |
|
| 1447 | + /** |
|
| 1448 | + * Removes the specified keys from the target array, |
|
| 1449 | + * if they exist. |
|
| 1450 | + * |
|
| 1451 | + * @param array $array |
|
| 1452 | + * @param array $keys |
|
| 1453 | + */ |
|
| 1454 | 1454 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1455 | 1455 | { |
| 1456 | 1456 | foreach($keys as $key) |
@@ -1461,13 +1461,13 @@ discard block |
||
| 1461 | 1461 | } |
| 1462 | 1462 | } |
| 1463 | 1463 | |
| 1464 | - /** |
|
| 1465 | - * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1466 | - * Accepts both positive and negative integers. |
|
| 1467 | - * |
|
| 1468 | - * @param mixed $value |
|
| 1469 | - * @return bool |
|
| 1470 | - */ |
|
| 1464 | + /** |
|
| 1465 | + * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1466 | + * Accepts both positive and negative integers. |
|
| 1467 | + * |
|
| 1468 | + * @param mixed $value |
|
| 1469 | + * @return bool |
|
| 1470 | + */ |
|
| 1471 | 1471 | public static function isInteger($value) : bool |
| 1472 | 1472 | { |
| 1473 | 1473 | if(is_int($value)) { |
@@ -1487,52 +1487,52 @@ discard block |
||
| 1487 | 1487 | return false; |
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | - /** |
|
| 1491 | - * Converts an amount of seconds to a DateInterval object. |
|
| 1492 | - * |
|
| 1493 | - * @param int $seconds |
|
| 1494 | - * @return \DateInterval |
|
| 1495 | - * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
| 1496 | - * |
|
| 1497 | - * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
| 1498 | - */ |
|
| 1490 | + /** |
|
| 1491 | + * Converts an amount of seconds to a DateInterval object. |
|
| 1492 | + * |
|
| 1493 | + * @param int $seconds |
|
| 1494 | + * @return \DateInterval |
|
| 1495 | + * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
| 1496 | + * |
|
| 1497 | + * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
| 1498 | + */ |
|
| 1499 | 1499 | public static function seconds2interval(int $seconds) : \DateInterval |
| 1500 | 1500 | { |
| 1501 | 1501 | return ConvertHelper_DateInterval::fromSeconds($seconds)->getInterval(); |
| 1502 | 1502 | } |
| 1503 | 1503 | |
| 1504 | - /** |
|
| 1505 | - * Converts a size string like "50 MB" to the corresponding byte size. |
|
| 1506 | - * It is case insensitive, ignores spaces, and supports both traditional |
|
| 1507 | - * "MB" and "MiB" notations. |
|
| 1508 | - * |
|
| 1509 | - * @param string $size |
|
| 1510 | - * @return int |
|
| 1511 | - */ |
|
| 1504 | + /** |
|
| 1505 | + * Converts a size string like "50 MB" to the corresponding byte size. |
|
| 1506 | + * It is case insensitive, ignores spaces, and supports both traditional |
|
| 1507 | + * "MB" and "MiB" notations. |
|
| 1508 | + * |
|
| 1509 | + * @param string $size |
|
| 1510 | + * @return int |
|
| 1511 | + */ |
|
| 1512 | 1512 | public static function size2bytes(string $size) : int |
| 1513 | 1513 | { |
| 1514 | 1514 | return self::parseSize($size)->toBytes(); |
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | - /** |
|
| 1518 | - * Parses a size string like "50 MB" and returns a size notation instance |
|
| 1519 | - * that has utility methods to access information on it, and convert it. |
|
| 1520 | - * |
|
| 1521 | - * @param string $size |
|
| 1522 | - * @return ConvertHelper_SizeNotation |
|
| 1523 | - */ |
|
| 1517 | + /** |
|
| 1518 | + * Parses a size string like "50 MB" and returns a size notation instance |
|
| 1519 | + * that has utility methods to access information on it, and convert it. |
|
| 1520 | + * |
|
| 1521 | + * @param string $size |
|
| 1522 | + * @return ConvertHelper_SizeNotation |
|
| 1523 | + */ |
|
| 1524 | 1524 | public static function parseSize(string $size) : ConvertHelper_SizeNotation |
| 1525 | 1525 | { |
| 1526 | 1526 | return new ConvertHelper_SizeNotation($size); |
| 1527 | 1527 | } |
| 1528 | 1528 | |
| 1529 | - /** |
|
| 1530 | - * Creates a URL finder instance, which can be used to find |
|
| 1531 | - * URLs in a string - be it plain text, or HTML. |
|
| 1532 | - * |
|
| 1533 | - * @param string $subject |
|
| 1534 | - * @return ConvertHelper_URLFinder |
|
| 1535 | - */ |
|
| 1529 | + /** |
|
| 1530 | + * Creates a URL finder instance, which can be used to find |
|
| 1531 | + * URLs in a string - be it plain text, or HTML. |
|
| 1532 | + * |
|
| 1533 | + * @param string $subject |
|
| 1534 | + * @return ConvertHelper_URLFinder |
|
| 1535 | + */ |
|
| 1536 | 1536 | public static function createURLFinder(string $subject) : ConvertHelper_URLFinder |
| 1537 | 1537 | { |
| 1538 | 1538 | return new ConvertHelper_URLFinder($subject); |
@@ -32,39 +32,39 @@ discard block |
||
| 32 | 32 | const SECONDS_PER_MONTH_APPROX = 2505600; // imprecise - for 29 days, only for approximations. |
| 33 | 33 | const SECONDS_PER_YEAR = 31536000; |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | 38 | protected $dateFrom; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var int |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var int |
|
| 42 | + */ |
|
| 43 | 43 | protected $dateTo; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var bool |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var bool |
|
| 47 | + */ |
|
| 48 | 48 | protected $future = false; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 50 | + /** |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | 53 | protected $interval = ''; |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var int |
|
| 57 | - */ |
|
| 55 | + /** |
|
| 56 | + * @var int |
|
| 57 | + */ |
|
| 58 | 58 | protected $difference = 0; |
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @var int |
|
| 62 | - */ |
|
| 60 | + /** |
|
| 61 | + * @var int |
|
| 62 | + */ |
|
| 63 | 63 | protected $dateDiff = 0; |
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @var array|NULL |
|
| 67 | - */ |
|
| 65 | + /** |
|
| 66 | + * @var array|NULL |
|
| 67 | + */ |
|
| 68 | 68 | protected static $texts = null; |
| 69 | 69 | |
| 70 | 70 | public function __construct() |
@@ -84,17 +84,17 @@ discard block |
||
| 84 | 84 | self::$texts = null; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Sets the origin date to calculate from. |
|
| 89 | - * |
|
| 90 | - * NOTE: if this is further in the future than |
|
| 91 | - * the to: date, it will be considered as a |
|
| 92 | - * calculation for something to come, i.e. |
|
| 93 | - * "In two days". |
|
| 94 | - * |
|
| 95 | - * @param \DateTime $date |
|
| 96 | - * @return ConvertHelper_DurationConverter |
|
| 97 | - */ |
|
| 87 | + /** |
|
| 88 | + * Sets the origin date to calculate from. |
|
| 89 | + * |
|
| 90 | + * NOTE: if this is further in the future than |
|
| 91 | + * the to: date, it will be considered as a |
|
| 92 | + * calculation for something to come, i.e. |
|
| 93 | + * "In two days". |
|
| 94 | + * |
|
| 95 | + * @param \DateTime $date |
|
| 96 | + * @return ConvertHelper_DurationConverter |
|
| 97 | + */ |
|
| 98 | 98 | public function setDateFrom(\DateTime $date) : ConvertHelper_DurationConverter |
| 99 | 99 | { |
| 100 | 100 | $this->dateFrom = ConvertHelper::date2timestamp($date); |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | return $this; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Sets the date to calculate to. Defaults to |
|
| 107 | - * the current time if not set. |
|
| 108 | - * |
|
| 109 | - * @param \DateTime $date |
|
| 110 | - * @return ConvertHelper_DurationConverter |
|
| 111 | - */ |
|
| 105 | + /** |
|
| 106 | + * Sets the date to calculate to. Defaults to |
|
| 107 | + * the current time if not set. |
|
| 108 | + * |
|
| 109 | + * @param \DateTime $date |
|
| 110 | + * @return ConvertHelper_DurationConverter |
|
| 111 | + */ |
|
| 112 | 112 | public function setDateTo(\DateTime $date) : ConvertHelper_DurationConverter |
| 113 | 113 | { |
| 114 | 114 | $this->dateTo = ConvertHelper::date2timestamp($date); |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | return $this; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Converts the specified dates to a human readable string. |
|
| 121 | - * |
|
| 122 | - * @throws ConvertHelper_Exception |
|
| 123 | - * @return string |
|
| 124 | - * |
|
| 125 | - * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
| 126 | - */ |
|
| 119 | + /** |
|
| 120 | + * Converts the specified dates to a human readable string. |
|
| 121 | + * |
|
| 122 | + * @throws ConvertHelper_Exception |
|
| 123 | + * @return string |
|
| 124 | + * |
|
| 125 | + * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
| 126 | + */ |
|
| 127 | 127 | public function convert() : string |
| 128 | 128 | { |
| 129 | 129 | $this->initTexts(); |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | const BASE_2 = 1024; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var ConvertHelper_StorageSizeEnum_Size[] |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var ConvertHelper_StorageSizeEnum_Size[] |
|
| 36 | + */ |
|
| 37 | 37 | protected static $sizes = array(); |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Initializes the supported unit notations, and |
|
| 41 | - * how they are supposed to be calculated. |
|
| 42 | - * |
|
| 43 | - * @see ConvertHelper_SizeNotation::parseSize() |
|
| 44 | - */ |
|
| 39 | + /** |
|
| 40 | + * Initializes the supported unit notations, and |
|
| 41 | + * how they are supposed to be calculated. |
|
| 42 | + * |
|
| 43 | + * @see ConvertHelper_SizeNotation::parseSize() |
|
| 44 | + */ |
|
| 45 | 45 | protected static function init() : void |
| 46 | 46 | { |
| 47 | 47 | if(!empty(self::$sizes)) { |
@@ -68,28 +68,28 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Called whenever the application locale is changed, |
|
| 73 | - * to reset the size definitions so the labels get |
|
| 74 | - * translated to the new locale. |
|
| 75 | - */ |
|
| 71 | + /** |
|
| 72 | + * Called whenever the application locale is changed, |
|
| 73 | + * to reset the size definitions so the labels get |
|
| 74 | + * translated to the new locale. |
|
| 75 | + */ |
|
| 76 | 76 | public static function handle_localeChanged() : void |
| 77 | 77 | { |
| 78 | 78 | self::$sizes = array(); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Adds a storage size to the internal collection. |
|
| 83 | - * |
|
| 84 | - * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
| 85 | - * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
| 86 | - * @param int $exponent The multiplier of the base to get the byte value |
|
| 87 | - * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
| 88 | - * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
| 89 | - * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
| 90 | - * |
|
| 91 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 92 | - */ |
|
| 81 | + /** |
|
| 82 | + * Adds a storage size to the internal collection. |
|
| 83 | + * |
|
| 84 | + * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
| 85 | + * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
| 86 | + * @param int $exponent The multiplier of the base to get the byte value |
|
| 87 | + * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
| 88 | + * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
| 89 | + * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
| 90 | + * |
|
| 91 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 92 | + */ |
|
| 93 | 93 | protected static function addSize(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) : void |
| 94 | 94 | { |
| 95 | 95 | self::$sizes[$name] = new ConvertHelper_StorageSizeEnum_Size( |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Retrieves all known sizes. |
|
| 107 | - * |
|
| 108 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 109 | - */ |
|
| 105 | + /** |
|
| 106 | + * Retrieves all known sizes. |
|
| 107 | + * |
|
| 108 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 109 | + */ |
|
| 110 | 110 | public static function getSizes() : array |
| 111 | 111 | { |
| 112 | 112 | self::init(); |
@@ -114,15 +114,15 @@ discard block |
||
| 114 | 114 | return self::$sizes; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Retrieves a size definition instance by its name. |
|
| 119 | - * |
|
| 120 | - * @param string $name Case insensitive. For example "kb", "MiB"... |
|
| 121 | - * @throws ConvertHelper_Exception |
|
| 122 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
| 123 | - * |
|
| 124 | - * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
| 125 | - */ |
|
| 117 | + /** |
|
| 118 | + * Retrieves a size definition instance by its name. |
|
| 119 | + * |
|
| 120 | + * @param string $name Case insensitive. For example "kb", "MiB"... |
|
| 121 | + * @throws ConvertHelper_Exception |
|
| 122 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
| 123 | + * |
|
| 124 | + * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
| 125 | + */ |
|
| 126 | 126 | public static function getSizeByName(string $name) : ConvertHelper_StorageSizeEnum_Size |
| 127 | 127 | { |
| 128 | 128 | self::init(); |
@@ -144,10 +144,10 @@ discard block |
||
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 147 | + /** |
|
| 148 | + * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | 151 | public static function getSizeNames() : array |
| 152 | 152 | { |
| 153 | 153 | self::init(); |
@@ -155,16 +155,16 @@ discard block |
||
| 155 | 155 | return array_keys(self::$sizes); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Retrieves all available storage sizes for the specified |
|
| 160 | - * base value. |
|
| 161 | - * |
|
| 162 | - * @param int $base |
|
| 163 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 164 | - * |
|
| 165 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 166 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 167 | - */ |
|
| 158 | + /** |
|
| 159 | + * Retrieves all available storage sizes for the specified |
|
| 160 | + * base value. |
|
| 161 | + * |
|
| 162 | + * @param int $base |
|
| 163 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 164 | + * |
|
| 165 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 166 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 167 | + */ |
|
| 168 | 168 | public static function getSizesByBase(int $base) : array |
| 169 | 169 | { |
| 170 | 170 | self::init(); |
@@ -23,37 +23,37 @@ |
||
| 23 | 23 | { |
| 24 | 24 | const ERROR_NOT_LOADED_YET = 56501; |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var \SimpleXMLElement|NULL |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var \SimpleXMLElement|NULL |
|
| 28 | + */ |
|
| 29 | 29 | private $element = null; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var XMLHelper_SimpleXML_Error[] |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var XMLHelper_SimpleXML_Error[] |
|
| 33 | + */ |
|
| 34 | 34 | private $errors = array(); |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Creates a simplexml instance from an XML string. |
|
| 38 | - * |
|
| 39 | - * NOTE: returns false in case of a fatal error. |
|
| 40 | - * |
|
| 41 | - * @param string $string |
|
| 42 | - * @return \SimpleXMLElement|NULL |
|
| 43 | - */ |
|
| 36 | + /** |
|
| 37 | + * Creates a simplexml instance from an XML string. |
|
| 38 | + * |
|
| 39 | + * NOTE: returns false in case of a fatal error. |
|
| 40 | + * |
|
| 41 | + * @param string $string |
|
| 42 | + * @return \SimpleXMLElement|NULL |
|
| 43 | + */ |
|
| 44 | 44 | public function loadString(string $string) : ?\SimpleXMLElement |
| 45 | 45 | { |
| 46 | 46 | return $this->load('string', $string); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Creates a simplexml instance from an XML file. |
|
| 51 | - * |
|
| 52 | - * NOTE: returns false in case of a fatal error. |
|
| 53 | - * |
|
| 54 | - * @param string $file |
|
| 55 | - * @return \SimpleXMLElement|NULL |
|
| 56 | - */ |
|
| 49 | + /** |
|
| 50 | + * Creates a simplexml instance from an XML file. |
|
| 51 | + * |
|
| 52 | + * NOTE: returns false in case of a fatal error. |
|
| 53 | + * |
|
| 54 | + * @param string $file |
|
| 55 | + * @return \SimpleXMLElement|NULL |
|
| 56 | + */ |
|
| 57 | 57 | public function loadFile(string $file) : ?\SimpleXMLElement |
| 58 | 58 | { |
| 59 | 59 | return $this->load('file', $file); |
@@ -24,9 +24,9 @@ |
||
| 24 | 24 | const ERROR_CANNOT_UNSERIALIZE_ERROR_DATA = 57201; |
| 25 | 25 | const ERROR_ERROR_DATA_KEY_MISSING = 57202; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var \LibXMLError |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var \LibXMLError |
|
| 29 | + */ |
|
| 30 | 30 | private $error; |
| 31 | 31 | |
| 32 | 32 | private static $requiredKeys = array( |