Symfony\Component\Validator\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 ). 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 ) of the context point to the <tt>Person</tt>
instance. The property path is empty at this point (see ).
The metadata of the context is the metadata of the <tt>Person</tt> node
(see ).
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
) which for example returns a or a object. he context also contains the
validation group that is currently being validated (see ) and
the violations that happened up until now (see ).
Apart from reading the execution context, you can also use
or to add new violations and
or to validate values that the
validator otherwise would not reach.
- Author: Bernhard Schussek <bschussek@gmail.com>
Synopsis
- // methods
- public void addViolation()
- public void addViolationAt()
- public void validate()
- public void validateValue()
- public ConstraintViolationListInterface getViolations()
- public mixed getRoot()
- public mixed getValue()
- public MetadataInterface|null getMetadata()
- public MetadataFactoryInterface getMetadataFactory()
- public string getGroup()
- public string|null getClassName()
- public string|null getPropertyName()
- public string getPropertyPath()
Methods
public
- addViolation() — Adds a violation at the current node of the validation graph.
- addViolationAt() — Adds a violation at the validation graph node with the given property path relative to the current property path.
- getClassName() — Returns the class name of the current node.
- getGroup() — Returns the validation group that is currently being validated.
- getMetadata() — Returns the metadata for the currently validated value.
- getMetadataFactory() — Returns the used metadata factory.
- getPropertyName() — Returns the property name of the current node.
- getPropertyPath() — Returns the property path to the value that the validator is currently validating.
- getRoot() — Returns the value at which validation was started in the object graph.
- getValue() — Returns the value that the validator is currently validating.
- getViolations() — Returns the violations generated by the validator so far.
- validate() — Validates the given value within the scope of the current validation.
- validateValue() — Validates a value against a constraint.