createValidator() public method

Get a validator for a given data type. Returns a validator implementing the ValidatorInterface or NULL if no validator could be resolved.
public createValidator ( string $validatorType, array $validatorOptions = [] ) : Neos\Flow\Validation\Validator\ValidatorInterface
$validatorType string Either one of the built-in data types or fully qualified validator class name
$validatorOptions array Options to be passed to the validator
return Neos\Flow\Validation\Validator\ValidatorInterface
 /**
  * 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'], $this->options['elementValidatorOptions']);
         } 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.º 2
0
 /**
  * Checks if the given value is a valid electronic address according to its type.
  *
  * If at least one error occurred, the result is FALSE and any errors can
  * be retrieved through the getErrors() method.
  *
  * @param mixed $value The value that should be validated
  * @return void
  */
 public function isValid($value)
 {
     if ($value instanceof ElectronicAddress) {
         $addressType = $value->getType();
         switch ($addressType) {
             case 'Email':
                 $addressValidator = $this->validatorResolver->createValidator('EmailAddress');
                 break;
             default:
                 $addressValidator = $this->validatorResolver->createValidator('Neos.Party:' . $addressType . 'Address');
         }
         if ($addressValidator === null) {
             $this->addError('No validator found for electronic address of type "' . $addressType . '".', 1268676030);
         } else {
             $result = $addressValidator->validate($value->getIdentifier());
             if ($result->hasErrors()) {
                 $this->result = $result;
             }
         }
     }
 }