class ValidationVisitor implements ValidationVisitorInterface, GlobalExecutionContextInterface

Default implementation of {@link ValidationVisitorInterface} and {@link GlobalExecutionContextInterface}.

Methods

__construct(mixed $root, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, TranslatorInterface $translator, string|null $translationDomain = null, array $objectInitializers = array())

Creates a new validation visitor.

visit(MetadataInterface $metadata, mixed $value, string $group, string $propertyPath)

Validates a value against the constraints defined in some metadata.

validate(mixed $value, string $group, string $propertyPath, Boolean $traverse = false, Boolean $deep = false)

Validates a value.

getViolations()

Returns the violations generated by the validator so far.

mixed
getRoot()

Returns the value at which validation was started in the object graph.

getVisitor()

Returns the visitor instance used to validate the object graph nodes.

getValidatorFactory()

Returns the factory for constraint validators.

getMetadataFactory()

Returns the factory for validation metadata objects.

Details

at line line 78
__construct(mixed $root, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, TranslatorInterface $translator, string|null $translationDomain = null, array $objectInitializers = array())

Creates a new validation visitor.

Parameters

mixed $root The value passed to the validator.
MetadataFactoryInterface $metadataFactory The factory for obtaining metadata instances.
ConstraintValidatorFactoryInterface $validatorFactory The factory for creating constraint validators.
TranslatorInterface $translator The translator for translating violation messages.
string|null $translationDomain The domain of the translation messages.
array $objectInitializers The initializers for preparing objects before validation.

Exceptions

UnexpectedTypeException If any of the object initializers is not an instance of ObjectInitializerInterface

at line line 98
visit(MetadataInterface $metadata, mixed $value, string $group, string $propertyPath)

Validates a value against the constraints defined in some metadata.

This method implements the Visitor design pattern. See also {@link ValidationVisitorInterface}.

Parameters

MetadataInterface $metadata The metadata holding the constraints.
mixed $value The value to validate.
string $group The validation group to validate.
string $propertyPath The current property path in the validation graph.

at line line 116
validate(mixed $value, string $group, string $propertyPath, Boolean $traverse = false, Boolean $deep = false)

Validates a value.

If the value is an array or a traversable object, you can set the parameter $traverse to true in order to run through the collection and validate each element. If these elements can be collections again and you want to traverse them recursively, set the parameter $deep to true as well.

If you set $traversable to true, the visitor will nevertheless try to find metadata for the collection and validate its constraints. If no such metadata is found, the visitor ignores that and only iterates the collection.

If you don't set $traversable to true and the visitor does not find metadata for the given value, it will fail with an exception.

Parameters

mixed $value The value to validate.
string $group The validation group to validate.
string $propertyPath The current property path in the validation graph.
Boolean $traverse Whether to traverse the value if it is traversable.
Boolean $deep Whether to traverse nested traversable values recursively.

Exceptions

NoSuchMetadataException If no metadata can be found for the given value.

at line line 169
ConstraintViolationListInterface getViolations()

Returns the violations generated by the validator so far.

Return Value

ConstraintViolationListInterface A list of constraint violations.

at line line 177
mixed getRoot()

Returns the value at which validation was started in the object graph.

Return Value

mixed The root value.

at line line 185
ValidationVisitorInterface getVisitor()

Returns the visitor instance used to validate the object graph nodes.

Return Value

ValidationVisitorInterface The validation visitor.

at line line 193
ConstraintValidatorFactoryInterface getValidatorFactory()

Returns the factory for constraint validators.

Return Value

ConstraintValidatorFactoryInterface The constraint validator factory.

at line line 201
MetadataFactoryInterface getMetadataFactory()

Returns the factory for validation metadata objects.

Return Value

MetadataFactoryInterface The metadata factory.