You are here

public function Validator::validateValue in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/validator/Validator.php \Symfony\Component\Validator\Validator::validateValue()

Validates a value against a constraint or a list of constraints.

Parameters

mixed $value The value to validate.:

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

array|null $groups The validation groups to validate.:

Return value

ConstraintViolationListInterface A list of constraint violations. If the list is empty, validation succeeded.

Overrides ValidatorInterface::validateValue

Deprecated

since version 2.5, to be removed in 3.0. Renamed to {@link Validator\ValidatorInterface::validate()} in Symfony 2.5.

File

vendor/symfony/validator/Validator.php, line 177

Class

Validator
Default implementation of {@link ValidatorInterface}.

Namespace

Symfony\Component\Validator

Code

public function validateValue($value, $constraints, $groups = null) {
  $context = new ExecutionContext($this
    ->createVisitor($value), $this->translator, $this->translationDomain);
  $constraints = is_array($constraints) ? $constraints : array(
    $constraints,
  );
  foreach ($constraints as $constraint) {
    if ($constraint instanceof Valid) {

      // Why can't the Valid constraint be executed directly?
      //
      // It cannot be executed like regular other constraints, because regular
      // constraints are only executed *if they belong to the validated group*.
      // The Valid constraint, on the other hand, is always executed and propagates
      // the group to the cascaded object. The propagated group depends on
      //
      //  * Whether a group sequence is currently being executed. Then the default
      //    group is propagated.
      //
      //  * Otherwise the validated group is propagated.
      throw new ValidatorException(sprintf('The constraint %s cannot be validated. Use the method validate() instead.', get_class($constraint)));
    }
    $context
      ->validateValue($value, $constraint, '', $groups);
  }
  return $context
    ->getViolations();
}