‪TYPO3CMS  10.4
BooleanValidator.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  // The default is set to NULL here, because we need to be backward compatible here, because this
28  // BooleanValidator is called automatically on boolean action arguments. If we would set it to TRUE,
29  // every FALSE value for an action argument would break.
30  // @todo with next patches: deprecate this BooleanValidator and introduce a BooleanValueValidator, like
31  // in Flow, which won't be called on boolean action arguments.
32  'is' => [null, 'Boolean value', 'boolean|string|integer']
33  ];
34 
44  public function ‪isValid($value)
45  {
46  // see comment above, check if expectation is NULL, then nothing to do!
47  if ($this->options['is'] === null) {
48  return;
49  }
50  switch (strtolower((string)$this->options['is'])) {
51  case 'true':
52  case '1':
53  $expectation = true;
54  break;
55  case 'false':
56  case '':
57  case '0':
58  $expectation = false;
59  break;
60  default:
61  $this->‪addError('The given expectation is not valid.', 1361959227);
62  return;
63  }
64 
65  if ($value !== $expectation) {
66  if (!is_bool($value)) {
68  'validator.boolean.nottrue',
69  'extbase'
70  ) ?? '', 1361959230);
71  } else {
72  if ($expectation) {
74  'validator.boolean.nottrue',
75  'extbase'
76  ) ?? '', 1361959228);
77  } else {
79  'validator.boolean.notfalse',
80  'extbase'
81  ) ?? '', 1361959229);
82  }
83  }
84  }
85  }
86 }
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
Definition: AbstractValidator.php:27
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator\translateErrorMessage
‪string null translateErrorMessage($translateKey, $extensionName, $arguments=[])
Definition: AbstractValidator.php:153
‪TYPO3\CMS\Extbase\Validation\Validator
Definition: AbstractCompositeValidator.php:16
‪TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator\$supportedOptions
‪array $supportedOptions
Definition: BooleanValidator.php:25
‪TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator
Definition: BooleanValidator.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator\addError
‪addError($message, $code, array $arguments=[], $title='')
Definition: AbstractValidator.php:120
‪TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator\isValid
‪isValid($value)
Definition: BooleanValidator.php:43