TYPO3 CMS  TYPO3_8-7
NumberRangeValidator.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 {
27  protected $supportedOptions = [
28  'minimum' => [0, 'The minimum value to accept', 'integer'],
29  'maximum' => [PHP_INT_MAX, 'The maximum value to accept', 'integer']
30  ];
31 
38  public function isValid($value)
39  {
40  if (!is_numeric($value)) {
41  $this->addError(
42  $this->translateErrorMessage(
43  'validator.numberrange.notvalid',
44  'extbase'
45  ),
46  1221563685
47  );
48  return;
49  }
50 
51  $minimum = $this->options['minimum'];
52  $maximum = $this->options['maximum'];
53 
54  if ($minimum > $maximum) {
55  $x = $minimum;
56  $minimum = $maximum;
57  $maximum = $x;
58  }
59  if ($value < $minimum || $value > $maximum) {
60  $this->addError($this->translateErrorMessage(
61  'validator.numberrange.range',
62  'extbase',
63  [
64  $minimum,
65  $maximum
66  ]
67  ), 1221561046, [$minimum, $maximum]);
68  }
69  }
70 }
addError($message, $code, array $arguments=[], $title='')
translateErrorMessage($translateKey, $extensionName, $arguments=[])