@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class ConvertHelper_ByteConverter |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var int |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var int |
|
| 28 | + */ |
|
| 29 | 29 | protected $bytes; |
| 30 | 30 | |
| 31 | 31 | public function __construct(int $bytes) |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Detects the size matching the byte value for the specified base. |
|
| 44 | - * |
|
| 45 | - * @param int $base |
|
| 46 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
| 47 | - */ |
|
| 42 | + /** |
|
| 43 | + * Detects the size matching the byte value for the specified base. |
|
| 44 | + * |
|
| 45 | + * @param int $base |
|
| 46 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
| 47 | + */ |
|
| 48 | 48 | protected function detectSize(int $base) : ConvertHelper_StorageSizeEnum_Size |
| 49 | 49 | { |
| 50 | 50 | $sizes = $this->getSizesSorted($base); |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | return ConvertHelper_StorageSizeEnum::getSizeByName('b'); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Retrieves all storage sizes for the specified base, |
|
| 75 | - * sorted from smallest byte size to highest. |
|
| 76 | - * |
|
| 77 | - * @param int $base |
|
| 78 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 79 | - */ |
|
| 73 | + /** |
|
| 74 | + * Retrieves all storage sizes for the specified base, |
|
| 75 | + * sorted from smallest byte size to highest. |
|
| 76 | + * |
|
| 77 | + * @param int $base |
|
| 78 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 79 | + */ |
|
| 80 | 80 | protected function getSizesSorted(int $base) |
| 81 | 81 | { |
| 82 | 82 | $sizes = ConvertHelper_StorageSizeEnum::getSizesByBase($base); |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | return $sizes; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Converts the byte value to a human readable string, e.g. "5 KB", "140 MB". |
|
| 94 | - * |
|
| 95 | - * @param int $precision The amount of decimals (rounded up) |
|
| 96 | - * @param int $base The base to calculate bytes with. |
|
| 97 | - * @return string |
|
| 98 | - * |
|
| 99 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 100 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 101 | - */ |
|
| 92 | + /** |
|
| 93 | + * Converts the byte value to a human readable string, e.g. "5 KB", "140 MB". |
|
| 94 | + * |
|
| 95 | + * @param int $precision The amount of decimals (rounded up) |
|
| 96 | + * @param int $base The base to calculate bytes with. |
|
| 97 | + * @return string |
|
| 98 | + * |
|
| 99 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 100 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 101 | + */ |
|
| 102 | 102 | public function toString(int $precision, int $base=ConvertHelper_StorageSizeEnum::BASE_10) : string |
| 103 | 103 | { |
| 104 | 104 | $size = $this->detectSize($base); |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | return round($this->bytes / $size->getBytes(), $precision) . ' ' . $size->getSuffix(); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Converts the byte value to the amount of the corresponding units (KB, MB...). |
|
| 111 | - * |
|
| 112 | - * @param int $precision The amount of decimals (rounded up) |
|
| 113 | - * @param string $sizeName The lowercase storage size name (e.g. "kb", "kib") |
|
| 114 | - * @return float |
|
| 115 | - */ |
|
| 109 | + /** |
|
| 110 | + * Converts the byte value to the amount of the corresponding units (KB, MB...). |
|
| 111 | + * |
|
| 112 | + * @param int $precision The amount of decimals (rounded up) |
|
| 113 | + * @param string $sizeName The lowercase storage size name (e.g. "kb", "kib") |
|
| 114 | + * @return float |
|
| 115 | + */ |
|
| 116 | 116 | public function toNumber(int $precision, string $sizeName) : float |
| 117 | 117 | { |
| 118 | 118 | $size = ConvertHelper_StorageSizeEnum::getSizeByName($sizeName); |
@@ -120,56 +120,56 @@ discard block |
||
| 120 | 120 | return round($this->bytes / $size->getBytes(), $precision); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Converts the bytes to Kilobytes. |
|
| 125 | - * |
|
| 126 | - * @param int $precision Amount of decimals (rounded up) |
|
| 127 | - * @return float |
|
| 128 | - */ |
|
| 123 | + /** |
|
| 124 | + * Converts the bytes to Kilobytes. |
|
| 125 | + * |
|
| 126 | + * @param int $precision Amount of decimals (rounded up) |
|
| 127 | + * @return float |
|
| 128 | + */ |
|
| 129 | 129 | public function toKilobytes(int $precision=1) : float |
| 130 | 130 | { |
| 131 | 131 | return $this->toNumber($precision, 'kb'); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Converts the bytes to Megabytes. |
|
| 136 | - * |
|
| 137 | - * @param int $precision Amount of decimals (rounded up) |
|
| 138 | - * @return float |
|
| 139 | - */ |
|
| 134 | + /** |
|
| 135 | + * Converts the bytes to Megabytes. |
|
| 136 | + * |
|
| 137 | + * @param int $precision Amount of decimals (rounded up) |
|
| 138 | + * @return float |
|
| 139 | + */ |
|
| 140 | 140 | public function toMegabytes(int $precision=1) : float |
| 141 | 141 | { |
| 142 | 142 | return $this->toNumber($precision, 'mb'); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Converts the bytes to Gigabytes. |
|
| 147 | - * |
|
| 148 | - * @param int $precision Amount of decimals (rounded up) |
|
| 149 | - * @return float |
|
| 150 | - */ |
|
| 145 | + /** |
|
| 146 | + * Converts the bytes to Gigabytes. |
|
| 147 | + * |
|
| 148 | + * @param int $precision Amount of decimals (rounded up) |
|
| 149 | + * @return float |
|
| 150 | + */ |
|
| 151 | 151 | public function toGigabytes(int $precision=1) : float |
| 152 | 152 | { |
| 153 | 153 | return $this->toNumber($precision, 'gb'); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Converts the bytes to Terabytes. |
|
| 158 | - * |
|
| 159 | - * @param int $precision Amount of decimals (rounded up) |
|
| 160 | - * @return float |
|
| 161 | - */ |
|
| 156 | + /** |
|
| 157 | + * Converts the bytes to Terabytes. |
|
| 158 | + * |
|
| 159 | + * @param int $precision Amount of decimals (rounded up) |
|
| 160 | + * @return float |
|
| 161 | + */ |
|
| 162 | 162 | public function toTerabytes(int $precision=1) : float |
| 163 | 163 | { |
| 164 | 164 | return $this->toNumber($precision, 'tb'); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Converts the bytes to Petabytes. |
|
| 169 | - * |
|
| 170 | - * @param int $precision Amount of decimals (rounded up) |
|
| 171 | - * @return float |
|
| 172 | - */ |
|
| 167 | + /** |
|
| 168 | + * Converts the bytes to Petabytes. |
|
| 169 | + * |
|
| 170 | + * @param int $precision Amount of decimals (rounded up) |
|
| 171 | + * @return float |
|
| 172 | + */ |
|
| 173 | 173 | public function toPetabytes(int $precision=1) : float |
| 174 | 174 | { |
| 175 | 175 | return $this->toNumber($precision, 'pb'); |
@@ -25,34 +25,34 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class ConvertHelper_StorageSizeEnum_Size |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | 31 | protected $name; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var int |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var int |
|
| 35 | + */ |
|
| 36 | 36 | protected $base; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var int |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var int |
|
| 40 | + */ |
|
| 41 | 41 | protected $exponent; |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | 46 | protected $singular; |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 48 | + /** |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | 51 | protected $plural; |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 53 | + /** |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | 56 | protected $suffix; |
| 57 | 57 | |
| 58 | 58 | public function __construct(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | const VALIDATION_ERROR_NEGATIVE_VALUE = 43803; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | 37 | protected $sizeString; |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -41,41 +41,41 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | protected $sizeDefinition; |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var integer |
|
| 46 | - */ |
|
| 44 | + /** |
|
| 45 | + * @var integer |
|
| 46 | + */ |
|
| 47 | 47 | protected $bytes = 0; |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var bool |
|
| 51 | - */ |
|
| 49 | + /** |
|
| 50 | + * @var bool |
|
| 51 | + */ |
|
| 52 | 52 | protected $valid = true; |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 54 | + /** |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | 57 | protected $units = null; |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 59 | + /** |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | protected $number = ''; |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 64 | + /** |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | 67 | protected $errorMessage = ''; |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var int |
|
| 71 | - */ |
|
| 69 | + /** |
|
| 70 | + * @var int |
|
| 71 | + */ |
|
| 72 | 72 | protected $errorCode = 0; |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Create a new instance for the specified size string. |
|
| 76 | - * |
|
| 77 | - * @param string $sizeString A size notation in the format "50 MB", or a number of bytes without units. Spaces are ignored, so "50MB" = "50 MB" = " 50 MB ". Floating point values are accepted, both with dot and comma notation ("50.5" = "50,5"). To use Base 2 values, ose appropriate units, e.g. "50 MiB", "1.5 GiB". The units are case insensitive, so "50 MB" = "50 mb". |
|
| 78 | - */ |
|
| 74 | + /** |
|
| 75 | + * Create a new instance for the specified size string. |
|
| 76 | + * |
|
| 77 | + * @param string $sizeString A size notation in the format "50 MB", or a number of bytes without units. Spaces are ignored, so "50MB" = "50 MB" = " 50 MB ". Floating point values are accepted, both with dot and comma notation ("50.5" = "50,5"). To use Base 2 values, ose appropriate units, e.g. "50 MiB", "1.5 GiB". The units are case insensitive, so "50 MB" = "50 mb". |
|
| 78 | + */ |
|
| 79 | 79 | public function __construct(string $sizeString) |
| 80 | 80 | { |
| 81 | 81 | $this->sizeString = $this->cleanString($sizeString); |
@@ -83,31 +83,31 @@ discard block |
||
| 83 | 83 | $this->convert(); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Gets the amount of bytes contained in the size notation. |
|
| 88 | - * @return int |
|
| 89 | - */ |
|
| 86 | + /** |
|
| 87 | + * Gets the amount of bytes contained in the size notation. |
|
| 88 | + * @return int |
|
| 89 | + */ |
|
| 90 | 90 | public function toBytes() : int |
| 91 | 91 | { |
| 92 | 92 | return $this->bytes; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Converts the size notation to a human readable string, e.g. "50 MB". |
|
| 97 | - * |
|
| 98 | - * @param int $precision |
|
| 99 | - * @return string |
|
| 100 | - * @see ConvertHelper::bytes2readable() |
|
| 101 | - */ |
|
| 95 | + /** |
|
| 96 | + * Converts the size notation to a human readable string, e.g. "50 MB". |
|
| 97 | + * |
|
| 98 | + * @param int $precision |
|
| 99 | + * @return string |
|
| 100 | + * @see ConvertHelper::bytes2readable() |
|
| 101 | + */ |
|
| 102 | 102 | public function toString(int $precision=1) : string |
| 103 | 103 | { |
| 104 | 104 | return ConvertHelper::bytes2readable($this->bytes, $precision, $this->getBase()); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Retrieves the detected number's base. |
|
| 109 | - * @return int The base number (1000 for Base 10, or 1024 for Base 2), or 0 if it is not valid. |
|
| 110 | - */ |
|
| 107 | + /** |
|
| 108 | + * Retrieves the detected number's base. |
|
| 109 | + * @return int The base number (1000 for Base 10, or 1024 for Base 2), or 0 if it is not valid. |
|
| 110 | + */ |
|
| 111 | 111 | public function getBase() : int |
| 112 | 112 | { |
| 113 | 113 | if($this->isValid()) { |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | return 0; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Retrieves the detected storage size instance, if |
|
| 122 | - * the size string is valid. |
|
| 123 | - * |
|
| 124 | - * @return ConvertHelper_StorageSizeEnum_Size|NULL |
|
| 125 | - * @see ConvertHelper_StorageSizeEnum_Size |
|
| 126 | - */ |
|
| 120 | + /** |
|
| 121 | + * Retrieves the detected storage size instance, if |
|
| 122 | + * the size string is valid. |
|
| 123 | + * |
|
| 124 | + * @return ConvertHelper_StorageSizeEnum_Size|NULL |
|
| 125 | + * @see ConvertHelper_StorageSizeEnum_Size |
|
| 126 | + */ |
|
| 127 | 127 | public function getSizeDefinition() : ?ConvertHelper_StorageSizeEnum_Size |
| 128 | 128 | { |
| 129 | 129 | if($this->isValid()) { |
@@ -133,27 +133,27 @@ discard block |
||
| 133 | 133 | return null; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Checks whether the size notation was valid and could be parsed |
|
| 138 | - * into a meaningful byte value. If this returns `false`, it is |
|
| 139 | - * possible to use the `getErrorXXX` methods to retrieve information |
|
| 140 | - * on what went wrong. |
|
| 141 | - * |
|
| 142 | - * @return bool |
|
| 143 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 144 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 145 | - */ |
|
| 136 | + /** |
|
| 137 | + * Checks whether the size notation was valid and could be parsed |
|
| 138 | + * into a meaningful byte value. If this returns `false`, it is |
|
| 139 | + * possible to use the `getErrorXXX` methods to retrieve information |
|
| 140 | + * on what went wrong. |
|
| 141 | + * |
|
| 142 | + * @return bool |
|
| 143 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 144 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 145 | + */ |
|
| 146 | 146 | public function isValid() : bool |
| 147 | 147 | { |
| 148 | 148 | return $this->valid; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Retrieves the error message if the size notation validation failed. |
|
| 153 | - * |
|
| 154 | - * @return string |
|
| 155 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 156 | - */ |
|
| 151 | + /** |
|
| 152 | + * Retrieves the error message if the size notation validation failed. |
|
| 153 | + * |
|
| 154 | + * @return string |
|
| 155 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 156 | + */ |
|
| 157 | 157 | public function getErrorMessage() : string |
| 158 | 158 | { |
| 159 | 159 | return $this->errorMessage; |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | ); |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * Detects the units and the number in the size notation string. |
|
| 205 | - * Populates the `units` and `number` properties. |
|
| 206 | - * |
|
| 207 | - * @return bool Whether the string could be parsed successfully. |
|
| 208 | - */ |
|
| 203 | + /** |
|
| 204 | + * Detects the units and the number in the size notation string. |
|
| 205 | + * Populates the `units` and `number` properties. |
|
| 206 | + * |
|
| 207 | + * @return bool Whether the string could be parsed successfully. |
|
| 208 | + */ |
|
| 209 | 209 | protected function detectParts() : bool |
| 210 | 210 | { |
| 211 | 211 | $units = ConvertHelper_StorageSizeEnum::getSizeNames(); |
@@ -241,16 +241,16 @@ discard block |
||
| 241 | 241 | return true; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * If the validation fails, this is used to store the reason for retrieval later. |
|
| 246 | - * |
|
| 247 | - * @param string $message |
|
| 248 | - * @param int $code |
|
| 249 | - * |
|
| 250 | - * @see ConvertHelper_SizeNotation::isValid() |
|
| 251 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 252 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 253 | - */ |
|
| 244 | + /** |
|
| 245 | + * If the validation fails, this is used to store the reason for retrieval later. |
|
| 246 | + * |
|
| 247 | + * @param string $message |
|
| 248 | + * @param int $code |
|
| 249 | + * |
|
| 250 | + * @see ConvertHelper_SizeNotation::isValid() |
|
| 251 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 252 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 253 | + */ |
|
| 254 | 254 | protected function setError(string $message, int $code) : void |
| 255 | 255 | { |
| 256 | 256 | $this->valid = false; |
@@ -258,12 +258,12 @@ discard block |
||
| 258 | 258 | $this->errorCode = $code; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Retrieves the error code, if the size notation validation failed. |
|
| 263 | - * |
|
| 264 | - * @return int |
|
| 265 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 266 | - */ |
|
| 261 | + /** |
|
| 262 | + * Retrieves the error code, if the size notation validation failed. |
|
| 263 | + * |
|
| 264 | + * @return int |
|
| 265 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 266 | + */ |
|
| 267 | 267 | public function getErrorCode() : int |
| 268 | 268 | { |
| 269 | 269 | return $this->errorCode; |
@@ -20,24 +20,24 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class URLInfo_Parser |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | 26 | protected $url; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var bool |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var bool |
|
| 30 | + */ |
|
| 31 | 31 | protected $isValid = false; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | 36 | protected $info; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var array|NULL |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var array|NULL |
|
| 40 | + */ |
|
| 41 | 41 | protected $error; |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | return false; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Goes through all information in the parse_url result |
|
| 182 | - * array, and attempts to fix any user errors in formatting |
|
| 183 | - * that can be recovered from, mostly regarding stray spaces. |
|
| 184 | - */ |
|
| 180 | + /** |
|
| 181 | + * Goes through all information in the parse_url result |
|
| 182 | + * array, and attempts to fix any user errors in formatting |
|
| 183 | + * that can be recovered from, mostly regarding stray spaces. |
|
| 184 | + */ |
|
| 185 | 185 | protected function filterParsed() |
| 186 | 186 | { |
| 187 | 187 | foreach($this->info as $key => $val) |
@@ -20,9 +20,9 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class URLInfo_Highlighter |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var URLInfo |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var URLInfo |
|
| 25 | + */ |
|
| 26 | 26 | protected $info; |
| 27 | 27 | |
| 28 | 28 | public function __construct(URLInfo $info) |
@@ -39,9 +39,9 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | protected static $instance; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $baseURL = ''; |
| 46 | 46 | |
| 47 | 47 | public function __construct() |
@@ -51,10 +51,10 @@ discard block |
||
| 51 | 51 | $this->init(); |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Can be extended in a subclass, to avoid |
|
| 56 | - * redefining the constructor. |
|
| 57 | - */ |
|
| 54 | + /** |
|
| 55 | + * Can be extended in a subclass, to avoid |
|
| 56 | + * redefining the constructor. |
|
| 57 | + */ |
|
| 58 | 58 | protected function init() |
| 59 | 59 | { |
| 60 | 60 | |
@@ -124,12 +124,12 @@ discard block |
||
| 124 | 124 | return $this->buildURL($params, $dispatcher); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Retrieves the name of the current dispatcher script / page. |
|
| 129 | - * This is made to be extended and implemented in a subclass. |
|
| 130 | - * |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 127 | + /** |
|
| 128 | + * Retrieves the name of the current dispatcher script / page. |
|
| 129 | + * This is made to be extended and implemented in a subclass. |
|
| 130 | + * |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | 133 | public function getDispatcher() : string |
| 134 | 134 | { |
| 135 | 135 | return ''; |
@@ -198,10 +198,10 @@ discard block |
||
| 198 | 198 | return $url; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Retrieves the base URL of the application. |
|
| 203 | - * @return string |
|
| 204 | - */ |
|
| 201 | + /** |
|
| 202 | + * Retrieves the base URL of the application. |
|
| 203 | + * @return string |
|
| 204 | + */ |
|
| 205 | 205 | public function getBaseURL() : string |
| 206 | 206 | { |
| 207 | 207 | return $this->baseURL; |
@@ -231,13 +231,13 @@ discard block |
||
| 231 | 231 | return $this->knownParams[$name]; |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Retrieves a previously registered parameter instance. |
|
| 236 | - * |
|
| 237 | - * @param string $name |
|
| 238 | - * @throws Request_Exception |
|
| 239 | - * @return Request_Param |
|
| 240 | - */ |
|
| 234 | + /** |
|
| 235 | + * Retrieves a previously registered parameter instance. |
|
| 236 | + * |
|
| 237 | + * @param string $name |
|
| 238 | + * @throws Request_Exception |
|
| 239 | + * @return Request_Param |
|
| 240 | + */ |
|
| 241 | 241 | public function getRegisteredParam(string $name) : Request_Param |
| 242 | 242 | { |
| 243 | 243 | if(isset($this->knownParams[$name])) { |
@@ -254,48 +254,48 @@ discard block |
||
| 254 | 254 | ); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - /** |
|
| 258 | - * Checks whether a parameter with the specified name |
|
| 259 | - * has been registered. |
|
| 260 | - * |
|
| 261 | - * @param string $name |
|
| 262 | - * @return bool |
|
| 263 | - */ |
|
| 257 | + /** |
|
| 258 | + * Checks whether a parameter with the specified name |
|
| 259 | + * has been registered. |
|
| 260 | + * |
|
| 261 | + * @param string $name |
|
| 262 | + * @return bool |
|
| 263 | + */ |
|
| 264 | 264 | public function hasRegisteredParam(string $name) : bool |
| 265 | 265 | { |
| 266 | 266 | return isset($this->knownParams[$name]); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Retrieves an indexed array with accept mime types |
|
| 271 | - * that the client sent, in the order of preference |
|
| 272 | - * the client specified. |
|
| 273 | - * |
|
| 274 | - * Example: |
|
| 275 | - * |
|
| 276 | - * array( |
|
| 277 | - * 'text/html', |
|
| 278 | - * 'application/xhtml+xml', |
|
| 279 | - * 'image/webp' |
|
| 280 | - * ... |
|
| 281 | - * ) |
|
| 282 | - * |
|
| 283 | - * @return array |
|
| 284 | - * @see Request::parseAcceptHeaders() |
|
| 285 | - */ |
|
| 269 | + /** |
|
| 270 | + * Retrieves an indexed array with accept mime types |
|
| 271 | + * that the client sent, in the order of preference |
|
| 272 | + * the client specified. |
|
| 273 | + * |
|
| 274 | + * Example: |
|
| 275 | + * |
|
| 276 | + * array( |
|
| 277 | + * 'text/html', |
|
| 278 | + * 'application/xhtml+xml', |
|
| 279 | + * 'image/webp' |
|
| 280 | + * ... |
|
| 281 | + * ) |
|
| 282 | + * |
|
| 283 | + * @return array |
|
| 284 | + * @see Request::parseAcceptHeaders() |
|
| 285 | + */ |
|
| 286 | 286 | public static function getAcceptHeaders() : array |
| 287 | 287 | { |
| 288 | 288 | return self::parseAcceptHeaders()->getMimeStrings(); |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | - /** |
|
| 292 | - * Returns an instance of the accept headers parser, |
|
| 293 | - * to access information on the browser's accepted |
|
| 294 | - * mime types. |
|
| 295 | - * |
|
| 296 | - * @return Request_AcceptHeaders |
|
| 297 | - * @see Request::getAcceptHeaders() |
|
| 298 | - */ |
|
| 291 | + /** |
|
| 292 | + * Returns an instance of the accept headers parser, |
|
| 293 | + * to access information on the browser's accepted |
|
| 294 | + * mime types. |
|
| 295 | + * |
|
| 296 | + * @return Request_AcceptHeaders |
|
| 297 | + * @see Request::getAcceptHeaders() |
|
| 298 | + */ |
|
| 299 | 299 | public static function parseAcceptHeaders() : Request_AcceptHeaders |
| 300 | 300 | { |
| 301 | 301 | static $accept; |
@@ -343,14 +343,14 @@ discard block |
||
| 343 | 343 | return false; |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - /** |
|
| 347 | - * Removes a single parameter from the request. |
|
| 348 | - * If the parameter has been registered, also |
|
| 349 | - * removes the registration info. |
|
| 350 | - * |
|
| 351 | - * @param string $name |
|
| 352 | - * @return Request |
|
| 353 | - */ |
|
| 346 | + /** |
|
| 347 | + * Removes a single parameter from the request. |
|
| 348 | + * If the parameter has been registered, also |
|
| 349 | + * removes the registration info. |
|
| 350 | + * |
|
| 351 | + * @param string $name |
|
| 352 | + * @return Request |
|
| 353 | + */ |
|
| 354 | 354 | public function removeParam(string $name) : Request |
| 355 | 355 | { |
| 356 | 356 | if(isset($_REQUEST[$name])) { |
@@ -364,12 +364,12 @@ discard block |
||
| 364 | 364 | return $this; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | - /** |
|
| 368 | - * Removes several parameters from the request. |
|
| 369 | - * |
|
| 370 | - * @param string[] $names |
|
| 371 | - * @return Request |
|
| 372 | - */ |
|
| 367 | + /** |
|
| 368 | + * Removes several parameters from the request. |
|
| 369 | + * |
|
| 370 | + * @param string[] $names |
|
| 371 | + * @return Request |
|
| 372 | + */ |
|
| 373 | 373 | public function removeParams(array $names) : Request |
| 374 | 374 | { |
| 375 | 375 | foreach($names as $name) { |
@@ -434,18 +434,18 @@ discard block |
||
| 434 | 434 | return $val; |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - /** |
|
| 438 | - * Treats the request parameter as a JSON string, and |
|
| 439 | - * if it exists and contains valid JSON, returns the |
|
| 440 | - * decoded JSON value as an array (default). |
|
| 441 | - * |
|
| 442 | - * @param string $name |
|
| 443 | - * @param bool $assoc |
|
| 444 | - * @return array|object |
|
| 445 | - * |
|
| 446 | - * @see Request::getJSONAssoc() |
|
| 447 | - * @see Request::getJSONObject() |
|
| 448 | - */ |
|
| 437 | + /** |
|
| 438 | + * Treats the request parameter as a JSON string, and |
|
| 439 | + * if it exists and contains valid JSON, returns the |
|
| 440 | + * decoded JSON value as an array (default). |
|
| 441 | + * |
|
| 442 | + * @param string $name |
|
| 443 | + * @param bool $assoc |
|
| 444 | + * @return array|object |
|
| 445 | + * |
|
| 446 | + * @see Request::getJSONAssoc() |
|
| 447 | + * @see Request::getJSONObject() |
|
| 448 | + */ |
|
| 449 | 449 | public function getJSON(string $name, bool $assoc=true) |
| 450 | 450 | { |
| 451 | 451 | $value = $this->getParam($name); |
@@ -470,13 +470,13 @@ discard block |
||
| 470 | 470 | return new \stdClass(); |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - /** |
|
| 474 | - * Like {@link Request::getJSON()}, but omitting the second |
|
| 475 | - * parameter. Use this for more readable code. |
|
| 476 | - * |
|
| 477 | - * @param string $name |
|
| 478 | - * @return array |
|
| 479 | - */ |
|
| 473 | + /** |
|
| 474 | + * Like {@link Request::getJSON()}, but omitting the second |
|
| 475 | + * parameter. Use this for more readable code. |
|
| 476 | + * |
|
| 477 | + * @param string $name |
|
| 478 | + * @return array |
|
| 479 | + */ |
|
| 480 | 480 | public function getJSONAssoc(string $name) : array |
| 481 | 481 | { |
| 482 | 482 | $result = $this->getJSON($name); |
@@ -487,13 +487,13 @@ discard block |
||
| 487 | 487 | return array(); |
| 488 | 488 | } |
| 489 | 489 | |
| 490 | - /** |
|
| 491 | - * Like {@link Request::getJSON()}, but omitting the second |
|
| 492 | - * parameter. Use this for more readable code. |
|
| 493 | - * |
|
| 494 | - * @param string $name |
|
| 495 | - * @return object |
|
| 496 | - */ |
|
| 490 | + /** |
|
| 491 | + * Like {@link Request::getJSON()}, but omitting the second |
|
| 492 | + * parameter. Use this for more readable code. |
|
| 493 | + * |
|
| 494 | + * @param string $name |
|
| 495 | + * @return object |
|
| 496 | + */ |
|
| 497 | 497 | public function getJSONObject(string $name) : object |
| 498 | 498 | { |
| 499 | 499 | $result = $this->getJSON($name, false); |
@@ -504,12 +504,12 @@ discard block |
||
| 504 | 504 | return new \stdClass(); |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | - /** |
|
| 508 | - * Sends a JSON response with the correct headers. |
|
| 509 | - * |
|
| 510 | - * @param array|string $data |
|
| 511 | - * @param bool $exit Whether to exit the script afterwards. |
|
| 512 | - */ |
|
| 507 | + /** |
|
| 508 | + * Sends a JSON response with the correct headers. |
|
| 509 | + * |
|
| 510 | + * @param array|string $data |
|
| 511 | + * @param bool $exit Whether to exit the script afterwards. |
|
| 512 | + */ |
|
| 513 | 513 | public static function sendJSON($data, bool $exit=true) |
| 514 | 514 | { |
| 515 | 515 | $payload = $data; |
@@ -529,12 +529,12 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | } |
| 531 | 531 | |
| 532 | - /** |
|
| 533 | - * Sends HTML to the browser with the correct headers. |
|
| 534 | - * |
|
| 535 | - * @param string $html |
|
| 536 | - * @param bool $exit Whether to exit the script afterwards. |
|
| 537 | - */ |
|
| 532 | + /** |
|
| 533 | + * Sends HTML to the browser with the correct headers. |
|
| 534 | + * |
|
| 535 | + * @param string $html |
|
| 536 | + * @param bool $exit Whether to exit the script afterwards. |
|
| 537 | + */ |
|
| 538 | 538 | public static function sendHTML(string $html, bool $exit=true) |
| 539 | 539 | { |
| 540 | 540 | header('Cache-Control: no-cache, must-revalidate'); |
@@ -549,16 +549,16 @@ discard block |
||
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - /** |
|
| 553 | - * Creates a new instance of the URL comparer, which can check |
|
| 554 | - * whether the specified URLs match, regardless of the order in |
|
| 555 | - * which the query parameters are, if any. |
|
| 556 | - * |
|
| 557 | - * @param string $sourceURL |
|
| 558 | - * @param string $targetURL |
|
| 559 | - * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
| 560 | - * @return Request_URLComparer |
|
| 561 | - */ |
|
| 552 | + /** |
|
| 553 | + * Creates a new instance of the URL comparer, which can check |
|
| 554 | + * whether the specified URLs match, regardless of the order in |
|
| 555 | + * which the query parameters are, if any. |
|
| 556 | + * |
|
| 557 | + * @param string $sourceURL |
|
| 558 | + * @param string $targetURL |
|
| 559 | + * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
| 560 | + * @return Request_URLComparer |
|
| 561 | + */ |
|
| 562 | 562 | public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
| 563 | 563 | { |
| 564 | 564 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
@@ -567,10 +567,10 @@ discard block |
||
| 567 | 567 | return $comparer; |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | - /** |
|
| 571 | - * Retrieves the full URL that was used to access the current page. |
|
| 572 | - * @return string |
|
| 573 | - */ |
|
| 570 | + /** |
|
| 571 | + * Retrieves the full URL that was used to access the current page. |
|
| 572 | + * @return string |
|
| 573 | + */ |
|
| 574 | 574 | public function getCurrentURL() : string |
| 575 | 575 | { |
| 576 | 576 | return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
@@ -28,20 +28,20 @@ discard block |
||
| 28 | 28 | $this->parse(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Retrieves an indexed array with accept mime types |
|
| 33 | - * that the client sent, in the order of preference |
|
| 34 | - * the client specified. |
|
| 35 | - * |
|
| 36 | - * Example: |
|
| 37 | - * |
|
| 38 | - * array( |
|
| 39 | - * 'text/html', |
|
| 40 | - * 'application/xhtml+xml', |
|
| 41 | - * 'image/webp' |
|
| 42 | - * ... |
|
| 43 | - * ) |
|
| 44 | - */ |
|
| 31 | + /** |
|
| 32 | + * Retrieves an indexed array with accept mime types |
|
| 33 | + * that the client sent, in the order of preference |
|
| 34 | + * the client specified. |
|
| 35 | + * |
|
| 36 | + * Example: |
|
| 37 | + * |
|
| 38 | + * array( |
|
| 39 | + * 'text/html', |
|
| 40 | + * 'application/xhtml+xml', |
|
| 41 | + * 'image/webp' |
|
| 42 | + * ... |
|
| 43 | + * ) |
|
| 44 | + */ |
|
| 45 | 45 | public function getMimeStrings() : array |
| 46 | 46 | { |
| 47 | 47 | $result = array(); |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | return $result; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Checks that an accept header string exists, and tries to parse it. |
|
| 59 | - */ |
|
| 57 | + /** |
|
| 58 | + * Checks that an accept header string exists, and tries to parse it. |
|
| 59 | + */ |
|
| 60 | 60 | protected function parse() : void |
| 61 | 61 | { |
| 62 | 62 | // we may be in a CLI environment where the headers |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | $this->headers = $this->parseHeader($_SERVER['HTTP_ACCEPT']); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Splits the accept header string and parses the mime types. |
|
| 73 | - * |
|
| 74 | - * @param string $acceptHeader |
|
| 75 | - */ |
|
| 71 | + /** |
|
| 72 | + * Splits the accept header string and parses the mime types. |
|
| 73 | + * |
|
| 74 | + * @param string $acceptHeader |
|
| 75 | + */ |
|
| 76 | 76 | protected function parseHeader(string $acceptHeader) : array |
| 77 | 77 | { |
| 78 | 78 | $tokens = preg_split('/\s*,\s*/', $acceptHeader); |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | return $accept; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Parses a single mime type entry. |
|
| 94 | - * |
|
| 95 | - * @param int $i The position in the accept string |
|
| 96 | - * @param string $mime The mime type |
|
| 97 | - * @return array |
|
| 98 | - */ |
|
| 92 | + /** |
|
| 93 | + * Parses a single mime type entry. |
|
| 94 | + * |
|
| 95 | + * @param int $i The position in the accept string |
|
| 96 | + * @param string $mime The mime type |
|
| 97 | + * @return array |
|
| 98 | + */ |
|
| 99 | 99 | protected function parseEntry(int $i, string $mime) : array |
| 100 | 100 | { |
| 101 | 101 | $entry = array( |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | return $entry; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Sorts the mime types collection, first by quality |
|
| 130 | - * and then by position in the list. |
|
| 131 | - * |
|
| 132 | - * @param array $a |
|
| 133 | - * @param array $b |
|
| 134 | - * @return number |
|
| 135 | - */ |
|
| 128 | + /** |
|
| 129 | + * Sorts the mime types collection, first by quality |
|
| 130 | + * and then by position in the list. |
|
| 131 | + * |
|
| 132 | + * @param array $a |
|
| 133 | + * @param array $b |
|
| 134 | + * @return number |
|
| 135 | + */ |
|
| 136 | 136 | protected function sortMimeTypes(array $a, array $b) |
| 137 | 137 | { |
| 138 | 138 | /* first tier: highest q factor wins */ |
@@ -22,9 +22,9 @@ |
||
| 22 | 22 | { |
| 23 | 23 | use Traits_Optionable; |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var Request_Param |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var Request_Param |
|
| 27 | + */ |
|
| 28 | 28 | protected $param; |
| 29 | 29 | |
| 30 | 30 | protected $value; |
@@ -114,18 +114,18 @@ discard block |
||
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Adds a callback as a validation method. The callback gets the |
|
| 119 | - * value to validate as first parameter, and any additional |
|
| 120 | - * parameters passed here get appended to that. |
|
| 121 | - * |
|
| 122 | - * The callback must return boolean true or false depending on |
|
| 123 | - * whether the value is valid. |
|
| 124 | - * |
|
| 125 | - * @param callable $callback |
|
| 126 | - * @param array $args |
|
| 127 | - * @return Request_Param |
|
| 128 | - */ |
|
| 117 | + /** |
|
| 118 | + * Adds a callback as a validation method. The callback gets the |
|
| 119 | + * value to validate as first parameter, and any additional |
|
| 120 | + * parameters passed here get appended to that. |
|
| 121 | + * |
|
| 122 | + * The callback must return boolean true or false depending on |
|
| 123 | + * whether the value is valid. |
|
| 124 | + * |
|
| 125 | + * @param callable $callback |
|
| 126 | + * @param array $args |
|
| 127 | + * @return Request_Param |
|
| 128 | + */ |
|
| 129 | 129 | public function setCallback($callback, array $args=array()) : Request_Param |
| 130 | 130 | { |
| 131 | 131 | if(!is_callable($callback)) { |
@@ -169,16 +169,16 @@ discard block |
||
| 169 | 169 | return $value; |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Validates the specified value using the validation type. Returns |
|
| 174 | - * the validated value. |
|
| 175 | - * |
|
| 176 | - * @param mixed $value |
|
| 177 | - * @param string $type |
|
| 178 | - * @param array $params |
|
| 179 | - * @throws Request_Exception |
|
| 180 | - * @return mixed |
|
| 181 | - */ |
|
| 172 | + /** |
|
| 173 | + * Validates the specified value using the validation type. Returns |
|
| 174 | + * the validated value. |
|
| 175 | + * |
|
| 176 | + * @param mixed $value |
|
| 177 | + * @param string $type |
|
| 178 | + * @param array $params |
|
| 179 | + * @throws Request_Exception |
|
| 180 | + * @return mixed |
|
| 181 | + */ |
|
| 182 | 182 | protected function validateType($value, string $type, array $params) |
| 183 | 183 | { |
| 184 | 184 | $class = '\AppUtils\Request_Param_Validator_'.ucfirst($type); |
@@ -276,13 +276,13 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | protected $valueType = self::VALUE_TYPE_STRING; |
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Sets the variable to contain a comma-separated list of integer IDs. |
|
| 281 | - * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
| 282 | - * <code>145</code>. |
|
| 283 | - * |
|
| 284 | - * @return Request_Param |
|
| 285 | - */ |
|
| 279 | + /** |
|
| 280 | + * Sets the variable to contain a comma-separated list of integer IDs. |
|
| 281 | + * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
| 282 | + * <code>145</code>. |
|
| 283 | + * |
|
| 284 | + * @return Request_Param |
|
| 285 | + */ |
|
| 286 | 286 | public function setIDList() |
| 287 | 287 | { |
| 288 | 288 | $this->valueType = self::VALUE_TYPE_ID_LIST; |
@@ -291,13 +291,13 @@ discard block |
||
| 291 | 291 | return $this; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - /** |
|
| 295 | - * Sets the variable to be an alias, as defined by the |
|
| 296 | - * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
| 297 | - * |
|
| 298 | - * @return Request_Param |
|
| 299 | - * @see RegexHelper::REGEX_ALIAS |
|
| 300 | - */ |
|
| 294 | + /** |
|
| 295 | + * Sets the variable to be an alias, as defined by the |
|
| 296 | + * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
| 297 | + * |
|
| 298 | + * @return Request_Param |
|
| 299 | + * @see RegexHelper::REGEX_ALIAS |
|
| 300 | + */ |
|
| 301 | 301 | public function setAlias() |
| 302 | 302 | { |
| 303 | 303 | return $this->setRegex(RegexHelper::REGEX_ALIAS); |
@@ -338,12 +338,12 @@ discard block |
||
| 338 | 338 | return $this->setValidation(self::VALIDATION_TYPE_ALPHA); |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * Sets the parameter value as a string containing lowercase |
|
| 343 | - * and/or uppercase letters, as well as numbers. |
|
| 344 | - * |
|
| 345 | - * @return Request_Param |
|
| 346 | - */ |
|
| 341 | + /** |
|
| 342 | + * Sets the parameter value as a string containing lowercase |
|
| 343 | + * and/or uppercase letters, as well as numbers. |
|
| 344 | + * |
|
| 345 | + * @return Request_Param |
|
| 346 | + */ |
|
| 347 | 347 | public function setAlnum() |
| 348 | 348 | { |
| 349 | 349 | return $this->setValidation(self::VALIDATION_TYPE_ALNUM); |
@@ -376,17 +376,17 @@ discard block |
||
| 376 | 376 | ); |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Only available for array values: the parameter must be |
|
| 381 | - * an array value, and the array may only contain values |
|
| 382 | - * specified in the values array. |
|
| 383 | - * |
|
| 384 | - * Submitted values that are not in the allowed list of |
|
| 385 | - * values are stripped from the value. |
|
| 386 | - * |
|
| 387 | - * @param array $values List of allowed values |
|
| 388 | - * @return \AppUtils\Request_Param |
|
| 389 | - */ |
|
| 379 | + /** |
|
| 380 | + * Only available for array values: the parameter must be |
|
| 381 | + * an array value, and the array may only contain values |
|
| 382 | + * specified in the values array. |
|
| 383 | + * |
|
| 384 | + * Submitted values that are not in the allowed list of |
|
| 385 | + * values are stripped from the value. |
|
| 386 | + * |
|
| 387 | + * @param array $values List of allowed values |
|
| 388 | + * @return \AppUtils\Request_Param |
|
| 389 | + */ |
|
| 390 | 390 | public function setValuesList(array $values) |
| 391 | 391 | { |
| 392 | 392 | $this->setArray(); |
@@ -404,53 +404,53 @@ discard block |
||
| 404 | 404 | return $this->setValidation(self::VALIDATION_TYPE_ARRAY); |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - /** |
|
| 408 | - * Specifies that a JSON-encoded string is expected. |
|
| 409 | - * |
|
| 410 | - * NOTE: Numbers or quoted strings are technically valid |
|
| 411 | - * JSON, but are not accepted, because it is assumed |
|
| 412 | - * at least an array or object are expected. |
|
| 413 | - * |
|
| 414 | - * @return \AppUtils\Request_Param |
|
| 415 | - */ |
|
| 407 | + /** |
|
| 408 | + * Specifies that a JSON-encoded string is expected. |
|
| 409 | + * |
|
| 410 | + * NOTE: Numbers or quoted strings are technically valid |
|
| 411 | + * JSON, but are not accepted, because it is assumed |
|
| 412 | + * at least an array or object are expected. |
|
| 413 | + * |
|
| 414 | + * @return \AppUtils\Request_Param |
|
| 415 | + */ |
|
| 416 | 416 | public function setJSON() : Request_Param |
| 417 | 417 | { |
| 418 | 418 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => true)); |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * Like {@link Request_Param::setJSON()}, but accepts |
|
| 423 | - * only JSON objects. Arrays will not be accepted. |
|
| 424 | - * |
|
| 425 | - * @return \AppUtils\Request_Param |
|
| 426 | - */ |
|
| 421 | + /** |
|
| 422 | + * Like {@link Request_Param::setJSON()}, but accepts |
|
| 423 | + * only JSON objects. Arrays will not be accepted. |
|
| 424 | + * |
|
| 425 | + * @return \AppUtils\Request_Param |
|
| 426 | + */ |
|
| 427 | 427 | public function setJSONObject() : Request_Param |
| 428 | 428 | { |
| 429 | 429 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => false)); |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | - /** |
|
| 433 | - * The parameter is a string boolean representation. This means |
|
| 434 | - * it can be any of the following: "yes", "true", "no", "false". |
|
| 435 | - * The value is automatically converted to a boolean when retrieving |
|
| 436 | - * the parameter. |
|
| 437 | - * |
|
| 438 | - * @return Request_Param |
|
| 439 | - */ |
|
| 432 | + /** |
|
| 433 | + * The parameter is a string boolean representation. This means |
|
| 434 | + * it can be any of the following: "yes", "true", "no", "false". |
|
| 435 | + * The value is automatically converted to a boolean when retrieving |
|
| 436 | + * the parameter. |
|
| 437 | + * |
|
| 438 | + * @return Request_Param |
|
| 439 | + */ |
|
| 440 | 440 | public function setBoolean() : Request_Param |
| 441 | 441 | { |
| 442 | 442 | return $this->addClassFilter('Boolean'); |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | - /** |
|
| 446 | - * Validates the request parameter as an MD5 string, |
|
| 447 | - * so that only values resembling md5 values are accepted. |
|
| 448 | - * |
|
| 449 | - * NOTE: This can only guarantee the format, not whether |
|
| 450 | - * it is an actual valid hash of something. |
|
| 451 | - * |
|
| 452 | - * @return \AppUtils\Request_Param |
|
| 453 | - */ |
|
| 445 | + /** |
|
| 446 | + * Validates the request parameter as an MD5 string, |
|
| 447 | + * so that only values resembling md5 values are accepted. |
|
| 448 | + * |
|
| 449 | + * NOTE: This can only guarantee the format, not whether |
|
| 450 | + * it is an actual valid hash of something. |
|
| 451 | + * |
|
| 452 | + * @return \AppUtils\Request_Param |
|
| 453 | + */ |
|
| 454 | 454 | public function setMD5() : Request_Param |
| 455 | 455 | { |
| 456 | 456 | return $this->setRegex(RegexHelper::REGEX_MD5); |
@@ -492,14 +492,14 @@ discard block |
||
| 492 | 492 | return $this; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - /** |
|
| 496 | - * Retrieves the value of the request parameter, |
|
| 497 | - * applying all filters (if any) and validation |
|
| 498 | - * (if any). |
|
| 499 | - * |
|
| 500 | - * @param mixed $default |
|
| 501 | - * @return mixed |
|
| 502 | - */ |
|
| 495 | + /** |
|
| 496 | + * Retrieves the value of the request parameter, |
|
| 497 | + * applying all filters (if any) and validation |
|
| 498 | + * (if any). |
|
| 499 | + * |
|
| 500 | + * @param mixed $default |
|
| 501 | + * @return mixed |
|
| 502 | + */ |
|
| 503 | 503 | public function get($default=null) |
| 504 | 504 | { |
| 505 | 505 | $value = $this->request->getParam($this->paramName); |
@@ -587,12 +587,12 @@ discard block |
||
| 587 | 587 | return $this; |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | - /** |
|
| 591 | - * Adds a filter that trims whitespace from the request |
|
| 592 | - * parameter using the PHP <code>trim</code> function. |
|
| 593 | - * |
|
| 594 | - * @return \AppUtils\Request_Param |
|
| 595 | - */ |
|
| 590 | + /** |
|
| 591 | + * Adds a filter that trims whitespace from the request |
|
| 592 | + * parameter using the PHP <code>trim</code> function. |
|
| 593 | + * |
|
| 594 | + * @return \AppUtils\Request_Param |
|
| 595 | + */ |
|
| 596 | 596 | public function addFilterTrim() : Request_Param |
| 597 | 597 | { |
| 598 | 598 | // to guarantee we only work with strings |
@@ -601,13 +601,13 @@ discard block |
||
| 601 | 601 | return $this->addCallbackFilter('trim'); |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | - /** |
|
| 605 | - * Converts the value to a string, even if it is not |
|
| 606 | - * a string value. Complex types like arrays and objects |
|
| 607 | - * are converted to an empty string. |
|
| 608 | - * |
|
| 609 | - * @return \AppUtils\Request_Param |
|
| 610 | - */ |
|
| 604 | + /** |
|
| 605 | + * Converts the value to a string, even if it is not |
|
| 606 | + * a string value. Complex types like arrays and objects |
|
| 607 | + * are converted to an empty string. |
|
| 608 | + * |
|
| 609 | + * @return \AppUtils\Request_Param |
|
| 610 | + */ |
|
| 611 | 611 | public function addStringFilter() : Request_Param |
| 612 | 612 | { |
| 613 | 613 | return $this->addClassFilter('String'); |
@@ -657,12 +657,12 @@ discard block |
||
| 657 | 657 | return $this->addCallbackFilter('strip_tags', array($allowedTags)); |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - /** |
|
| 661 | - * Adds a filter that strips all whitespace from the |
|
| 662 | - * request parameter, from spaces to tabs and newlines. |
|
| 663 | - * |
|
| 664 | - * @return \AppUtils\Request_Param |
|
| 665 | - */ |
|
| 660 | + /** |
|
| 661 | + * Adds a filter that strips all whitespace from the |
|
| 662 | + * request parameter, from spaces to tabs and newlines. |
|
| 663 | + * |
|
| 664 | + * @return \AppUtils\Request_Param |
|
| 665 | + */ |
|
| 666 | 666 | public function addStripWhitespaceFilter() : Request_Param |
| 667 | 667 | { |
| 668 | 668 | // to ensure we only work with strings. |
@@ -671,14 +671,14 @@ discard block |
||
| 671 | 671 | return $this->addClassFilter('StripWhitespace'); |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - /** |
|
| 675 | - * Adds a filter that transforms comma separated values |
|
| 676 | - * into an array of values. |
|
| 677 | - * |
|
| 678 | - * @param bool $trimEntries Trim whitespace from each entry? |
|
| 679 | - * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
| 680 | - * @return \AppUtils\Request_Param |
|
| 681 | - */ |
|
| 674 | + /** |
|
| 675 | + * Adds a filter that transforms comma separated values |
|
| 676 | + * into an array of values. |
|
| 677 | + * |
|
| 678 | + * @param bool $trimEntries Trim whitespace from each entry? |
|
| 679 | + * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
| 680 | + * @return \AppUtils\Request_Param |
|
| 681 | + */ |
|
| 682 | 682 | public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
| 683 | 683 | { |
| 684 | 684 | $this->setArray(); |
@@ -703,12 +703,12 @@ discard block |
||
| 703 | 703 | ); |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - /** |
|
| 707 | - * Adds a filter that encodes all HTML special characters |
|
| 708 | - * using the PHP <code>htmlspecialchars</code> function. |
|
| 709 | - * |
|
| 710 | - * @return \AppUtils\Request_Param |
|
| 711 | - */ |
|
| 706 | + /** |
|
| 707 | + * Adds a filter that encodes all HTML special characters |
|
| 708 | + * using the PHP <code>htmlspecialchars</code> function. |
|
| 709 | + * |
|
| 710 | + * @return \AppUtils\Request_Param |
|
| 711 | + */ |
|
| 712 | 712 | public function addHTMLSpecialcharsFilter() : Request_Param |
| 713 | 713 | { |
| 714 | 714 | return $this->addCallbackFilter('htmlspecialchars', array(ENT_QUOTES, 'UTF-8')); |
@@ -721,14 +721,14 @@ discard block |
||
| 721 | 721 | |
| 722 | 722 | protected $required = false; |
| 723 | 723 | |
| 724 | - /** |
|
| 725 | - * Marks this request parameter as required. To use this feature, |
|
| 726 | - * you have to call the request's {@link Request::validate()} |
|
| 727 | - * method. |
|
| 728 | - * |
|
| 729 | - * @return Request_Param |
|
| 730 | - * @see Request::validate() |
|
| 731 | - */ |
|
| 724 | + /** |
|
| 725 | + * Marks this request parameter as required. To use this feature, |
|
| 726 | + * you have to call the request's {@link Request::validate()} |
|
| 727 | + * method. |
|
| 728 | + * |
|
| 729 | + * @return Request_Param |
|
| 730 | + * @see Request::validate() |
|
| 731 | + */ |
|
| 732 | 732 | public function makeRequired() : Request_Param |
| 733 | 733 | { |
| 734 | 734 | $this->required = true; |