PHP Class Neos\Flow\Validation\ValidatorResolver

Show file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$baseValidatorConjunctions array
$objectManager Neos\Flow\ObjectManagement\ObjectManagerInterface
$reflectionService Neos\Flow\Reflection\ReflectionService

Public Methods

Method Description
buildMethodArgumentsValidatorConjunctions ( string $className, string $methodName, array $methodParameters = null, array $methodValidateAnnotations = null ) : array Detects and registers any validators for arguments: - by the data type specified in the param annotations - additional validators specified in the validate annotations of a method
createValidator ( string $validatorType, array $validatorOptions = [] ) : Neos\Flow\Validation\Validator\ValidatorInterface Get a validator for a given data type. Returns a validator implementing the ValidatorInterface or NULL if no validator could be resolved.
getBaseValidatorConjunction ( string $targetClassName, array $validationGroups = ['Default'] ) : ConjunctionValidator Resolves and returns the base validator conjunction for the given data type.
getPolyTypeObjectValidatorImplementationClassNames ( Neos\Flow\ObjectManagement\ObjectManagerInterface $objectManager ) : array Returns a map of object validator class names.
getValidatorImplementationClassNames ( Neos\Flow\ObjectManagement\ObjectManagerInterface $objectManager ) : array Returns all class names implementing the ValidatorInterface.
reset ( ) : void Resets the baseValidatorConjunctions It is usually not required to reset the ValidatorResolver during one request. This method is mainly useful for functional tests

Protected Methods

Method Description
addCustomValidators ( string $targetClassName, ConjunctionValidator &$conjunctionValidator ) : null | Neos\Flow\Validation\Validator\ObjectValidatorInterface This adds custom validators to the passed $conjunctionValidator.
buildBaseValidatorConjunction ( string $indexKey, string $targetClassName, array $validationGroups ) : void Builds a base validator conjunction for the given data type.
buildSubObjectValidator ( array $objectPath, Neos\Flow\Validation\Validator\ValidatorInterface $propertyValidator ) : GenericObjectValidator Builds a chain of nested object validators by specification of the given object path.
getValidatorType ( string $type ) : string Used to map PHP types to validator types.
resolveValidatorObjectName ( string $validatorType ) : string | boolean Returns the class name of an appropriate validator for the given type. If no validator is available FALSE is returned

Method Details

addCustomValidators() protected method

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.
protected addCustomValidators ( string $targetClassName, ConjunctionValidator &$conjunctionValidator ) : null | Neos\Flow\Validation\Validator\ObjectValidatorInterface
$targetClassName string
$conjunctionValidator Neos\Flow\Validation\Validator\ConjunctionValidator
return null | Neos\Flow\Validation\Validator\ObjectValidatorInterface

buildBaseValidatorConjunction() protected method

The base validation rules are those which were declared directly in a class (typically a model) through some validate annotations on properties. If a property holds a class for which a base validator exists, that property will be checked as well, regardless of a validate annotation Additionally, if a custom validator was defined for the class in question, it will be added to the end of the conjunction. A custom validator is found if it follows the naming convention "Replace '\Model\' by '\Validator\' and append 'Validator'". Example: $targetClassName is Neos\Foo\Domain\Model\Quux, then the validator will be found if it has the name Neos\Foo\Domain\Validator\QuuxValidator
protected buildBaseValidatorConjunction ( string $indexKey, string $targetClassName, array $validationGroups ) : void
$indexKey string The key to use as index in $this->baseValidatorConjunctions; calculated from target class name and validation groups
$targetClassName string The data type to build the validation conjunction for. Needs to be the fully qualified class name.
$validationGroups array The validation groups to build the validator for
return void

buildMethodArgumentsValidatorConjunctions() public method

Detects and registers any validators for arguments: - by the data type specified in the param annotations - additional validators specified in the validate annotations of a method
public buildMethodArgumentsValidatorConjunctions ( string $className, string $methodName, array $methodParameters = null, array $methodValidateAnnotations = null ) : array
$className string
$methodName string
$methodParameters array Optional pre-compiled array of method parameters
$methodValidateAnnotations array Optional pre-compiled array of validate annotations (as array)
return array An Array of ValidatorConjunctions for each method parameters.

buildSubObjectValidator() protected method

Builds a chain of nested object validators by specification of the given object path.
protected buildSubObjectValidator ( array $objectPath, Neos\Flow\Validation\Validator\ValidatorInterface $propertyValidator ) : GenericObjectValidator
$objectPath array The object path
$propertyValidator Neos\Flow\Validation\Validator\ValidatorInterface The validator which should be added to the property specified by objectPath
return Neos\Flow\Validation\Validator\GenericObjectValidator

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

getBaseValidatorConjunction() public method

If no validation is necessary, the returned validator is empty.
public getBaseValidatorConjunction ( string $targetClassName, array $validationGroups = ['Default'] ) : ConjunctionValidator
$targetClassName string Fully qualified class name of the target class, ie. the class which should be validated
$validationGroups array The validation groups to build the validator for
return Neos\Flow\Validation\Validator\ConjunctionValidator The validator conjunction

getPolyTypeObjectValidatorImplementationClassNames() public static method

Returns a map of object validator class names.
public static getPolyTypeObjectValidatorImplementationClassNames ( Neos\Flow\ObjectManagement\ObjectManagerInterface $objectManager ) : array
$objectManager Neos\Flow\ObjectManagement\ObjectManagerInterface
return array Array of object validator class names

getValidatorImplementationClassNames() public static method

Returns all class names implementing the ValidatorInterface.
public static getValidatorImplementationClassNames ( Neos\Flow\ObjectManagement\ObjectManagerInterface $objectManager ) : array
$objectManager Neos\Flow\ObjectManagement\ObjectManagerInterface
return array Array of class names implementing ValidatorInterface indexed by class name

getValidatorType() protected method

Used to map PHP types to validator types.
protected getValidatorType ( string $type ) : string
$type string Data type to unify
return string unified data type

reset() public method

Resets the baseValidatorConjunctions It is usually not required to reset the ValidatorResolver during one request. This method is mainly useful for functional tests
public reset ( ) : void
return void

resolveValidatorObjectName() protected method

Returns the class name of an appropriate validator for the given type. If no validator is available FALSE is returned
protected resolveValidatorObjectName ( string $validatorType ) : string | boolean
$validatorType string Either the fully qualified class name of the validator or the short name of a built-in validator
return string | boolean Class name of the validator or FALSE if not available

Property Details

$baseValidatorConjunctions protected property

protected array $baseValidatorConjunctions
return array

$objectManager protected property

protected ObjectManagerInterface,Neos\Flow\ObjectManagement $objectManager
return Neos\Flow\ObjectManagement\ObjectManagerInterface

$reflectionService protected property

protected ReflectionService,Neos\Flow\Reflection $reflectionService
return Neos\Flow\Reflection\ReflectionService