ValidatorResolver
class ValidatorResolver (View source)
Validator resolver to automatically find a appropriate validator for a given subject
Constants
PATTERN_MATCH_VALIDATORS |
Match validator names and options |
PATTERN_MATCH_VALIDATOROPTIONS |
Match validator options (to parse actual options) |
Properties
protected ObjectManagerInterface | $objectManager | ||
protected ReflectionService | $reflectionService | ||
protected array | $baseValidatorConjunctions |
Methods
Get a validator for a given data type. Returns a validator implementing the ValidatorInterface or NULL if no validator could be resolved.
Resolves and returns the base validator conjunction for the given data type.
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
Resets the baseValidatorConjunctions It is usually not required to reset the ValidatorResolver during one request. This method is mainly useful for functional tests
Builds a chain of nested object validators by specification of the given object path.
Builds a base validator conjunction for the given data type.
This adds custom validators to the passed $conjunctionValidator.
Returns a map of object validator class names.
Returns the class name of an appropriate validator for the given type. If no validator is available false is returned
Returns all class names implementing the ValidatorInterface.
Used to map PHP types to validator types.
Details
ValidatorInterface
createValidator(string $validatorType, array $validatorOptions = [])
Get a validator for a given data type. Returns a validator implementing the ValidatorInterface or NULL if no validator could be resolved.
ConjunctionValidator
getBaseValidatorConjunction(string $targetClassName, array $validationGroups = ['Default'])
Resolves and returns the base validator conjunction for the given data type.
If no validation is necessary, the returned validator is empty.
ConjunctionValidator[]
buildMethodArgumentsValidatorConjunctions(string $className, string $methodName, array $methodParameters = null, array $methodValidateAnnotations = null)
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
void
reset()
Resets the baseValidatorConjunctions It is usually not required to reset the ValidatorResolver during one request. This method is mainly useful for functional tests
protected GenericObjectValidator
buildSubObjectValidator(array $objectPath, ValidatorInterface $propertyValidator)
Builds a chain of nested object validators by specification of the given object path.
protected void
buildBaseValidatorConjunction(string $indexKey, string $targetClassName, array $validationGroups)
Builds a base validator conjunction for the given data type.
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 void
addCustomValidators(string $targetClassName, ConjunctionValidator $conjunctionValidator)
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.
static array
getPolyTypeObjectValidatorImplementationClassNames(ObjectManagerInterface $objectManager)
Returns a map of object validator class names.
protected string|bool
resolveValidatorObjectName(string $validatorType)
Returns the class name of an appropriate validator for the given type. If no validator is available false is returned
static array
getValidatorImplementationClassNames(ObjectManagerInterface $objectManager)
Returns all class names implementing the ValidatorInterface.
protected string
getValidatorType(string $type)
Used to map PHP types to validator types.