‪TYPO3CMS  9.5
AbstractCompositeValidator.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
20 abstract class ‪AbstractCompositeValidator implements ‪ObjectValidatorInterface, \Countable
21 {
27  protected ‪$supportedOptions = [];
28 
32  protected ‪$options = [];
33 
37  protected ‪$validators;
38 
43 
50  public function ‪__construct(array ‪$options = [])
51  {
52  // check for options given but not supported
53  if (($unsupportedOptions = array_diff_key(‪$options, $this->supportedOptions)) !== []) {
54  throw new \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException('Unsupported validation option(s) found: ' . implode(', ', array_keys($unsupportedOptions)), 1339079804);
55  }
56 
57  // check for required options being set
58  array_walk(
59  $this->supportedOptions,
60  function ($supportedOptionData, $supportedOptionName, ‪$options) {
61  if (isset($supportedOptionData[3]) && !array_key_exists($supportedOptionName, ‪$options)) {
62  throw new \TYPO3\CMS\Extbase\Validation\Exception\InvalidValidationOptionsException('Required validation option not set: ' . $supportedOptionName, 1339163922);
63  }
64  },
66  );
67 
68  // merge with default values
69  $this->options = array_merge(
70  array_map(
71  function ($value) {
72  return $value[0];
73  },
75  ),
77  );
78  $this->validators = new \SplObjectStorage();
79  }
80 
86  public function ‪addValidator(\‪TYPO3\CMS\‪Extbase\Validation\Validator\‪ValidatorInterface ‪$validator)
87  {
89  // @todo: provide bugfix as soon as it is fixed in TYPO3.Flow (http://forge.typo3.org/issues/48093)
90  ‪$validator->setValidatedInstancesContainer = ‪$this->validatedInstancesContainer;
91  }
92  $this->validators->attach(‪$validator);
93  }
94 
101  public function ‪removeValidator(\‪TYPO3\CMS\‪Extbase\Validation\Validator\ValidatorInterface ‪$validator)
102  {
103  if (!$this->validators->contains(‪$validator)) {
104  throw new \TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException('Cannot remove validator because its not in the conjunction.', 1207020177);
105  }
106  $this->validators->detach(‪$validator);
107  }
108 
114  public function ‪count()
115  {
116  return ‪count($this->validators);
117  }
118 
124  public function ‪getValidators()
125  {
126  return ‪$this->validators;
127  }
128 
134  public function ‪getOptions()
135  {
136  return ‪$this->options;
137  }
138 
144  public function ‪setValidatedInstancesContainer(\SplObjectStorage ‪$validatedInstancesContainer)
145  {
146  $this->validatedInstancesContainer = ‪$validatedInstancesContainer;
147  }
148 }
‪TYPO3\CMS\Extbase\Validation\Validator\ObjectValidatorInterface
Definition: ObjectValidatorInterface.php:21
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\$validators
‪SplObjectStorage $validators
Definition: AbstractCompositeValidator.php:34
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\$supportedOptions
‪array $supportedOptions
Definition: AbstractCompositeValidator.php:26
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\setValidatedInstancesContainer
‪setValidatedInstancesContainer(\SplObjectStorage $validatedInstancesContainer)
Definition: AbstractCompositeValidator.php:140
‪TYPO3
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\getValidators
‪SplObjectStorage getValidators()
Definition: AbstractCompositeValidator.php:120
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\$options
‪array $options
Definition: AbstractCompositeValidator.php:30
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\removeValidator
‪removeValidator(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $validator)
Definition: AbstractCompositeValidator.php:97
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\count
‪int count()
Definition: AbstractCompositeValidator.php:110
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\$validatedInstancesContainer
‪SplObjectStorage $validatedInstancesContainer
Definition: AbstractCompositeValidator.php:38
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:218
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\__construct
‪__construct(array $options=[])
Definition: AbstractCompositeValidator.php:46
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\addValidator
‪addValidator(\TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface $validator)
Definition: AbstractCompositeValidator.php:82
‪TYPO3\CMS\Extbase\Validation\Validator
Definition: AbstractCompositeValidator.php:2
‪TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface
Definition: ValidatorInterface.php:21
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator
Definition: AbstractCompositeValidator.php:21
‪TYPO3\CMS\Extbase\Validation\Validator\AbstractCompositeValidator\getOptions
‪array getOptions()
Definition: AbstractCompositeValidator.php:130