‪TYPO3CMS  10.4
AbstractCompositeValidator.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 
20 
24 abstract class ‪AbstractCompositeValidator implements ‪ObjectValidatorInterface, \Countable
25 {
31  protected ‪$supportedOptions = [];
32 
36  protected ‪$options = [];
37 
41  protected ‪$validators;
42 
47 
54  public function ‪__construct(array ‪$options = [])
55  {
56  // check for options given but not supported
57  if (($unsupportedOptions = array_diff_key(‪$options, $this->supportedOptions)) !== []) {
58  throw new ‪InvalidValidationOptionsException('Unsupported validation option(s) found: ' . implode(', ', array_keys($unsupportedOptions)), 1339079804);
59  }
60 
61  // check for required options being set
62  array_walk(
63  $this->supportedOptions,
64  function ($supportedOptionData, $supportedOptionName, ‪$options) {
65  if (isset($supportedOptionData[3]) && !array_key_exists($supportedOptionName, ‪$options)) {
66  throw new ‪InvalidValidationOptionsException('Required validation option not set: ' . $supportedOptionName, 1339163922);
67  }
68  },
70  );
71 
72  // merge with default values
73  $this->options = array_merge(
74  array_map(
75  function ($value) {
76  return $value[0];
77  },
79  ),
81  );
82  $this->validators = new \SplObjectStorage();
83  }
84 
91  {
93  // @todo: provide bugfix as soon as it is fixed in TYPO3.Flow (https://forge.typo3.org/issues/48093)
94  ‪$validator->setValidatedInstancesContainer = ‪$this->validatedInstancesContainer;
95  }
96  $this->validators->attach(‪$validator);
97  }
98 
105  public function ‪removeValidator(ValidatorInterface ‪$validator)
106  {
107  if (!$this->validators->contains(‪$validator)) {
108  throw new NoSuchValidatorException('Cannot remove validator because its not in the conjunction.', 1207020177);
109  }
110  $this->validators->detach(‪$validator);
111  }
112 
118  public function ‪count()
119  {
120  return ‪count($this->validators);
121  }
122 
128  public function ‪getValidators()
129  {
130  return ‪$this->validators;
131  }
132 
138  public function ‪getOptions()
139  {
140  return ‪$this->options;
141  }
142 
148  public function ‪setValidatedInstancesContainer(\SplObjectStorage ‪$validatedInstancesContainer)
149  {
150  $this->validatedInstancesContainer = ‪$validatedInstancesContainer;
151  }
152 }
‪TYPO3\CMS\Extbase\Validation\Validator\ObjectValidatorInterface
Definition: ObjectValidatorInterface.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\$validators
‪SplObjectStorage $validators
Definition: AbstractCompositeValidator.php:38
‪TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException
Definition: NoSuchValidatorException.php:26
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\$supportedOptions
‪array $supportedOptions
Definition: AbstractCompositeValidator.php:30
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\setValidatedInstancesContainer
‪setValidatedInstancesContainer(\SplObjectStorage $validatedInstancesContainer)
Definition: AbstractCompositeValidator.php:144
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\getValidators
‪SplObjectStorage getValidators()
Definition: AbstractCompositeValidator.php:124
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\$options
‪array $options
Definition: AbstractCompositeValidator.php:34
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\count
‪int count()
Definition: AbstractCompositeValidator.php:114
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\$validatedInstancesContainer
‪SplObjectStorage $validatedInstancesContainer
Definition: AbstractCompositeValidator.php:42
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\addValidator
‪addValidator(ValidatorInterface $validator)
Definition: AbstractCompositeValidator.php:86
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\__construct
‪__construct(array $options=[])
Definition: AbstractCompositeValidator.php:50
‪TYPO3\CMS\Extbase\Validation\Validator
Definition: AbstractCompositeValidator.php:16
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\removeValidator
‪removeValidator(ValidatorInterface $validator)
Definition: AbstractCompositeValidator.php:101
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:22
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator
Definition: AbstractCompositeValidator.php:25
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\getOptions
‪array getOptions()
Definition: AbstractCompositeValidator.php:134
‪TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException
Definition: InvalidValidationOptionsException.php:26