‪TYPO3CMS  ‪main
BooleanValidator.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 {
28  protected ‪$supportedOptions = [
29  // The default is set to NULL here, because we need to be backward compatible here, because this
30  // BooleanValidator is called automatically on boolean action arguments. If we would set it to TRUE,
31  // every FALSE value for an action argument would break.
32  // @todo with next patches: deprecate this BooleanValidator and introduce a BooleanValueValidator, like
33  // in Flow, which won't be called on boolean action arguments.
34  'is' => [null, 'Boolean value', 'boolean|string|integer'],
35  ];
36 
44  public function ‪isValid(mixed $value): void
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:29
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator\addError
‪addError(string $message, int $code, array $arguments=[], string $title='')
Definition: AbstractValidator.php:82
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator\translateErrorMessage
‪translateErrorMessage(string $translateKey, string $extensionName, array $arguments=[])
Definition: AbstractValidator.php:122
‪TYPO3\CMS\Extbase\Validation\Validator
Definition: AbstractCompositeValidator.php:18
‪TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator\$supportedOptions
‪array $supportedOptions
Definition: BooleanValidator.php:27
‪TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator
Definition: BooleanValidator.php:24
‪TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator\isValid
‪isValid(mixed $value)
Definition: BooleanValidator.php:43