‪TYPO3CMS  11.5
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 
26 
35 {
41  protected ‪$dataType;
42 
47 
53  {
54  $this->propertyMapper = ‪$propertyMapper;
55  $this->propertyMappingConfiguration = GeneralUtility::makeInstance(PropertyMappingConfiguration::class);
56  $this->validator = GeneralUtility::makeInstance(ConjunctionValidator::class);
57  $this->processingMessages = GeneralUtility::makeInstance(Result::class);
58  }
59 
65  {
67  }
68 
73  public function ‪getDataType(): string
74  {
75  return ‪$this->dataType;
76  }
77 
82  public function ‪setDataType(string ‪$dataType)
83  {
84  $this->dataType = ‪$dataType;
85  }
86 
93  public function ‪getValidators(): \SplObjectStorage
94  {
95  return $this->validator->getValidators();
96  }
97 
102  public function ‪addValidator(ValidatorInterface ‪$validator)
103  {
104  $this->validator->addValidator(‪$validator);
105  }
106 
112  public function ‪removeAllValidators(): void
113  {
114  $this->‪filterValidators(fn() => false);
115  }
116 
122  public function ‪filterValidators(\Closure $filter): void
123  {
124  $validatorsToRemove = new \SplObjectStorage();
125  $validators = $this->‪getValidators();
126  foreach ($validators as ‪$validator) {
127  if (!$filter(‪$validator)) {
128  $validatorsToRemove->attach(‪$validator);
129  }
130  }
131  $validators->removeAll($validatorsToRemove);
132  }
133 
141  public function ‪removeValidator(ValidatorInterface ‪$validator)
142  {
143  $this->validator->removeValidator(‪$validator);
144  }
145 
151  public function ‪process($value)
152  {
153  if ($this->dataType !== null) {
154  $value = $this->propertyMapper->convert($value, $this->dataType, $this->propertyMappingConfiguration);
155  $messages = $this->propertyMapper->getMessages();
156  $this->propertyMapper->resetMessages();
157  } else {
158  $messages = GeneralUtility::makeInstance(Result::class);
159  }
160 
161  $validationResult = $this->validator->validate($value);
162  $messages->merge($validationResult);
163 
164  $this->processingMessages->merge($messages);
165  return $value;
166  }
167 
172  public function ‪getProcessingMessages(): Result
173  {
175  }
176 }
‪TYPO3\CMS\Form\Mvc\ProcessingRule\filterValidators
‪filterValidators(\Closure $filter)
Definition: ProcessingRule.php:121
‪TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator
Definition: ConjunctionValidator.php:24
‪TYPO3\CMS\Form\Mvc\ProcessingRule\getDataType
‪string getDataType()
Definition: ProcessingRule.php:72
‪TYPO3\CMS\Form\Mvc\ProcessingRule\addValidator
‪addValidator(ValidatorInterface $validator)
Definition: ProcessingRule.php:101
‪TYPO3\CMS\Form\Mvc\ProcessingRule\getPropertyMappingConfiguration
‪PropertyMappingConfiguration getPropertyMappingConfiguration()
Definition: ProcessingRule.php:63
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$dataType
‪string $dataType
Definition: ProcessingRule.php:40
‪TYPO3\CMS\Form\Mvc\ProcessingRule\__construct
‪__construct(PropertyMapper $propertyMapper)
Definition: ProcessingRule.php:51
‪TYPO3\CMS\Form\Mvc\ProcessingRule\removeValidator
‪removeValidator(ValidatorInterface $validator)
Definition: ProcessingRule.php:140
‪TYPO3\CMS\Extbase\Error\Result
Definition: Result.php:24
‪TYPO3\CMS\Form\Mvc\ProcessingRule\getValidators
‪SplObjectStorage getValidators()
Definition: ProcessingRule.php:92
‪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:150
‪TYPO3\CMS\Extbase\Property\PropertyMapper
Definition: PropertyMapper.php:39
‪TYPO3\CMS\Form\Mvc\ProcessingRule\getProcessingMessages
‪Result getProcessingMessages()
Definition: ProcessingRule.php:171
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$propertyMapper
‪PropertyMapper $propertyMapper
Definition: ProcessingRule.php:45
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$validator
‪ConjunctionValidator $validator
Definition: ProcessingRule.php:43
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$propertyMappingConfiguration
‪PropertyMappingConfiguration $propertyMappingConfiguration
Definition: ProcessingRule.php:42
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:22
‪TYPO3\CMS\Form\Mvc\ProcessingRule
Definition: ProcessingRule.php:35
‪TYPO3\CMS\Form\Mvc\ProcessingRule\removeAllValidators
‪removeAllValidators()
Definition: ProcessingRule.php:111
‪TYPO3\CMS\Form\Mvc\ProcessingRule\$processingMessages
‪Result $processingMessages
Definition: ProcessingRule.php:44
‪TYPO3\CMS\Form\Mvc