/** * Checks for a collection and if needed validates the items in the collection. * This is done with the specified element validator or a validator based on * the given element type and validation group. * * Either elementValidator or elementType must be given, otherwise validation * will be skipped. * * @param mixed $value A collection to be validated * @return void * @todo: method must be protected once the old property mapper is removed */ public function isValid($value) { if (!$this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) { // @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1 if ($this->validatedInstancesContainer == NULL) { $this->validatedInstancesContainer = new \SplObjectStorage(); } if ($this->result == NULL) { $this->result = new \TYPO3\CMS\Extbase\Error\Result(); } } foreach ($value as $index => $collectionElement) { if (isset($this->options['elementValidator'])) { $collectionElementValidator = $this->validatorResolver->createValidator($this->options['elementValidator']); } elseif (isset($this->options['elementType'])) { if (isset($this->options['validationGroups'])) { $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType'], $this->options['validationGroups']); } else { $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType']); } } else { return; } if ($collectionElementValidator instanceof ObjectValidatorInterface) { $collectionElementValidator->setValidatedInstancesContainer($this->validatedInstancesContainer); } $this->result->forProperty($index)->merge($collectionElementValidator->validate($collectionElement)); } }
/** * Checks for a collection and if needed validates the items in the collection. * This is done with the specified element validator or a validator based on * the given element type and validation group. * * Either elementValidator or elementType must be given, otherwise validation * will be skipped. * * @param mixed $value A collection to be validated * @return void */ protected function isValid($value) { foreach ($value as $index => $collectionElement) { if (isset($this->options['elementValidator'])) { $collectionElementValidator = $this->validatorResolver->createValidator($this->options['elementValidator']); } elseif (isset($this->options['elementType'])) { if (isset($this->options['validationGroups'])) { $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType'], $this->options['validationGroups']); } else { $collectionElementValidator = $this->validatorResolver->getBaseValidatorConjunction($this->options['elementType']); } } else { return; } if ($collectionElementValidator instanceof ObjectValidatorInterface) { $collectionElementValidator->setValidatedInstancesContainer($this->validatedInstancesContainer); } $this->result->forProperty($index)->merge($collectionElementValidator->validate($collectionElement)); } }
/** * See ValidatorResolver::createValidator() for more information * * @param string $type Shorthand notation of an application validator * @param array $options Options for the validator instance * * @return ValidatorInterface */ private function getValidatorFromResolver($type, array $options = []) { return $this->validatorResolver->createValidator($type, $options); }