interface ValidationVisitorInterface
deprecated
since version 2.5, to be removed in 3.0.
Validates values against constraints defined in {@link MetadataInterface} instances.
This interface is an implementation of the Visitor design pattern. A value is validated by first passing it to the {@link validate} method. That method will determine the matching {@link MetadataInterface} for validating the value. It then calls the {@link MetadataInterface::accept} method of that metadata. accept() does two things:
- It calls {@link visit} to validate the value against the constraints of the metadata.
- It calls accept() on all nested metadata instances with the corresponding values extracted from the current value. For example, if the current metadata represents a class and the current value is an object of that class, the metadata contains nested instances for each property of that class. It forwards the call to these nested metadata with the values of the corresponding properties in the original object.
Methods
validate(mixed $value, string $group, string $propertyPath, bool $traverse = false, bool $deep = false) Validates a value. | ||
visit(MetadataInterface $metadata, mixed $value, string $group, string $propertyPath) Validates a value against the constraints defined in some metadata. |
Details
validate(mixed $value, string $group, string $propertyPath, bool $traverse = false, bool $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.
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}.
Please login to continue.