예제 #1
0
 /**
  * @param mixed $value
  * @return mixed
  */
 public function process($value)
 {
     if ($this->dataType !== null) {
         $value = $this->propertyMapper->convert($value, $this->dataType, $this->propertyMappingConfiguration);
         $messages = $this->propertyMapper->getMessages();
     } else {
         $messages = new \TYPO3\Flow\Error\Result();
     }
     $validationResult = $this->validator->validate($value);
     $messages->merge($validationResult);
     $this->processingMessages->merge($messages);
     return $value;
 }
 /**
  * This adds custom validators to the passed $conjunctionValidator.
  *
  * A custom validator is found if it follows the naming convention "Replace '\Model\' by '\Validator\' and
  * append 'Validator'". If found, it will be added to the $conjunctionValidator.
  *
  * In addition canValidate() will be called on all implementations of the ObjectValidatorInterface to find
  * all validators that could validate the target. The one with the highest priority will be added as well.
  * If multiple validators have the same priority, which one will be added is not deterministic.
  *
  * @param string $targetClassName
  * @param ConjunctionValidator $conjunctionValidator
  * @return NULL|Validator\ObjectValidatorInterface
  */
 protected function addCustomValidators($targetClassName, ConjunctionValidator &$conjunctionValidator)
 {
     // Custom validator for the class
     $addedValidatorClassName = NULL;
     $possibleValidatorClassName = str_replace('\\Model\\', '\\Validator\\', $targetClassName) . 'Validator';
     $customValidator = $this->createValidator($possibleValidatorClassName);
     if ($customValidator !== NULL) {
         $conjunctionValidator->addValidator($customValidator);
         $addedValidatorClassName = get_class($customValidator);
     }
     // find polytype validator for class
     $acceptablePolyTypeValidators = array();
     $polyTypeObjectValidatorImplementationClassNames = static::getPolyTypeObjectValidatorImplementationClassNames($this->objectManager);
     foreach ($polyTypeObjectValidatorImplementationClassNames as $validatorImplementationClassName) {
         $acceptablePolyTypeValidator = $this->createValidator($validatorImplementationClassName);
         // skip custom validator already added above
         if ($addedValidatorClassName === get_class($acceptablePolyTypeValidator)) {
             continue;
         }
         if ($acceptablePolyTypeValidator->canValidate($targetClassName)) {
             $acceptablePolyTypeValidators[$acceptablePolyTypeValidator->getPriority()] = $acceptablePolyTypeValidator;
         }
     }
     if (count($acceptablePolyTypeValidators) > 0) {
         ksort($acceptablePolyTypeValidators);
         $conjunctionValidator->addValidator(array_pop($acceptablePolyTypeValidators));
     }
 }