You are here

public function ExecutionContext::validateValue in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/validator/ExecutionContext.php \Symfony\Component\Validator\ExecutionContext::validateValue()
  2. 8.0 vendor/symfony/validator/Context/ExecutionContext.php \Symfony\Component\Validator\Context\ExecutionContext::validateValue()
  3. 8.0 core/lib/Drupal/Core/TypedData/Validation/ExecutionContext.php \Drupal\Core\TypedData\Validation\ExecutionContext::validateValue()
Same name and namespace in other branches
  1. 8 vendor/symfony/validator/ExecutionContext.php \Symfony\Component\Validator\ExecutionContext::validateValue()

Validates a value against a constraint.

Use the parameter <tt>$subPath</tt> to adapt the property path for the validated value. For example, take the following object graph:

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

When the validator validates the <tt>Address</tt> instance, the property path stored in the execution context is "address". When you manually validate the property <tt>$street</tt> now, pass the sub path "street" to adapt the full property path to "address.street":

<pre> $context->validate($address->street, new NotNull(), 'street'); </pre>

Parameters

mixed $value The value to validate.:

Constraint|Constraint[] $constraints The constraint(s) to validate against.:

string $subPath The path to append to the context's property path.:

null|string|string[] $groups The groups to validate in. If you don't pass any: groups here, the current group of the context will be used.

Overrides ExecutionContextInterface::validateValue

Deprecated

since version 2.5, to be removed in 3.0. Use {@link Context\ExecutionContextInterface::getValidator()} instead.

File

vendor/symfony/validator/ExecutionContext.php, line 235

Class

ExecutionContext
Default implementation of {@link ExecutionContextInterface}.

Namespace

Symfony\Component\Validator

Code

public function validateValue($value, $constraints, $subPath = '', $groups = null) {
  $constraints = is_array($constraints) ? $constraints : array(
    $constraints,
  );
  if (null === $groups && '' === $subPath) {
    $context = clone $this;
    $context->value = $value;
    $context
      ->executeConstraintValidators($value, $constraints);
    return;
  }
  $propertyPath = $this
    ->getPropertyPath($subPath);
  foreach ($this
    ->resolveGroups($groups) as $group) {
    $context = clone $this;
    $context->value = $value;
    $context->group = $group;
    $context->propertyPath = $propertyPath;
    $context
      ->executeConstraintValidators($value, $constraints);
  }
}