interface ExecutionContextInterface

Stores the validator's state during validation.

For example, let's validate the following object graph:

<pre> (Person)---($firstName: string) \ ($address: Address)---($street: string) </pre>

We validate the <tt>Person</tt> instance, which becomes the "root" of the validation run (see {@link getRoot}). The state of the context after the first step will be like this:

<pre> (Person)---($firstName: string) ^ \ ($address: Address)---($street: string) </pre>

The validator is stopped at the <tt>Person</tt> node, both the root and the value (see {@link getValue}) of the context point to the <tt>Person</tt> instance. The property path is empty at this point (see {@link getPropertyPath}). The metadata of the context is the metadata of the <tt>Person</tt> node (see {@link getMetadata}).

After advancing to the property <tt>$firstName</tt> of the <tt>Person</tt> instance, the state of the context looks like this:

<pre> (Person)---($firstName: string) \ ^ ($address: Address)---($street: string) </pre>

The validator is stopped at the property <tt>$firstName</tt>. The root still points to the <tt>Person</tt> instance, because this is where the validation started. The property path is now "firstName" and the current value is the value of that property.

After advancing to the <tt>$address</tt> property and then to the <tt>$street</tt> property of the <tt>Address</tt> instance, the context state looks like this:

<pre> (Person)---($firstName: string) \ ($address: Address)---($street: string) ^ </pre>

The validator is stopped at the property <tt>$street</tt>. The root still points to the <tt>Person</tt> instance, but the property path is now "address.street" and the validated value is the value of that property.

Apart from the root, the property path and the currently validated value, the execution context also knows the metadata of the current node (see {@link getMetadata}) which for example returns a {@link Mapping\PropertyMetadata} or a {@link Mapping\ClassMetadata} object. he context also contains the validation group that is currently being validated (see {@link getGroup}) and the violations that happened up until now (see {@link getViolations}).

Apart from reading the execution context, you can also use {@link addViolation} or {@link addViolationAt} to add new violations and {@link validate} or {@link validateValue} to validate values that the validator otherwise would not reach.

@author Bernhard Schussek <bschussek@gmail.com>

@api

Hierarchy

Expanded class hierarchy of ExecutionContextInterface

All classes that implement ExecutionContextInterface

1 file declares its use of ExecutionContextInterface

File

drupal/core/vendor/symfony/validator/Symfony/Component/Validator/ExecutionContextInterface.php, line 86

Namespace

Symfony\Component\Validator
View source

Members

Namesort descending Modifiers Type Description Overrides
ExecutionContextInterface::addViolation public function Adds a violation at the current node of the validation graph. 1
ExecutionContextInterface::addViolationAt public function Adds a violation at the validation graph node with the given property path relative to the current property path. 1
ExecutionContextInterface::getClassName public function Returns the class name of the current node. 1
ExecutionContextInterface::getGroup public function Returns the validation group that is currently being validated. 1
ExecutionContextInterface::getMetadata public function Returns the metadata for the currently validated value. 1
ExecutionContextInterface::getMetadataFactory public function Returns the used metadata factory. 1
ExecutionContextInterface::getPropertyName public function Returns the property name of the current node. 1
ExecutionContextInterface::getPropertyPath public function Returns the property path to the value that the validator is currently validating. 1
ExecutionContextInterface::getRoot public function Returns the value at which validation was started in the object graph. 1
ExecutionContextInterface::getValue public function Returns the value that the validator is currently validating. 1
ExecutionContextInterface::getViolations public function Returns the violations generated by the validator so far. 1
ExecutionContextInterface::validate public function Validates the given value within the scope of the current validation. 1
ExecutionContextInterface::validateValue public function Validates a value against a constraint. 1