‪TYPO3CMS  ‪main
ProcessingRule.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 
18 namespace ‪TYPO3\CMS\Form\Mvc;
19 
27 
36 {
42  protected ‪$dataType;
43 
47 
52  public function ‪__construct(
53  protected readonly ‪PropertyMapper $propertyMapper,
54  ‪ValidatorResolver $validatorResolver,
55  ) {
56  $this->propertyMappingConfiguration = GeneralUtility::makeInstance(PropertyMappingConfiguration::class);
58  ‪$validator = $validatorResolver->‪createValidator(ConjunctionValidator::class);
59  $this->validator = ‪$validator;
60  $this->processingMessages = GeneralUtility::makeInstance(Result::class);
61  }
62 
67  {
69  }
70 
74  public function ‪getDataType(): string
75  {
76  return ‪$this->dataType;
77  }
78 
82  public function ‪setDataType(string ‪$dataType)
83  {
84  $this->dataType = ‪$dataType;
85  }
86 
92  public function ‪getValidators(): \SplObjectStorage
93  {
94  return $this->validator->getValidators();
95  }
96 
100  public function ‪addValidator(ValidatorInterface ‪$validator)
101  {
102  $this->validator->addValidator(‪$validator);
103  }
104 
110  public function ‪removeAllValidators(): void
111  {
112  $this->‪filterValidators(fn() => false);
113  }
114 
120  public function ‪filterValidators(\Closure $filter): void
121  {
122  $validatorsToRemove = new \SplObjectStorage();
123  $validators = $this->‪getValidators();
124  foreach ($validators as ‪$validator) {
125  if (!$filter(‪$validator)) {
126  $validatorsToRemove->attach(‪$validator);
127  }
128  }
129  $validators->removeAll($validatorsToRemove);
130  }
131 
139  public function ‪removeValidator(ValidatorInterface ‪$validator)
140  {
141  $this->validator->removeValidator(‪$validator);
142  }
143 
149  public function ‪process($value)
150  {
151  if ($this->dataType !== null) {
152  $value = $this->propertyMapper->convert($value, $this->dataType, $this->propertyMappingConfiguration);
153  $messages = $this->propertyMapper->getMessages();
154  $this->propertyMapper->resetMessages();
155  } else {
156  $messages = GeneralUtility::makeInstance(Result::class);
157  }
158 
159  $validationResult = $this->validator->validate($value);
160  $messages->merge($validationResult);
161 
162  $this->processingMessages->merge($messages);
163  return $value;
164  }
165 
169  public function ‪getProcessingMessages(): Result
170  {
172  }
173 }
‪TYPO3\CMS\Form\Mvc\ProcessingRule\filterValidators
‪filterValidators(\Closure $filter)
Definition: ProcessingRule.php:119
‪TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator
Definition: ConjunctionValidator.php:26
‪TYPO3\CMS\Form\Mvc\ProcessingRule\__construct
‪__construct(protected readonly PropertyMapper $propertyMapper, ValidatorResolver $validatorResolver,)
Definition: ProcessingRule.php:51
‪TYPO3\CMS\Form\Mvc\ProcessingRule\getPropertyMappingConfiguration
‪getPropertyMappingConfiguration()
Definition: ProcessingRule.php:65
‪TYPO3\CMS\Form\Mvc\ProcessingRule\addValidator
‪addValidator(ValidatorInterface $validator)
Definition: ProcessingRule.php:99
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$dataType
‪string $dataType
Definition: ProcessingRule.php:41
‪TYPO3\CMS\Extbase\Validation\ValidatorResolver
Definition: ValidatorResolver.php:38
‪TYPO3\CMS\Extbase\Validation\ValidatorResolver\createValidator
‪createValidator(string $validatorType, array $validatorOptions=[])
Definition: ValidatorResolver.php:50
‪TYPO3\CMS\Form\Mvc\ProcessingRule\removeValidator
‪removeValidator(ValidatorInterface $validator)
Definition: ProcessingRule.php:138
‪TYPO3\CMS\Extbase\Error\Result
Definition: Result.php:24
‪TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration
Definition: PropertyMappingConfiguration.php:22
‪TYPO3\CMS\Form\Mvc\ProcessingRule\setDataType
‪setDataType(string $dataType)
Definition: ProcessingRule.php:81
‪TYPO3\CMS\Form\Mvc\ProcessingRule\process
‪mixed process($value)
Definition: ProcessingRule.php:148
‪TYPO3\CMS\Form\Mvc\ProcessingRule\getDataType
‪getDataType()
Definition: ProcessingRule.php:73
‪TYPO3\CMS\Form\Mvc\ProcessingRule\getValidators
‪getValidators()
Definition: ProcessingRule.php:91
‪TYPO3\CMS\Extbase\Property\PropertyMapper
Definition: PropertyMapper.php:30
‪TYPO3\CMS\Form\Mvc\ProcessingRule\getProcessingMessages
‪getProcessingMessages()
Definition: ProcessingRule.php:168
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$validator
‪ConjunctionValidator $validator
Definition: ProcessingRule.php:44
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$propertyMappingConfiguration
‪PropertyMappingConfiguration $propertyMappingConfiguration
Definition: ProcessingRule.php:43
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:26
‪TYPO3\CMS\Form\Mvc\ProcessingRule
Definition: ProcessingRule.php:36
‪TYPO3\CMS\Form\Mvc\ProcessingRule\removeAllValidators
‪removeAllValidators()
Definition: ProcessingRule.php:109
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$processingMessages
‪Result $processingMessages
Definition: ProcessingRule.php:45
‪TYPO3\CMS\Form\Mvc