@@ -23,44 +23,44 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class Request_URLComparer |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var Request |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var Request |
|
| 28 | + */ |
|
| 29 | 29 | protected $request; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | 34 | protected $sourceURL; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | 39 | protected $targetURL; |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | 44 | protected $limitParams = array(); |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var bool |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var bool |
|
| 48 | + */ |
|
| 49 | 49 | protected $isMatch = false; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | 54 | protected $ignoreFragment = true; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var URLInfo |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var URLInfo |
|
| 58 | + */ |
|
| 59 | 59 | protected $sourceInfo; |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @var URLInfo |
|
| 63 | - */ |
|
| 61 | + /** |
|
| 62 | + * @var URLInfo |
|
| 63 | + */ |
|
| 64 | 64 | protected $targetInfo; |
| 65 | 65 | |
| 66 | 66 | public function __construct(Request $request, string $sourceURL, string $targetURL) |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | public function addLimitParam(string $name) : Request_URLComparer |
| 81 | 81 | { |
| 82 | - if(!in_array($name, $this->limitParams)) { |
|
| 82 | + if (!in_array($name, $this->limitParams)) { |
|
| 83 | 83 | $this->limitParams[] = $name; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -88,14 +88,14 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | public function addLimitParams(array $names) : Request_URLComparer |
| 90 | 90 | { |
| 91 | - foreach($names as $name) { |
|
| 91 | + foreach ($names as $name) { |
|
| 92 | 92 | $this->addLimitParam($name); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | return $this; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - public function setIgnoreFragment(bool $ignore=true) : Request_URLComparer |
|
| 98 | + public function setIgnoreFragment(bool $ignore = true) : Request_URLComparer |
|
| 99 | 99 | { |
| 100 | 100 | $this->ignoreFragment = $ignore; |
| 101 | 101 | return $this; |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | 'query' |
| 122 | 122 | ); |
| 123 | 123 | |
| 124 | - if(!$this->ignoreFragment) { |
|
| 124 | + if (!$this->ignoreFragment) { |
|
| 125 | 125 | $keys[] = 'fragment'; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - foreach($keys as $key) |
|
| 128 | + foreach ($keys as $key) |
|
| 129 | 129 | { |
| 130 | - if(!$this->compareKey($key)) { |
|
| 130 | + if (!$this->compareKey($key)) { |
|
| 131 | 131 | return false; |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $filter = 'filter_'.$key; |
| 144 | 144 | |
| 145 | - if(method_exists($this, $filter)) |
|
| 145 | + if (method_exists($this, $filter)) |
|
| 146 | 146 | { |
| 147 | 147 | $sVal = $this->$filter($sVal); |
| 148 | 148 | $tVal = $this->$filter($tVal); |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | protected function filter_path(string $path) : string |
| 155 | 155 | { |
| 156 | 156 | // fix double slashes in URLs |
| 157 | - while(stristr($path, '//')) { |
|
| 157 | + while (stristr($path, '//')) { |
|
| 158 | 158 | $path = str_replace('//', '/', $path); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | protected function filter_query(string $query) : string |
| 165 | 165 | { |
| 166 | - if(empty($query)) { |
|
| 166 | + if (empty($query)) { |
|
| 167 | 167 | return ''; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -178,15 +178,15 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | protected function limitParams(array $params) : array |
| 180 | 180 | { |
| 181 | - if(empty($this->limitParams)) { |
|
| 181 | + if (empty($this->limitParams)) { |
|
| 182 | 182 | return $params; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $keep = array(); |
| 186 | 186 | |
| 187 | - foreach($this->limitParams as $name) |
|
| 187 | + foreach ($this->limitParams as $name) |
|
| 188 | 188 | { |
| 189 | - if(isset($params[$name])) { |
|
| 189 | + if (isset($params[$name])) { |
|
| 190 | 190 | $keep[$name] = $params[$name]; |
| 191 | 191 | } |
| 192 | 192 | } |
@@ -572,8 +572,7 @@ |
||
| 572 | 572 | { |
| 573 | 573 | $number = null; |
| 574 | 574 | $empty = true; |
| 575 | - } |
|
| 576 | - else |
|
| 575 | + } else |
|
| 577 | 576 | { |
| 578 | 577 | $number = (float)$number * 1; |
| 579 | 578 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function setValue($value) : NumberInfo |
| 86 | 86 | { |
| 87 | - if($value instanceof NumberInfo) { |
|
| 87 | + if ($value instanceof NumberInfo) { |
|
| 88 | 88 | $value = $value->getValue(); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public function isPositive() : bool |
| 119 | 119 | { |
| 120 | - if(!$this->isEmpty()) { |
|
| 120 | + if (!$this->isEmpty()) { |
|
| 121 | 121 | $number = $this->getNumber(); |
| 122 | 122 | return $number > 0; |
| 123 | 123 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function hasValue() : bool |
| 150 | 150 | { |
| 151 | - if(!$this->isEmpty() && !$this->isZero()) { |
|
| 151 | + if (!$this->isEmpty() && !$this->isZero()) { |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public function getUnits() |
| 223 | 223 | { |
| 224 | - if(!$this->hasUnits()) { |
|
| 224 | + if (!$this->hasUnits()) { |
|
| 225 | 225 | return 'px'; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -255,15 +255,15 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | public function toAttribute() : string |
| 257 | 257 | { |
| 258 | - if($this->isEmpty()) { |
|
| 258 | + if ($this->isEmpty()) { |
|
| 259 | 259 | return ''; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if($this->isZero()) { |
|
| 262 | + if ($this->isZero()) { |
|
| 263 | 263 | return '0'; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if($this->isPercent()) { |
|
| 266 | + if ($this->isPercent()) { |
|
| 267 | 267 | return $this->getNumber().$this->getUnits(); |
| 268 | 268 | } |
| 269 | 269 | |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function toCSS() : string |
| 278 | 278 | { |
| 279 | - if($this->isEmpty()) { |
|
| 279 | + if ($this->isEmpty()) { |
|
| 280 | 280 | return ''; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if($this->isZero()) { |
|
| 283 | + if ($this->isZero()) { |
|
| 284 | 284 | return '0'; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | public function __toString() |
| 291 | 291 | { |
| 292 | - if($this->isEmpty()) { |
|
| 292 | + if ($this->isEmpty()) { |
|
| 293 | 293 | return ''; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | public function isBiggerThan($number) |
| 308 | 308 | { |
| 309 | 309 | $number = parseNumber($number); |
| 310 | - if($number->getUnits() != $this->getUnits()) { |
|
| 310 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | public function isSmallerThan($number) |
| 326 | 326 | { |
| 327 | 327 | $number = parseNumber($number); |
| 328 | - if($number->getUnits() != $this->getUnits()) { |
|
| 328 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 329 | 329 | return false; |
| 330 | 330 | } |
| 331 | 331 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | public function isBiggerEqual($number) |
| 336 | 336 | { |
| 337 | 337 | $number = parseNumber($number); |
| 338 | - if($number->getUnits() != $this->getUnits()) { |
|
| 338 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 339 | 339 | return false; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | */ |
| 353 | 353 | public function add($value) |
| 354 | 354 | { |
| 355 | - if($this->isEmpty()) { |
|
| 355 | + if ($this->isEmpty()) { |
|
| 356 | 356 | $this->setValue($value); |
| 357 | 357 | return $this; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $number = parseNumber($value); |
| 361 | 361 | |
| 362 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 362 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 363 | 363 | { |
| 364 | 364 | $new = $this->getNumber() + $number->getNumber(); |
| 365 | 365 | $this->setValue($new.$this->getUnits()); |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function subtract($value) |
| 380 | 380 | { |
| 381 | - if($this->isEmpty()) { |
|
| 381 | + if ($this->isEmpty()) { |
|
| 382 | 382 | $this->setValue($value); |
| 383 | 383 | return $this; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $number = parseNumber($value); |
| 387 | 387 | |
| 388 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 388 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 389 | 389 | { |
| 390 | 390 | $new = $this->getNumber() - $number->getNumber(); |
| 391 | 391 | $this->setValue($new.$this->getUnits()); |
@@ -412,25 +412,25 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | protected function percentOperation($operation, $percent) |
| 414 | 414 | { |
| 415 | - if($this->isZeroOrEmpty()) { |
|
| 415 | + if ($this->isZeroOrEmpty()) { |
|
| 416 | 416 | return $this; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | $percent = parseNumber($percent); |
| 420 | - if($percent->hasUnits() && !$percent->isPercent()) { |
|
| 420 | + if ($percent->hasUnits() && !$percent->isPercent()) { |
|
| 421 | 421 | return $this; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | $number = $this->getNumber(); |
| 425 | 425 | $value = $number * $percent->getNumber() / 100; |
| 426 | 426 | |
| 427 | - if($operation == '-') { |
|
| 427 | + if ($operation == '-') { |
|
| 428 | 428 | $number = $number - $value; |
| 429 | 429 | } else { |
| 430 | 430 | $number = $number + $value; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if($this->isUnitInteger()) { |
|
| 433 | + if ($this->isUnitInteger()) { |
|
| 434 | 434 | $number = intval($number); |
| 435 | 435 | } |
| 436 | 436 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | $key = $this->createValueKey($value); |
| 483 | 483 | |
| 484 | - if(array_key_exists($key, $cache)) { |
|
| 484 | + if (array_key_exists($key, $cache)) { |
|
| 485 | 485 | return $cache[$key]; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -491,13 +491,13 @@ discard block |
||
| 491 | 491 | 'number' => null |
| 492 | 492 | ); |
| 493 | 493 | |
| 494 | - if($key === '_EMPTY_') |
|
| 494 | + if ($key === '_EMPTY_') |
|
| 495 | 495 | { |
| 496 | 496 | $cache[$key]['empty'] = true; |
| 497 | 497 | return $cache[$key]; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - if($value === 0 || $value === '0') |
|
| 500 | + if ($value === 0 || $value === '0') |
|
| 501 | 501 | { |
| 502 | 502 | $cache[$key]['number'] = 0; |
| 503 | 503 | $cache[$key] = $this->filterInfo($cache[$key]); |
@@ -506,20 +506,20 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | $test = trim((string)$value); |
| 508 | 508 | |
| 509 | - if($test === '') |
|
| 509 | + if ($test === '') |
|
| 510 | 510 | { |
| 511 | 511 | $cache[$key]['empty'] = true; |
| 512 | 512 | return $cache[$key]; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // replace comma notation (which is only possible if it's a string) |
| 516 | - if(is_string($value)) |
|
| 516 | + if (is_string($value)) |
|
| 517 | 517 | { |
| 518 | 518 | $test = $this->preProcess($test, $cache, $value); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // convert to a number if it's numeric |
| 522 | - if(is_numeric($test)) |
|
| 522 | + if (is_numeric($test)) |
|
| 523 | 523 | { |
| 524 | 524 | $cache[$key]['number'] = (float)$test * 1; |
| 525 | 525 | $cache[$key] = $this->filterInfo($cache[$key]); |
@@ -545,19 +545,19 @@ discard block |
||
| 545 | 545 | $empty = false; |
| 546 | 546 | |
| 547 | 547 | $found = $this->findUnits($test); |
| 548 | - if($found !== null) |
|
| 548 | + if ($found !== null) |
|
| 549 | 549 | { |
| 550 | 550 | $number = $found['number']; |
| 551 | 551 | $units = $found['units']; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | // the filters have to restore the value |
| 555 | - if($this->postProcess) |
|
| 555 | + if ($this->postProcess) |
|
| 556 | 556 | { |
| 557 | 557 | $number = $this->postProcess($number, $test); |
| 558 | 558 | } |
| 559 | 559 | // empty number |
| 560 | - else if($number === '' || $number === null || is_bool($number)) |
|
| 560 | + else if ($number === '' || $number === null || is_bool($number)) |
|
| 561 | 561 | { |
| 562 | 562 | $number = null; |
| 563 | 563 | $empty = true; |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | $number = trim($number); |
| 569 | 569 | |
| 570 | 570 | // may be an arbitrary string in some cases |
| 571 | - if(!is_numeric($number)) |
|
| 571 | + if (!is_numeric($number)) |
|
| 572 | 572 | { |
| 573 | 573 | $number = null; |
| 574 | 574 | $empty = true; |
@@ -600,17 +600,17 @@ discard block |
||
| 600 | 600 | $vlength = strlen($value); |
| 601 | 601 | $names = array_keys($this->knownUnits); |
| 602 | 602 | |
| 603 | - foreach($names as $unit) |
|
| 603 | + foreach ($names as $unit) |
|
| 604 | 604 | { |
| 605 | 605 | $ulength = strlen($unit); |
| 606 | - $start = $vlength-$ulength; |
|
| 607 | - if($start < 0) { |
|
| 606 | + $start = $vlength - $ulength; |
|
| 607 | + if ($start < 0) { |
|
| 608 | 608 | continue; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | $search = substr($value, $start, $ulength); |
| 612 | 612 | |
| 613 | - if($search==$unit) |
|
| 613 | + if ($search == $unit) |
|
| 614 | 614 | { |
| 615 | 615 | return array( |
| 616 | 616 | 'units' => $unit, |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | */ |
| 631 | 631 | private function createValueKey($value) : string |
| 632 | 632 | { |
| 633 | - if(!is_string($value) && !is_numeric($value)) |
|
| 633 | + if (!is_string($value) && !is_numeric($value)) |
|
| 634 | 634 | { |
| 635 | 635 | return '_EMPTY_'; |
| 636 | 636 | } |
@@ -696,12 +696,12 @@ discard block |
||
| 696 | 696 | protected function filterInfo(array $info) : array |
| 697 | 697 | { |
| 698 | 698 | $useUnits = 'px'; |
| 699 | - if($info['units'] !== null) { |
|
| 699 | + if ($info['units'] !== null) { |
|
| 700 | 700 | $useUnits = $info['units']; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | // the units are non-decimal: convert decimal values |
| 704 | - if($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 704 | + if ($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 705 | 705 | { |
| 706 | 706 | $info['number'] = intval($info['number']); |
| 707 | 707 | } |
@@ -38,24 +38,24 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | class NumberInfo |
| 40 | 40 | { |
| 41 | - /** |
|
| 42 | - * @var mixed |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var mixed |
|
| 43 | + */ |
|
| 44 | 44 | protected $rawValue; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | 49 | protected $info; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | 54 | protected $empty = false; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var array |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var array |
|
| 58 | + */ |
|
| 59 | 59 | protected $knownUnits = array( |
| 60 | 60 | '%' => true, |
| 61 | 61 | 'rem' => true, |
@@ -95,21 +95,21 @@ discard block |
||
| 95 | 95 | return $this; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Retrieves the raw, internal information array resulting |
|
| 100 | - * from the parsing of the number. |
|
| 101 | - * |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 98 | + /** |
|
| 99 | + * Retrieves the raw, internal information array resulting |
|
| 100 | + * from the parsing of the number. |
|
| 101 | + * |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | 104 | public function getRawInfo() : array |
| 105 | 105 | { |
| 106 | 106 | return $this->info; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Whether the number was empty (null or empty string). |
|
| 111 | - * @return boolean |
|
| 112 | - */ |
|
| 109 | + /** |
|
| 110 | + * Whether the number was empty (null or empty string). |
|
| 111 | + * @return boolean |
|
| 112 | + */ |
|
| 113 | 113 | public function isEmpty() : bool |
| 114 | 114 | { |
| 115 | 115 | return $this->empty; |
@@ -532,12 +532,12 @@ discard block |
||
| 532 | 532 | return $cache[$key]; |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - /** |
|
| 536 | - * Parses a string number notation with units included, e.g. 14px, 50%... |
|
| 537 | - * |
|
| 538 | - * @param string $test |
|
| 539 | - * @return array |
|
| 540 | - */ |
|
| 535 | + /** |
|
| 536 | + * Parses a string number notation with units included, e.g. 14px, 50%... |
|
| 537 | + * |
|
| 538 | + * @param string $test |
|
| 539 | + * @return array |
|
| 540 | + */ |
|
| 541 | 541 | private function parseStringValue(string $test) : array |
| 542 | 542 | { |
| 543 | 543 | $number = null; |
@@ -588,13 +588,13 @@ discard block |
||
| 588 | 588 | return $this->filterInfo($result); |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - /** |
|
| 592 | - * Attempts to determine what kind of units are specified |
|
| 593 | - * in the string. Returns NULL if none could be matched. |
|
| 594 | - * |
|
| 595 | - * @param string $value |
|
| 596 | - * @return array|NULL |
|
| 597 | - */ |
|
| 591 | + /** |
|
| 592 | + * Attempts to determine what kind of units are specified |
|
| 593 | + * in the string. Returns NULL if none could be matched. |
|
| 594 | + * |
|
| 595 | + * @param string $value |
|
| 596 | + * @return array|NULL |
|
| 597 | + */ |
|
| 598 | 598 | private function findUnits(string $value) : ?array |
| 599 | 599 | { |
| 600 | 600 | $vlength = strlen($value); |
@@ -622,12 +622,12 @@ discard block |
||
| 622 | 622 | return null; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - /** |
|
| 626 | - * Creates the cache key for the specified value. |
|
| 627 | - * |
|
| 628 | - * @param mixed $value |
|
| 629 | - * @return string |
|
| 630 | - */ |
|
| 625 | + /** |
|
| 626 | + * Creates the cache key for the specified value. |
|
| 627 | + * |
|
| 628 | + * @param mixed $value |
|
| 629 | + * @return string |
|
| 630 | + */ |
|
| 631 | 631 | private function createValueKey($value) : string |
| 632 | 632 | { |
| 633 | 633 | if(!is_string($value) && !is_numeric($value)) |
@@ -640,59 +640,59 @@ discard block |
||
| 640 | 640 | |
| 641 | 641 | protected $postProcess = false; |
| 642 | 642 | |
| 643 | - /** |
|
| 644 | - * Called if explicitly enabled: allows filtering the |
|
| 645 | - * number after the detection process has completed. |
|
| 646 | - * |
|
| 647 | - * @param string|NULL $number The adjusted number |
|
| 648 | - * @param string $originalString The original value before it was parsed |
|
| 649 | - * @return mixed |
|
| 650 | - */ |
|
| 643 | + /** |
|
| 644 | + * Called if explicitly enabled: allows filtering the |
|
| 645 | + * number after the detection process has completed. |
|
| 646 | + * |
|
| 647 | + * @param string|NULL $number The adjusted number |
|
| 648 | + * @param string $originalString The original value before it was parsed |
|
| 649 | + * @return mixed |
|
| 650 | + */ |
|
| 651 | 651 | protected function postProcess(?string $number, /** @scrutinizer ignore-unused */ string $originalString) |
| 652 | 652 | { |
| 653 | 653 | return $number; |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - /** |
|
| 657 | - * Filters the value before it is parsed, but only if it is a string. |
|
| 658 | - * |
|
| 659 | - * NOTE: This may be overwritten in a subclass, to allow custom filtering |
|
| 660 | - * the the values. An example of a use case would be a preprocessor for |
|
| 661 | - * variables in a templating system. |
|
| 662 | - * |
|
| 663 | - * @param string $trimmedString The trimmed value. |
|
| 664 | - * @param array $cache The internal values cache array. |
|
| 665 | - * @param string $originalValue The original value that the NumberInfo was created for. |
|
| 666 | - * @return string |
|
| 667 | - * |
|
| 668 | - * @see NumberInfo::enablePostProcess() |
|
| 669 | - */ |
|
| 656 | + /** |
|
| 657 | + * Filters the value before it is parsed, but only if it is a string. |
|
| 658 | + * |
|
| 659 | + * NOTE: This may be overwritten in a subclass, to allow custom filtering |
|
| 660 | + * the the values. An example of a use case would be a preprocessor for |
|
| 661 | + * variables in a templating system. |
|
| 662 | + * |
|
| 663 | + * @param string $trimmedString The trimmed value. |
|
| 664 | + * @param array $cache The internal values cache array. |
|
| 665 | + * @param string $originalValue The original value that the NumberInfo was created for. |
|
| 666 | + * @return string |
|
| 667 | + * |
|
| 668 | + * @see NumberInfo::enablePostProcess() |
|
| 669 | + */ |
|
| 670 | 670 | protected function preProcess(string $trimmedString, /** @scrutinizer ignore-unused */ array &$cache, /** @scrutinizer ignore-unused */ string $originalValue) : string |
| 671 | 671 | { |
| 672 | 672 | return str_replace(',', '.', $trimmedString); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - /** |
|
| 676 | - * Enables the post processing so the postProcess method gets called. |
|
| 677 | - * This should be called in the {@link NumberInfo::preProcess()} |
|
| 678 | - * method as needed. |
|
| 679 | - * |
|
| 680 | - * @return NumberInfo |
|
| 681 | - * @see NumberInfo::postProcess() |
|
| 682 | - */ |
|
| 675 | + /** |
|
| 676 | + * Enables the post processing so the postProcess method gets called. |
|
| 677 | + * This should be called in the {@link NumberInfo::preProcess()} |
|
| 678 | + * method as needed. |
|
| 679 | + * |
|
| 680 | + * @return NumberInfo |
|
| 681 | + * @see NumberInfo::postProcess() |
|
| 682 | + */ |
|
| 683 | 683 | protected function enablePostProcess() : NumberInfo |
| 684 | 684 | { |
| 685 | 685 | $this->postProcess = true; |
| 686 | 686 | return $this; |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | - /** |
|
| 690 | - * Filters the number info array to adjust the units |
|
| 691 | - * and number according to the required rules. |
|
| 692 | - * |
|
| 693 | - * @param array $info |
|
| 694 | - * @return array |
|
| 695 | - */ |
|
| 689 | + /** |
|
| 690 | + * Filters the number info array to adjust the units |
|
| 691 | + * and number according to the required rules. |
|
| 692 | + * |
|
| 693 | + * @param array $info |
|
| 694 | + * @return array |
|
| 695 | + */ |
|
| 696 | 696 | protected function filterInfo(array $info) : array |
| 697 | 697 | { |
| 698 | 698 | $useUnits = 'px'; |
@@ -142,7 +142,7 @@ |
||
| 142 | 142 | |
| 143 | 143 | protected function getInfoKey(string $name) : string |
| 144 | 144 | { |
| 145 | - if(isset($this->info[$name])) { |
|
| 145 | + if (isset($this->info[$name])) { |
|
| 146 | 146 | return (string)$this->info[$name]; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -19,51 +19,51 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | class RequestHelper_Response |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @var RequestHelper |
|
| 24 | - */ |
|
| 22 | + /** |
|
| 23 | + * @var RequestHelper |
|
| 24 | + */ |
|
| 25 | 25 | protected $request; |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | 30 | protected $body = ''; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | 35 | protected $info; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var bool |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var bool |
|
| 39 | + */ |
|
| 40 | 40 | protected $isError = false; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $errorMessage = ''; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var integer |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var integer |
|
| 49 | + */ |
|
| 50 | 50 | protected $errorCode = 0; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @param RequestHelper $helper |
|
| 54 | - * @param array $info The CURL info array from curl_getinfo(). |
|
| 55 | - */ |
|
| 52 | + /** |
|
| 53 | + * @param RequestHelper $helper |
|
| 54 | + * @param array $info The CURL info array from curl_getinfo(). |
|
| 55 | + */ |
|
| 56 | 56 | public function __construct(RequestHelper $helper, array $info) |
| 57 | 57 | { |
| 58 | 58 | $this->request = $helper; |
| 59 | 59 | $this->info = $info; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Retrieves the request instance that initiated the request. |
|
| 64 | - * |
|
| 65 | - * @return RequestHelper |
|
| 66 | - */ |
|
| 62 | + /** |
|
| 63 | + * Retrieves the request instance that initiated the request. |
|
| 64 | + * |
|
| 65 | + * @return RequestHelper |
|
| 66 | + */ |
|
| 67 | 67 | public function getRequest() : RequestHelper |
| 68 | 68 | { |
| 69 | 69 | return $this->request; |
@@ -84,79 +84,79 @@ discard block |
||
| 84 | 84 | return $this; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Whether an error occurred in the request. |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 87 | + /** |
|
| 88 | + * Whether an error occurred in the request. |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | 91 | public function isError() : bool |
| 92 | 92 | { |
| 93 | 93 | return $this->isError; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Whether the request timed out. |
|
| 98 | - * @return bool |
|
| 99 | - */ |
|
| 96 | + /** |
|
| 97 | + * Whether the request timed out. |
|
| 98 | + * @return bool |
|
| 99 | + */ |
|
| 100 | 100 | public function isTimeout() : bool |
| 101 | 101 | { |
| 102 | 102 | return $this->errorCode === RequestHelper_CURL::OPERATION_TIMEDOUT; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Retrieves the native error message, if an error occurred. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 105 | + /** |
|
| 106 | + * Retrieves the native error message, if an error occurred. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | 109 | public function getErrorMessage() : string |
| 110 | 110 | { |
| 111 | 111 | return $this->errorMessage; |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Retrieves the native CURL error code, if an error occurred. |
|
| 116 | - * @return int |
|
| 117 | - * @see RequestHelper_CURL For a list of error codes. |
|
| 118 | - */ |
|
| 114 | + /** |
|
| 115 | + * Retrieves the native CURL error code, if an error occurred. |
|
| 116 | + * @return int |
|
| 117 | + * @see RequestHelper_CURL For a list of error codes. |
|
| 118 | + */ |
|
| 119 | 119 | public function getErrorCode() : int |
| 120 | 120 | { |
| 121 | 121 | return $this->errorCode; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Retrieves the full body of the request. |
|
| 126 | - * |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 124 | + /** |
|
| 125 | + * Retrieves the full body of the request. |
|
| 126 | + * |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | 129 | public function getRequestBody() : string |
| 130 | 130 | { |
| 131 | 131 | return $this->request->getBody(); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Retrieves the body of the response, if any. |
|
| 136 | - * |
|
| 137 | - * @return string |
|
| 138 | - */ |
|
| 134 | + /** |
|
| 135 | + * Retrieves the body of the response, if any. |
|
| 136 | + * |
|
| 137 | + * @return string |
|
| 138 | + */ |
|
| 139 | 139 | public function getResponseBody() : string |
| 140 | 140 | { |
| 141 | 141 | return $this->body; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * The response HTTP code. |
|
| 146 | - * |
|
| 147 | - * @return int The code, or 0 if none was sent (on error). |
|
| 148 | - */ |
|
| 144 | + /** |
|
| 145 | + * The response HTTP code. |
|
| 146 | + * |
|
| 147 | + * @return int The code, or 0 if none was sent (on error). |
|
| 148 | + */ |
|
| 149 | 149 | public function getCode() : int |
| 150 | 150 | { |
| 151 | 151 | return intval($this->getInfoKey('http_code')); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * Retrieves the actual headers that were sent in the request: |
|
| 156 | - * one header by entry in the indexed array. |
|
| 157 | - * |
|
| 158 | - * @return array |
|
| 159 | - */ |
|
| 154 | + /** |
|
| 155 | + * Retrieves the actual headers that were sent in the request: |
|
| 156 | + * one header by entry in the indexed array. |
|
| 157 | + * |
|
| 158 | + * @return array |
|
| 159 | + */ |
|
| 160 | 160 | public function getHeaders() : array |
| 161 | 161 | { |
| 162 | 162 | return ConvertHelper::explodeTrim("\n", $this->getInfoKey('request_header')); |
@@ -22,9 +22,9 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | class RequestHelper_Exception extends BaseException |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var RequestHelper_Response|NULL |
|
| 27 | - */ |
|
| 25 | + /** |
|
| 26 | + * @var RequestHelper_Response|NULL |
|
| 27 | + */ |
|
| 28 | 28 | protected $response = null; |
| 29 | 29 | |
| 30 | 30 | public function setResponse(RequestHelper_Response $response) |
@@ -32,11 +32,11 @@ discard block |
||
| 32 | 32 | $this->response = $response; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Retrieves the related response instance, if available. |
|
| 37 | - * |
|
| 38 | - * @return RequestHelper_Response|NULL |
|
| 39 | - */ |
|
| 35 | + /** |
|
| 36 | + * Retrieves the related response instance, if available. |
|
| 37 | + * |
|
| 38 | + * @return RequestHelper_Response|NULL |
|
| 39 | + */ |
|
| 40 | 40 | public function getResponse() : ?RequestHelper_Response |
| 41 | 41 | { |
| 42 | 42 | return $this->response; |
@@ -32,23 +32,23 @@ |
||
| 32 | 32 | $this->info = $info; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Enables the authentication information in the URL, |
|
| 37 | - * if a username and password are present. |
|
| 38 | - * |
|
| 39 | - * @param bool $enable Whether to turn it on or off. |
|
| 40 | - * @return URLInfo_Normalizer |
|
| 41 | - */ |
|
| 35 | + /** |
|
| 36 | + * Enables the authentication information in the URL, |
|
| 37 | + * if a username and password are present. |
|
| 38 | + * |
|
| 39 | + * @param bool $enable Whether to turn it on or off. |
|
| 40 | + * @return URLInfo_Normalizer |
|
| 41 | + */ |
|
| 42 | 42 | public function enableAuth(bool $enable=true) : URLInfo_Normalizer |
| 43 | 43 | { |
| 44 | 44 | $this->auth = $enable; |
| 45 | 45 | return $this; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Retrieves the normalized URL. |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 48 | + /** |
|
| 49 | + * Retrieves the normalized URL. |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | 52 | public function normalize() : string |
| 53 | 53 | { |
| 54 | 54 | $method = 'normalize_'.$this->info->getType(); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param bool $enable Whether to turn it on or off. |
| 40 | 40 | * @return URLInfo_Normalizer |
| 41 | 41 | */ |
| 42 | - public function enableAuth(bool $enable=true) : URLInfo_Normalizer |
|
| 42 | + public function enableAuth(bool $enable = true) : URLInfo_Normalizer |
|
| 43 | 43 | { |
| 44 | 44 | $this->auth = $enable; |
| 45 | 45 | return $this; |
@@ -86,48 +86,48 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | protected function renderAuth(string $normalized) : string |
| 88 | 88 | { |
| 89 | - if(!$this->info->hasUsername() || !$this->auth) { |
|
| 89 | + if (!$this->info->hasUsername() || !$this->auth) { |
|
| 90 | 90 | return $normalized; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - return $normalized . urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
|
| 93 | + return $normalized.urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | protected function renderPort(string $normalized) : string |
| 97 | 97 | { |
| 98 | - if(!$this->info->hasPort()) { |
|
| 98 | + if (!$this->info->hasPort()) { |
|
| 99 | 99 | return $normalized; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - return $normalized . ':'.$this->info->getPort(); |
|
| 102 | + return $normalized.':'.$this->info->getPort(); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | protected function renderPath(string $normalized) : string |
| 106 | 106 | { |
| 107 | - if(!$this->info->hasPath()) { |
|
| 107 | + if (!$this->info->hasPath()) { |
|
| 108 | 108 | return $normalized; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return $normalized . $this->info->getPath(); |
|
| 111 | + return $normalized.$this->info->getPath(); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | protected function renderParams(string $normalized) : string |
| 115 | 115 | { |
| 116 | 116 | $params = $this->info->getParams(); |
| 117 | 117 | |
| 118 | - if(empty($params)) { |
|
| 118 | + if (empty($params)) { |
|
| 119 | 119 | return $normalized; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - return $normalized . '?'.http_build_query($params, '', '&', PHP_QUERY_RFC3986); |
|
| 122 | + return $normalized.'?'.http_build_query($params, '', '&', PHP_QUERY_RFC3986); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | protected function renderFragment(string $normalized) : string |
| 126 | 126 | { |
| 127 | - if(!$this->info->hasFragment()) { |
|
| 127 | + if (!$this->info->hasFragment()) { |
|
| 128 | 128 | return $normalized; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - return $normalized . '#'.$this->info->getFragment(); |
|
| 131 | + return $normalized.'#'.$this->info->getFragment(); |
|
| 132 | 132 | } |
| 133 | 133 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | protected static function init() : void |
| 46 | 46 | { |
| 47 | - if(!empty(self::$sizes)) { |
|
| 47 | + if (!empty(self::$sizes)) { |
|
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | |
| 63 | 63 | self::addSize('b', 1, 1, t('B'), t('Byte'), t('Bytes')); |
| 64 | 64 | |
| 65 | - if(class_exists('AppLocalize\Localization')) |
|
| 65 | + if (class_exists('AppLocalize\Localization')) |
|
| 66 | 66 | { |
| 67 | 67 | \AppLocalize\Localization::onLocaleChanged(array(self::class, 'handle_localeChanged')); |
| 68 | 68 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | $name = strtolower($name); |
| 133 | 133 | |
| 134 | - if(isset(self::$sizes[$name])) { |
|
| 134 | + if (isset(self::$sizes[$name])) { |
|
| 135 | 135 | return self::$sizes[$name]; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | |
| 174 | 174 | $result = array(); |
| 175 | 175 | |
| 176 | - foreach(self::$sizes as $size) |
|
| 176 | + foreach (self::$sizes as $size) |
|
| 177 | 177 | { |
| 178 | - if($size->getBase() === $base) { |
|
| 178 | + if ($size->getBase() === $base) { |
|
| 179 | 179 | $result[] = $size; |
| 180 | 180 | } |
| 181 | 181 | } |
@@ -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(); |
@@ -20,43 +20,43 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class ConvertHelper_TabsNormalizer |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var integer |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var integer |
|
| 25 | + */ |
|
| 26 | 26 | protected $max = 0; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var integer |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var integer |
|
| 30 | + */ |
|
| 31 | 31 | protected $min = PHP_INT_MAX; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var bool |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var bool |
|
| 35 | + */ |
|
| 36 | 36 | protected $tabs2spaces = false; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var array |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var array |
|
| 40 | + */ |
|
| 41 | 41 | protected $lines = array(); |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | 46 | protected $eol = ''; |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var integer |
|
| 50 | - */ |
|
| 48 | + /** |
|
| 49 | + * @var integer |
|
| 50 | + */ |
|
| 51 | 51 | protected $tabSize = 4; |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Whether to enable or disable the conversion |
|
| 55 | - * of tabs to spaces. |
|
| 56 | - * |
|
| 57 | - * @param bool $enable |
|
| 58 | - * @return ConvertHelper_TabsNormalizer |
|
| 59 | - */ |
|
| 53 | + /** |
|
| 54 | + * Whether to enable or disable the conversion |
|
| 55 | + * of tabs to spaces. |
|
| 56 | + * |
|
| 57 | + * @param bool $enable |
|
| 58 | + * @return ConvertHelper_TabsNormalizer |
|
| 59 | + */ |
|
| 60 | 60 | public function convertTabsToSpaces(bool $enable=true) : ConvertHelper_TabsNormalizer |
| 61 | 61 | { |
| 62 | 62 | $this->tabs2spaces = $enable; |
@@ -64,13 +64,13 @@ discard block |
||
| 64 | 64 | return $this; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Sets the size of a tab, in spaces. Used to convert tabs |
|
| 69 | - * from spaces and the other way around. Defaults to 4. |
|
| 70 | - * |
|
| 71 | - * @param int $amountSpaces |
|
| 72 | - * @return ConvertHelper_TabsNormalizer |
|
| 73 | - */ |
|
| 67 | + /** |
|
| 68 | + * Sets the size of a tab, in spaces. Used to convert tabs |
|
| 69 | + * from spaces and the other way around. Defaults to 4. |
|
| 70 | + * |
|
| 71 | + * @param int $amountSpaces |
|
| 72 | + * @return ConvertHelper_TabsNormalizer |
|
| 73 | + */ |
|
| 74 | 74 | public function setTabSize(int $amountSpaces) : ConvertHelper_TabsNormalizer |
| 75 | 75 | { |
| 76 | 76 | $this->tabSize = $amountSpaces; |
@@ -78,15 +78,15 @@ discard block |
||
| 78 | 78 | return $this; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Normalizes tabs in the specified string by indenting everything |
|
| 83 | - * back to the minimum tab distance. With the second parameter, |
|
| 84 | - * tabs can optionally be converted to spaces as well (recommended |
|
| 85 | - * for HTML output). |
|
| 86 | - * |
|
| 87 | - * @param string $string |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 81 | + /** |
|
| 82 | + * Normalizes tabs in the specified string by indenting everything |
|
| 83 | + * back to the minimum tab distance. With the second parameter, |
|
| 84 | + * tabs can optionally be converted to spaces as well (recommended |
|
| 85 | + * for HTML output). |
|
| 86 | + * |
|
| 87 | + * @param string $string |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | 90 | public function normalize(string $string) : string |
| 91 | 91 | { |
| 92 | 92 | $this->splitLines($string); |
@@ -143,10 +143,10 @@ discard block |
||
| 143 | 143 | return implode($this->eol, $converted); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Finds out the minimum and maximum amount of |
|
| 148 | - * tabs in the string. |
|
| 149 | - */ |
|
| 146 | + /** |
|
| 147 | + * Finds out the minimum and maximum amount of |
|
| 148 | + * tabs in the string. |
|
| 149 | + */ |
|
| 150 | 150 | protected function countOccurrences() : void |
| 151 | 151 | { |
| 152 | 152 | foreach($this->lines as $line) |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param bool $enable |
| 58 | 58 | * @return ConvertHelper_TabsNormalizer |
| 59 | 59 | */ |
| 60 | - public function convertTabsToSpaces(bool $enable=true) : ConvertHelper_TabsNormalizer |
|
| 60 | + public function convertTabsToSpaces(bool $enable = true) : ConvertHelper_TabsNormalizer |
|
| 61 | 61 | { |
| 62 | 62 | $this->tabs2spaces = $enable; |
| 63 | 63 | |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | $result = $this->_normalize(); |
| 96 | 96 | |
| 97 | - if($this->tabs2spaces) |
|
| 97 | + if ($this->tabs2spaces) |
|
| 98 | 98 | { |
| 99 | 99 | $result = ConvertHelper::tabs2spaces($result, $this->tabSize); |
| 100 | 100 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | $eol = ConvertHelper::detectEOLCharacter($string); |
| 110 | 110 | |
| 111 | - if($eol !== null) |
|
| 111 | + if ($eol !== null) |
|
| 112 | 112 | { |
| 113 | 113 | $this->eol = $eol->getCharacter(); |
| 114 | 114 | } |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | { |
| 127 | 127 | $converted = array(); |
| 128 | 128 | |
| 129 | - foreach($this->lines as $line) |
|
| 129 | + foreach ($this->lines as $line) |
|
| 130 | 130 | { |
| 131 | 131 | $amount = substr_count($line, "\t") - $this->min; |
| 132 | 132 | |
| 133 | 133 | $line = trim($line, "\n\r\t"); |
| 134 | 134 | |
| 135 | - if($amount >= 1) |
|
| 135 | + if ($amount >= 1) |
|
| 136 | 136 | { |
| 137 | - $line = str_repeat("\t", $amount) . $line; |
|
| 137 | + $line = str_repeat("\t", $amount).$line; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $converted[] = $line; |
@@ -149,23 +149,23 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | protected function countOccurrences() : void |
| 151 | 151 | { |
| 152 | - foreach($this->lines as $line) |
|
| 152 | + foreach ($this->lines as $line) |
|
| 153 | 153 | { |
| 154 | 154 | $amount = substr_count($line, "\t"); |
| 155 | 155 | |
| 156 | - if($amount > $this->max) |
|
| 156 | + if ($amount > $this->max) |
|
| 157 | 157 | { |
| 158 | 158 | $this->max = $amount; |
| 159 | 159 | continue; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if($amount > 0 && $amount < $this->min) |
|
| 162 | + if ($amount > 0 && $amount < $this->min) |
|
| 163 | 163 | { |
| 164 | 164 | $this->min = $amount; |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if($this->min === PHP_INT_MAX) { |
|
| 168 | + if ($this->min === PHP_INT_MAX) { |
|
| 169 | 169 | $this->min = 0; |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | ) |
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * @var array |
|
| 74 | - */ |
|
| 72 | + /** |
|
| 73 | + * @var array |
|
| 74 | + */ |
|
| 75 | 75 | protected $selected = array(); |
| 76 | 76 | |
| 77 | 77 | public function convert(string $string) : string |
@@ -81,16 +81,16 @@ discard block |
||
| 81 | 81 | return str_replace(array_keys($chars), array_values($chars), $string); |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Selects a character set to replace. Can be called |
|
| 86 | - * several times to add additional sets to the collection. |
|
| 87 | - * |
|
| 88 | - * @param string $type See the <code>CHAR_XXX</code> constants. |
|
| 89 | - * @return ConvertHelper_HiddenConverter |
|
| 90 | - * |
|
| 91 | - * @see ConvertHelper_HiddenConverter::CHARS_CONTROL |
|
| 92 | - * @see ConvertHelper_HiddenConverter::CHARS_WHITESPACE |
|
| 93 | - */ |
|
| 84 | + /** |
|
| 85 | + * Selects a character set to replace. Can be called |
|
| 86 | + * several times to add additional sets to the collection. |
|
| 87 | + * |
|
| 88 | + * @param string $type See the <code>CHAR_XXX</code> constants. |
|
| 89 | + * @return ConvertHelper_HiddenConverter |
|
| 90 | + * |
|
| 91 | + * @see ConvertHelper_HiddenConverter::CHARS_CONTROL |
|
| 92 | + * @see ConvertHelper_HiddenConverter::CHARS_WHITESPACE |
|
| 93 | + */ |
|
| 94 | 94 | public function selectCharacters(string $type) : ConvertHelper_HiddenConverter |
| 95 | 95 | { |
| 96 | 96 | if(!in_array($type, $this->selected)) { |
@@ -100,11 +100,11 @@ discard block |
||
| 100 | 100 | return $this; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Resolves the list of characters to make visible. |
|
| 105 | - * |
|
| 106 | - * @return array |
|
| 107 | - */ |
|
| 103 | + /** |
|
| 104 | + * Resolves the list of characters to make visible. |
|
| 105 | + * |
|
| 106 | + * @return array |
|
| 107 | + */ |
|
| 108 | 108 | protected function resolveSelection() : array |
| 109 | 109 | { |
| 110 | 110 | $selected = $this->selected; |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function selectCharacters(string $type) : ConvertHelper_HiddenConverter |
| 95 | 95 | { |
| 96 | - if(!in_array($type, $this->selected)) { |
|
| 96 | + if (!in_array($type, $this->selected)) { |
|
| 97 | 97 | $this->selected[] = $type; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | { |
| 110 | 110 | $selected = $this->selected; |
| 111 | 111 | |
| 112 | - if(empty($this->selected)) |
|
| 112 | + if (empty($this->selected)) |
|
| 113 | 113 | { |
| 114 | 114 | $selected = array( |
| 115 | 115 | self::CHARS_WHITESPACE, |
@@ -119,9 +119,9 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | $result = array(); |
| 121 | 121 | |
| 122 | - foreach($selected as $type) |
|
| 122 | + foreach ($selected as $type) |
|
| 123 | 123 | { |
| 124 | - if(isset($this->characters[$type])) |
|
| 124 | + if (isset($this->characters[$type])) |
|
| 125 | 125 | { |
| 126 | 126 | $result = array_merge($result, $this->characters[$type]); |
| 127 | 127 | } |
@@ -126,9 +126,9 @@ discard block |
||
| 126 | 126 | * @param array $args |
| 127 | 127 | * @return Request_Param |
| 128 | 128 | */ |
| 129 | - public function setCallback($callback, array $args=array()) : Request_Param |
|
| 129 | + public function setCallback($callback, array $args = array()) : Request_Param |
|
| 130 | 130 | { |
| 131 | - if(!is_callable($callback)) { |
|
| 131 | + if (!is_callable($callback)) { |
|
| 132 | 132 | throw new Request_Exception( |
| 133 | 133 | 'Not a valid callback', |
| 134 | 134 | 'The specified callback is not a valid callable entity.', |
@@ -159,22 +159,22 @@ discard block |
||
| 159 | 159 | // first off, apply filtering |
| 160 | 160 | $value = $this->filter($value); |
| 161 | 161 | |
| 162 | - if($this->valueType === self::VALUE_TYPE_LIST) |
|
| 162 | + if ($this->valueType === self::VALUE_TYPE_LIST) |
|
| 163 | 163 | { |
| 164 | - if(!is_array($value)) |
|
| 164 | + if (!is_array($value)) |
|
| 165 | 165 | { |
| 166 | 166 | $value = explode(',', $value); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $keep = array(); |
| 170 | 170 | |
| 171 | - foreach($value as $subval) |
|
| 171 | + foreach ($value as $subval) |
|
| 172 | 172 | { |
| 173 | 173 | $subval = $this->filter($subval); |
| 174 | 174 | |
| 175 | 175 | $subval = $this->applyValidations($subval, true); |
| 176 | 176 | |
| 177 | - if($subval !== null) { |
|
| 177 | + if ($subval !== null) { |
|
| 178 | 178 | $keep[] = $subval; |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -195,11 +195,11 @@ discard block |
||
| 195 | 195 | * @param mixed $value |
| 196 | 196 | * @return mixed |
| 197 | 197 | */ |
| 198 | - protected function applyValidations($value, bool $subval=false) |
|
| 198 | + protected function applyValidations($value, bool $subval = false) |
|
| 199 | 199 | { |
| 200 | 200 | // go through all enqueued validations in turn, each time |
| 201 | 201 | // replacing the value with the adjusted, validated value. |
| 202 | - foreach($this->validations as $validateDef) |
|
| 202 | + foreach ($this->validations as $validateDef) |
|
| 203 | 203 | { |
| 204 | 204 | $value = $this->validateType($value, $validateDef['type'], $validateDef['params'], $subval); |
| 205 | 205 | } |
@@ -222,7 +222,7 @@ discard block |
||
| 222 | 222 | { |
| 223 | 223 | $class = '\AppUtils\Request_Param_Validator_'.ucfirst($type); |
| 224 | 224 | |
| 225 | - if(!class_exists($class)) |
|
| 225 | + if (!class_exists($class)) |
|
| 226 | 226 | { |
| 227 | 227 | throw new Request_Exception( |
| 228 | 228 | 'Unknown validation type.', |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | { |
| 377 | 377 | $args = func_get_args(); // cannot be used as function parameter in some PHP versions |
| 378 | 378 | |
| 379 | - if(is_array($args[0])) |
|
| 379 | + if (is_array($args[0])) |
|
| 380 | 380 | { |
| 381 | 381 | $args = $args[0]; |
| 382 | 382 | } |
@@ -521,10 +521,10 @@ discard block |
||
| 521 | 521 | * @param mixed $default |
| 522 | 522 | * @return mixed |
| 523 | 523 | */ |
| 524 | - public function get($default=null) |
|
| 524 | + public function get($default = null) |
|
| 525 | 525 | { |
| 526 | 526 | $value = $this->request->getParam($this->paramName); |
| 527 | - if($value !== null && $value !== '') { |
|
| 527 | + if ($value !== null && $value !== '') { |
|
| 528 | 528 | return $value; |
| 529 | 529 | } |
| 530 | 530 | |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | { |
| 544 | 544 | $total = count($this->filters); |
| 545 | 545 | for ($i = 0; $i < $total; $i++) { |
| 546 | - $method = 'applyFilter_' . $this->filters[$i]['type']; |
|
| 546 | + $method = 'applyFilter_'.$this->filters[$i]['type']; |
|
| 547 | 547 | $value = $this->$method($value, $this->filters[$i]['params']); |
| 548 | 548 | } |
| 549 | 549 | |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | * @param bool $stripEmptyEntries Remove empty entries from the array? |
| 701 | 701 | * @return \AppUtils\Request_Param |
| 702 | 702 | */ |
| 703 | - public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
|
| 703 | + public function addCommaSeparatedFilter(bool $trimEntries = true, bool $stripEmptyEntries = true) : Request_Param |
|
| 704 | 704 | { |
| 705 | 705 | $this->setArray(); |
| 706 | 706 | |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | ); |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - protected function addClassFilter(string $name, array $params=array()) : Request_Param |
|
| 716 | + protected function addClassFilter(string $name, array $params = array()) : Request_Param |
|
| 717 | 717 | { |
| 718 | 718 | return $this->addFilter( |
| 719 | 719 | self::FILTER_TYPE_CLASS, |
@@ -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)) { |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | return $value; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - /** |
|
| 193 | - * Runs the value through all validations that were added. |
|
| 194 | - * |
|
| 195 | - * @param mixed $value |
|
| 196 | - * @return mixed |
|
| 197 | - */ |
|
| 192 | + /** |
|
| 193 | + * Runs the value through all validations that were added. |
|
| 194 | + * |
|
| 195 | + * @param mixed $value |
|
| 196 | + * @return mixed |
|
| 197 | + */ |
|
| 198 | 198 | protected function applyValidations($value, bool $subval=false) |
| 199 | 199 | { |
| 200 | 200 | // go through all enqueued validations in turn, each time |
@@ -207,17 +207,17 @@ discard block |
||
| 207 | 207 | return $value; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Validates the specified value using the validation type. Returns |
|
| 212 | - * the validated value. |
|
| 213 | - * |
|
| 214 | - * @param mixed $value |
|
| 215 | - * @param string $type |
|
| 216 | - * @param array $params |
|
| 217 | - * @param bool $subval Whether this is a subvalue in a list |
|
| 218 | - * @throws Request_Exception |
|
| 219 | - * @return mixed |
|
| 220 | - */ |
|
| 210 | + /** |
|
| 211 | + * Validates the specified value using the validation type. Returns |
|
| 212 | + * the validated value. |
|
| 213 | + * |
|
| 214 | + * @param mixed $value |
|
| 215 | + * @param string $type |
|
| 216 | + * @param array $params |
|
| 217 | + * @param bool $subval Whether this is a subvalue in a list |
|
| 218 | + * @throws Request_Exception |
|
| 219 | + * @return mixed |
|
| 220 | + */ |
|
| 221 | 221 | protected function validateType($value, string $type, array $params, bool $subval) |
| 222 | 222 | { |
| 223 | 223 | $class = '\AppUtils\Request_Param_Validator_'.ucfirst($type); |
@@ -286,13 +286,13 @@ discard block |
||
| 286 | 286 | |
| 287 | 287 | protected $valueType = self::VALUE_TYPE_STRING; |
| 288 | 288 | |
| 289 | - /** |
|
| 290 | - * Sets the variable to contain a comma-separated list of integer IDs. |
|
| 291 | - * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
| 292 | - * <code>145</code>. |
|
| 293 | - * |
|
| 294 | - * @return Request_Param |
|
| 295 | - */ |
|
| 289 | + /** |
|
| 290 | + * Sets the variable to contain a comma-separated list of integer IDs. |
|
| 291 | + * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
| 292 | + * <code>145</code>. |
|
| 293 | + * |
|
| 294 | + * @return Request_Param |
|
| 295 | + */ |
|
| 296 | 296 | public function setIDList() |
| 297 | 297 | { |
| 298 | 298 | $this->valueType = self::VALUE_TYPE_LIST; |
@@ -302,13 +302,13 @@ discard block |
||
| 302 | 302 | return $this; |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - /** |
|
| 306 | - * Sets the variable to be an alias, as defined by the |
|
| 307 | - * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
| 308 | - * |
|
| 309 | - * @return Request_Param |
|
| 310 | - * @see RegexHelper::REGEX_ALIAS |
|
| 311 | - */ |
|
| 305 | + /** |
|
| 306 | + * Sets the variable to be an alias, as defined by the |
|
| 307 | + * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
| 308 | + * |
|
| 309 | + * @return Request_Param |
|
| 310 | + * @see RegexHelper::REGEX_ALIAS |
|
| 311 | + */ |
|
| 312 | 312 | public function setAlias() |
| 313 | 313 | { |
| 314 | 314 | return $this->setRegex(RegexHelper::REGEX_ALIAS); |
@@ -349,12 +349,12 @@ discard block |
||
| 349 | 349 | return $this->setValidation(self::VALIDATION_TYPE_ALPHA); |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * Sets the parameter value as a string containing lowercase |
|
| 354 | - * and/or uppercase letters, as well as numbers. |
|
| 355 | - * |
|
| 356 | - * @return Request_Param |
|
| 357 | - */ |
|
| 352 | + /** |
|
| 353 | + * Sets the parameter value as a string containing lowercase |
|
| 354 | + * and/or uppercase letters, as well as numbers. |
|
| 355 | + * |
|
| 356 | + * @return Request_Param |
|
| 357 | + */ |
|
| 358 | 358 | public function setAlnum() |
| 359 | 359 | { |
| 360 | 360 | return $this->setValidation(self::VALIDATION_TYPE_ALNUM); |
@@ -387,17 +387,17 @@ discard block |
||
| 387 | 387 | ); |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - /** |
|
| 391 | - * Only available for array values: the parameter must be |
|
| 392 | - * an array value, and the array may only contain values |
|
| 393 | - * specified in the values array. |
|
| 394 | - * |
|
| 395 | - * Submitted values that are not in the allowed list of |
|
| 396 | - * values are stripped from the value. |
|
| 397 | - * |
|
| 398 | - * @param array $values List of allowed values |
|
| 399 | - * @return \AppUtils\Request_Param |
|
| 400 | - */ |
|
| 390 | + /** |
|
| 391 | + * Only available for array values: the parameter must be |
|
| 392 | + * an array value, and the array may only contain values |
|
| 393 | + * specified in the values array. |
|
| 394 | + * |
|
| 395 | + * Submitted values that are not in the allowed list of |
|
| 396 | + * values are stripped from the value. |
|
| 397 | + * |
|
| 398 | + * @param array $values List of allowed values |
|
| 399 | + * @return \AppUtils\Request_Param |
|
| 400 | + */ |
|
| 401 | 401 | public function setValuesList(array $values) |
| 402 | 402 | { |
| 403 | 403 | $this->setArray(); |
@@ -410,11 +410,11 @@ discard block |
||
| 410 | 410 | ); |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - /** |
|
| 414 | - * Whether the parameter is a list of values. |
|
| 415 | - * |
|
| 416 | - * @return bool |
|
| 417 | - */ |
|
| 413 | + /** |
|
| 414 | + * Whether the parameter is a list of values. |
|
| 415 | + * |
|
| 416 | + * @return bool |
|
| 417 | + */ |
|
| 418 | 418 | public function isList() : bool |
| 419 | 419 | { |
| 420 | 420 | return $this->valueType === self::VALUE_TYPE_LIST; |
@@ -425,53 +425,53 @@ discard block |
||
| 425 | 425 | return $this->setValidation(self::VALIDATION_TYPE_ARRAY); |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - /** |
|
| 429 | - * Specifies that a JSON-encoded string is expected. |
|
| 430 | - * |
|
| 431 | - * NOTE: Numbers or quoted strings are technically valid |
|
| 432 | - * JSON, but are not accepted, because it is assumed |
|
| 433 | - * at least an array or object are expected. |
|
| 434 | - * |
|
| 435 | - * @return \AppUtils\Request_Param |
|
| 436 | - */ |
|
| 428 | + /** |
|
| 429 | + * Specifies that a JSON-encoded string is expected. |
|
| 430 | + * |
|
| 431 | + * NOTE: Numbers or quoted strings are technically valid |
|
| 432 | + * JSON, but are not accepted, because it is assumed |
|
| 433 | + * at least an array or object are expected. |
|
| 434 | + * |
|
| 435 | + * @return \AppUtils\Request_Param |
|
| 436 | + */ |
|
| 437 | 437 | public function setJSON() : Request_Param |
| 438 | 438 | { |
| 439 | 439 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => true)); |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - /** |
|
| 443 | - * Like {@link Request_Param::setJSON()}, but accepts |
|
| 444 | - * only JSON objects. Arrays will not be accepted. |
|
| 445 | - * |
|
| 446 | - * @return \AppUtils\Request_Param |
|
| 447 | - */ |
|
| 442 | + /** |
|
| 443 | + * Like {@link Request_Param::setJSON()}, but accepts |
|
| 444 | + * only JSON objects. Arrays will not be accepted. |
|
| 445 | + * |
|
| 446 | + * @return \AppUtils\Request_Param |
|
| 447 | + */ |
|
| 448 | 448 | public function setJSONObject() : Request_Param |
| 449 | 449 | { |
| 450 | 450 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => false)); |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - /** |
|
| 454 | - * The parameter is a string boolean representation. This means |
|
| 455 | - * it can be any of the following: "yes", "true", "no", "false". |
|
| 456 | - * The value is automatically converted to a boolean when retrieving |
|
| 457 | - * the parameter. |
|
| 458 | - * |
|
| 459 | - * @return Request_Param |
|
| 460 | - */ |
|
| 453 | + /** |
|
| 454 | + * The parameter is a string boolean representation. This means |
|
| 455 | + * it can be any of the following: "yes", "true", "no", "false". |
|
| 456 | + * The value is automatically converted to a boolean when retrieving |
|
| 457 | + * the parameter. |
|
| 458 | + * |
|
| 459 | + * @return Request_Param |
|
| 460 | + */ |
|
| 461 | 461 | public function setBoolean() : Request_Param |
| 462 | 462 | { |
| 463 | 463 | return $this->addClassFilter('Boolean'); |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - /** |
|
| 467 | - * Validates the request parameter as an MD5 string, |
|
| 468 | - * so that only values resembling md5 values are accepted. |
|
| 469 | - * |
|
| 470 | - * NOTE: This can only guarantee the format, not whether |
|
| 471 | - * it is an actual valid hash of something. |
|
| 472 | - * |
|
| 473 | - * @return \AppUtils\Request_Param |
|
| 474 | - */ |
|
| 466 | + /** |
|
| 467 | + * Validates the request parameter as an MD5 string, |
|
| 468 | + * so that only values resembling md5 values are accepted. |
|
| 469 | + * |
|
| 470 | + * NOTE: This can only guarantee the format, not whether |
|
| 471 | + * it is an actual valid hash of something. |
|
| 472 | + * |
|
| 473 | + * @return \AppUtils\Request_Param |
|
| 474 | + */ |
|
| 475 | 475 | public function setMD5() : Request_Param |
| 476 | 476 | { |
| 477 | 477 | return $this->setRegex(RegexHelper::REGEX_MD5); |
@@ -513,14 +513,14 @@ discard block |
||
| 513 | 513 | return $this; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - /** |
|
| 517 | - * Retrieves the value of the request parameter, |
|
| 518 | - * applying all filters (if any) and validation |
|
| 519 | - * (if any). |
|
| 520 | - * |
|
| 521 | - * @param mixed $default |
|
| 522 | - * @return mixed |
|
| 523 | - */ |
|
| 516 | + /** |
|
| 517 | + * Retrieves the value of the request parameter, |
|
| 518 | + * applying all filters (if any) and validation |
|
| 519 | + * (if any). |
|
| 520 | + * |
|
| 521 | + * @param mixed $default |
|
| 522 | + * @return mixed |
|
| 523 | + */ |
|
| 524 | 524 | public function get($default=null) |
| 525 | 525 | { |
| 526 | 526 | $value = $this->request->getParam($this->paramName); |
@@ -531,14 +531,14 @@ discard block |
||
| 531 | 531 | return $this->validate($default); |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - /** |
|
| 535 | - * Filters the specified value by going through all available |
|
| 536 | - * filters, if any. If none have been set, the value is simply |
|
| 537 | - * passed through. |
|
| 538 | - * |
|
| 539 | - * @param mixed $value |
|
| 540 | - * @return mixed |
|
| 541 | - */ |
|
| 534 | + /** |
|
| 535 | + * Filters the specified value by going through all available |
|
| 536 | + * filters, if any. If none have been set, the value is simply |
|
| 537 | + * passed through. |
|
| 538 | + * |
|
| 539 | + * @param mixed $value |
|
| 540 | + * @return mixed |
|
| 541 | + */ |
|
| 542 | 542 | protected function filter($value) |
| 543 | 543 | { |
| 544 | 544 | $total = count($this->filters); |
@@ -608,12 +608,12 @@ discard block |
||
| 608 | 608 | return $this; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | - /** |
|
| 612 | - * Adds a filter that trims whitespace from the request |
|
| 613 | - * parameter using the PHP <code>trim</code> function. |
|
| 614 | - * |
|
| 615 | - * @return \AppUtils\Request_Param |
|
| 616 | - */ |
|
| 611 | + /** |
|
| 612 | + * Adds a filter that trims whitespace from the request |
|
| 613 | + * parameter using the PHP <code>trim</code> function. |
|
| 614 | + * |
|
| 615 | + * @return \AppUtils\Request_Param |
|
| 616 | + */ |
|
| 617 | 617 | public function addFilterTrim() : Request_Param |
| 618 | 618 | { |
| 619 | 619 | // to guarantee we only work with strings |
@@ -622,13 +622,13 @@ discard block |
||
| 622 | 622 | return $this->addCallbackFilter('trim'); |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - /** |
|
| 626 | - * Converts the value to a string, even if it is not |
|
| 627 | - * a string value. Complex types like arrays and objects |
|
| 628 | - * are converted to an empty string. |
|
| 629 | - * |
|
| 630 | - * @return \AppUtils\Request_Param |
|
| 631 | - */ |
|
| 625 | + /** |
|
| 626 | + * Converts the value to a string, even if it is not |
|
| 627 | + * a string value. Complex types like arrays and objects |
|
| 628 | + * are converted to an empty string. |
|
| 629 | + * |
|
| 630 | + * @return \AppUtils\Request_Param |
|
| 631 | + */ |
|
| 632 | 632 | public function addStringFilter() : Request_Param |
| 633 | 633 | { |
| 634 | 634 | return $this->addClassFilter('String'); |
@@ -678,12 +678,12 @@ discard block |
||
| 678 | 678 | return $this->addCallbackFilter('strip_tags', array($allowedTags)); |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - /** |
|
| 682 | - * Adds a filter that strips all whitespace from the |
|
| 683 | - * request parameter, from spaces to tabs and newlines. |
|
| 684 | - * |
|
| 685 | - * @return \AppUtils\Request_Param |
|
| 686 | - */ |
|
| 681 | + /** |
|
| 682 | + * Adds a filter that strips all whitespace from the |
|
| 683 | + * request parameter, from spaces to tabs and newlines. |
|
| 684 | + * |
|
| 685 | + * @return \AppUtils\Request_Param |
|
| 686 | + */ |
|
| 687 | 687 | public function addStripWhitespaceFilter() : Request_Param |
| 688 | 688 | { |
| 689 | 689 | // to ensure we only work with strings. |
@@ -692,14 +692,14 @@ discard block |
||
| 692 | 692 | return $this->addClassFilter('StripWhitespace'); |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | - /** |
|
| 696 | - * Adds a filter that transforms comma separated values |
|
| 697 | - * into an array of values. |
|
| 698 | - * |
|
| 699 | - * @param bool $trimEntries Trim whitespace from each entry? |
|
| 700 | - * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
| 701 | - * @return \AppUtils\Request_Param |
|
| 702 | - */ |
|
| 695 | + /** |
|
| 696 | + * Adds a filter that transforms comma separated values |
|
| 697 | + * into an array of values. |
|
| 698 | + * |
|
| 699 | + * @param bool $trimEntries Trim whitespace from each entry? |
|
| 700 | + * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
| 701 | + * @return \AppUtils\Request_Param |
|
| 702 | + */ |
|
| 703 | 703 | public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
| 704 | 704 | { |
| 705 | 705 | $this->setArray(); |
@@ -724,12 +724,12 @@ discard block |
||
| 724 | 724 | ); |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - /** |
|
| 728 | - * Adds a filter that encodes all HTML special characters |
|
| 729 | - * using the PHP <code>htmlspecialchars</code> function. |
|
| 730 | - * |
|
| 731 | - * @return \AppUtils\Request_Param |
|
| 732 | - */ |
|
| 727 | + /** |
|
| 728 | + * Adds a filter that encodes all HTML special characters |
|
| 729 | + * using the PHP <code>htmlspecialchars</code> function. |
|
| 730 | + * |
|
| 731 | + * @return \AppUtils\Request_Param |
|
| 732 | + */ |
|
| 733 | 733 | public function addHTMLSpecialcharsFilter() : Request_Param |
| 734 | 734 | { |
| 735 | 735 | return $this->addCallbackFilter('htmlspecialchars', array(ENT_QUOTES, 'UTF-8')); |
@@ -742,14 +742,14 @@ discard block |
||
| 742 | 742 | |
| 743 | 743 | protected $required = false; |
| 744 | 744 | |
| 745 | - /** |
|
| 746 | - * Marks this request parameter as required. To use this feature, |
|
| 747 | - * you have to call the request's {@link Request::validate()} |
|
| 748 | - * method. |
|
| 749 | - * |
|
| 750 | - * @return Request_Param |
|
| 751 | - * @see Request::validate() |
|
| 752 | - */ |
|
| 745 | + /** |
|
| 746 | + * Marks this request parameter as required. To use this feature, |
|
| 747 | + * you have to call the request's {@link Request::validate()} |
|
| 748 | + * method. |
|
| 749 | + * |
|
| 750 | + * @return Request_Param |
|
| 751 | + * @see Request::validate() |
|
| 752 | + */ |
|
| 753 | 753 | public function makeRequired() : Request_Param |
| 754 | 754 | { |
| 755 | 755 | $this->required = true; |