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