‪TYPO3CMS  ‪main
NotEmptyValidator.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 {
31  protected ‪$acceptsEmptyValues = false;
32 
33  protected string ‪$nullMessage = 'LLL:EXT:extbase/Resources/Private/Language/locallang.xlf:validator.notempty.null';
34  protected string ‪$emptyMessage = 'LLL:EXT:extbase/Resources/Private/Language/locallang.xlf:validator.notempty.empty';
35 
36  protected array ‪$translationOptions = ['nullMessage', 'emptyMessage'];
37 
38  protected ‪$supportedOptions = [
39  'nullMessage' => [null, 'Translation key or message for null value', 'string'],
40  'emptyMessage' => [null, 'Translation key or message for empty value', 'string'],
41  ];
42 
46  public function ‪isValid(mixed $value): void
47  {
48  if ($value === null) {
49  $this->‪addError($this->‪translateErrorMessage($this->nullMessage), 1221560910);
50  }
51  if ($value === '') {
52  $this->‪addError($this->‪translateErrorMessage($this->emptyMessage), 1221560718);
53  }
54  if (is_array($value) && empty($value)) {
55  $this->‪addError($this->‪translateErrorMessage($this->emptyMessage), 1347992400);
56  }
57  if ($value instanceof \Countable && $value->count() === 0) {
58  $this->‪addError($this->‪translateErrorMessage($this->emptyMessage), 1347992453);
59  }
60  }
61 }
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
Definition: AbstractValidator.php:30
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator\addError
‪addError(string $message, int $code, array $arguments=[], string $title='')
Definition: AbstractValidator.php:98
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator\$acceptsEmptyValues
‪bool $acceptsEmptyValues
Definition: NotEmptyValidator.php:30
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator\$translationOptions
‪array $translationOptions
Definition: NotEmptyValidator.php:35
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator\$emptyMessage
‪string $emptyMessage
Definition: NotEmptyValidator.php:33
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator\isValid
‪isValid(mixed $value)
Definition: NotEmptyValidator.php:45
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator\translateErrorMessage
‪translateErrorMessage(string $translateKey, string $extensionName='', array $arguments=[])
Definition: AbstractValidator.php:147
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator\$nullMessage
‪string $nullMessage
Definition: NotEmptyValidator.php:32
‪TYPO3\CMS\Extbase\Validation\Validator
Definition: AbstractCompositeValidator.php:18
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:24
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator\$supportedOptions
‪$supportedOptions
Definition: NotEmptyValidator.php:37