TYPO3 CMS  TYPO3_8-7
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 
44  public function isValid($value)
45  {
46  if (!is_array($value) && !($value instanceof \Countable)) {
47  $this->addError(
48  $this->translateErrorMessage(
49  'validation.error.1475002976',
50  'form'
51  ),
52  1475002976
53  );
54  return;
55  }
56 
57  $minimum = (int)$this->options['minimum'];
58  $maximum = (int)$this->options['maximum'];
59  if (count($value) < $minimum || count($value) > $maximum) {
60  $this->addError(
61  $this->translateErrorMessage(
62  'validation.error.1475002994',
63  'form',
64  [$minimum, $maximum]
65  ),
66  1475002994,
67  [$this->options['minimum'], $this->options['maximum']]
68  );
69  }
70  }
71 }
addError($message, $code, array $arguments=[], $title='')
translateErrorMessage($translateKey, $extensionName, $arguments=[])