Exemplo n.º 1
0
 /**
  * @test
  */
 public function buildBaseValidatorCachesTheResultOfTheBuildBaseValidatorConjunctionCalls()
 {
     $result1 = $this->validatorResolver->getBaseValidatorConjunction('TYPO3\\Virtual\\Foo');
     $this->assertInstanceOf('TYPO3\\FLOW3\\Validation\\Validator\\ConjunctionValidator', $result1, '#1');
     $result2 = $this->validatorResolver->getBaseValidatorConjunction('TYPO3\\Virtual\\Foo');
     $this->assertSame($result1, $result2, '#2');
 }
Exemplo n.º 2
0
 /**
  * Check if $value is valid. If it is not valid, needs to add an error
  * to Result.
  *
  * @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));
     }
 }
Exemplo n.º 3
0
 public function transform($data, $target)
 {
     $data = $this->cleanUpBlanks($data);
     $value = $this->propertyMapper->convert($data, $target, \Admin\Core\PropertyMappingConfiguration::getConfiguration());
     $this->validationResults = $this->propertyMapper->getMessages();
     $validator = $this->validatorResolver->getBaseValidatorConjunction($target);
     $validationMessages = $validator->validate($value);
     $this->validationResults->merge($validationMessages);
     $errors = $this->validationResults->getFlattenedErrors();
     if (empty($errors)) {
         return $value;
     } else {
         return $errors;
     }
 }
Exemplo n.º 4
0
 /**
  * Validates the given object and throws an exception if validation fails.
  *
  * @param object $object
  * @return void
  * @throws \TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException
  * @api
  */
 protected function validateObject($object)
 {
     $classSchema = $this->reflectionService->getClassSchema($object);
     $validator = $this->validatorResolver->getBaseValidatorConjunction($classSchema->getClassName());
     if ($validator === NULL) {
         return;
     }
     $validationResult = $validator->validate($object);
     if ($validationResult->hasErrors()) {
         $errorMessages = '';
         $allErrors = $validationResult->getFlattenedErrors();
         foreach ($allErrors as $path => $errors) {
             $errorMessages .= $path . ':' . PHP_EOL;
             foreach ($errors as $error) {
                 $errorMessages .= (string) $error . PHP_EOL;
             }
         }
         throw new \TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException('An instance of "' . get_class($object) . '" failed to pass validation with ' . count($errors) . ' error(s): ' . PHP_EOL . $errorMessages, 1322585162);
     }
 }
Exemplo n.º 5
0
 /**
  * Validates the given object and throws an exception if validation fails.
  *
  * @param object $object
  * @param \SplObjectStorage $validatedInstancesContainer
  * @return void
  * @throws \TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException
  */
 protected function validateObject($object, \SplObjectStorage $validatedInstancesContainer)
 {
     $className = $this->entityManager->getClassMetadata(get_class($object))->getName();
     $validator = $this->validatorResolver->getBaseValidatorConjunction($className, array('Persistence', 'Default'));
     if ($validator === NULL) {
         return;
     }
     $validator->setValidatedInstancesContainer($validatedInstancesContainer);
     $validationResult = $validator->validate($object);
     if ($validationResult->hasErrors()) {
         $errorMessages = '';
         $allErrors = $validationResult->getFlattenedErrors();
         foreach ($allErrors as $path => $errors) {
             $errorMessages .= $path . ':' . PHP_EOL;
             foreach ($errors as $error) {
                 $errorMessages .= (string) $error . PHP_EOL;
             }
         }
         throw new \TYPO3\FLOW3\Persistence\Exception\ObjectValidationFailedException('An instance of "' . get_class($object) . '" failed to pass validation with ' . count($errors) . ' error(s): ' . PHP_EOL . $errorMessages, 1322585164);
     }
 }