‪TYPO3CMS  9.5
CountValidator.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It originated from the Neos.Form package (www.neos.io)
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
21 
29 {
33  protected ‪$supportedOptions = [
34  'minimum' => [0, 'The minimum count to accept', 'integer'],
35  'maximum' => [PHP_INT_MAX, 'The maximum count to accept', 'integer']
36  ];
37 
43  public function ‪isValid($value)
44  {
45  if (!is_array($value) && !($value instanceof \Countable)) {
46  $this->‪addError(
48  'validation.error.1475002976',
49  'form'
50  ),
51  1475002976
52  );
53  return;
54  }
55 
56  $minimum = (int)$this->options['minimum'];
57  $maximum = (int)$this->options['maximum'];
58  if (count($value) < $minimum || count($value) > $maximum) {
59  $this->‪addError(
61  'validation.error.1475002994',
62  'form',
63  [$minimum, $maximum]
64  ),
65  1475002994,
66  [$this->options['minimum'], $this->options['maximum']]
67  );
68  }
69  }
70 }
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
Definition: AbstractValidator.php:23
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator\translateErrorMessage
‪string null translateErrorMessage($translateKey, $extensionName, $arguments=[])
Definition: AbstractValidator.php:149
‪TYPO3\CMS\Form\Mvc\Validation\CountValidator\isValid
‪isValid($value)
Definition: CountValidator.php:42
‪TYPO3\CMS\Form\Mvc\Validation\CountValidator
Definition: CountValidator.php:29
‪TYPO3\CMS\Form\Mvc\Validation\CountValidator\$supportedOptions
‪array $supportedOptions
Definition: CountValidator.php:32
‪TYPO3\CMS\Form\Mvc\Validation
Definition: CountValidator.php:3
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator\addError
‪addError($message, $code, array $arguments=[], $title='')
Definition: AbstractValidator.php:116