/**
  * 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));
     }
 }
 /**
  * Collects the base validators which were defined for the data type of each
  * controller argument and adds them to the argument's validator chain.
  *
  * @return void
  */
 public function initializeControllerArgumentsBaseValidators()
 {
     foreach ($this->arguments as $argument) {
         $validator = $this->validatorResolver->getBaseValidatorConjunction($argument->getDataType());
         if ($validator !== NULL) {
             $argument->setValidator($validator);
         }
     }
 }
Example #3
0
 /**
  * Collects the base validators which were defined for the data type of each
  * controller argument and adds them to the argument's validator chain.
  *
  * @return void
  */
 public function initializeControllerArgumentsBaseValidators()
 {
     /** @var \TYPO3\CMS\Extbase\Mvc\Controller\Argument $argument */
     foreach ($this->arguments as $argument) {
         $validator = $this->validatorResolver->getBaseValidatorConjunction($argument->getDataType());
         if ($validator !== null) {
             $argument->setValidator($validator);
         }
     }
 }
 /**
  * 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));
     }
 }
 /**
  * @test
  */
 public function collectionValidatorCallsCollectionElementValidatorWhenValidatingObjectStorages()
 {
     $entity = new \TYPO3\CMS\Extbase\Tests\Fixture\Entity('Foo');
     $elementType = \TYPO3\CMS\Extbase\Tests\Fixture\Entity::class;
     $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     $objectStorage->attach($entity);
     $aValidator = new \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator(array());
     $this->mockValidatorResolver->expects($this->never())->method('createValidator');
     $this->mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with($elementType)->will($this->returnValue($aValidator));
     $this->validator->_set('options', array('elementType' => $elementType));
     $this->validator->validate($objectStorage);
 }
 /**
  * We need to override this method to get the validate annotations also from TypoScript Configuration
  *
  * @param string $className
  * @param string $methodName
  *
  * @return array
  */
 public function getMethodValidateAnnotations($className, $methodName)
 {
     $validateAnnotations = parent::getMethodValidateAnnotations($className, $methodName);
     $methodParameters = $this->reflectionService->getMethodParameters($className, $methodName);
     foreach ($methodParameters as $argumentName => $methodParameterValue) {
         if (isset($this->settings[$className][$methodName][$argumentName])) {
             $overwriteDefaultValidation = isset($this->settings[$className][$methodName][$argumentName]['overwriteDefaultValidation']) ? (bool) $this->settings[$className][$methodName][$argumentName]['overwriteDefaultValidation'] : FALSE;
             array_push($validateAnnotations, array('argumentName' => $argumentName, 'validatorName' => \Portrino\PxValidation\Domain\Validator\TypoScriptValidator::class, 'validatorOptions' => array('className' => $className, 'methodName' => $methodName, 'argumentName' => $argumentName, 'overwriteDefaultValidation' => $overwriteDefaultValidation)));
         }
     }
     return $validateAnnotations;
 }
 /**
  * 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);
 }