function ExpressionValidator::validate
Overrides ConstraintValidatorInterface::validate
File
-
vendor/
symfony/ validator/ Constraints/ ExpressionValidator.php, line 34
Class
- ExpressionValidator
- @author Fabien Potencier <fabien@symfony.com> @author Bernhard Schussek <bschussek@symfony.com>
Namespace
Symfony\Component\Validator\ConstraintsCode
public function validate(mixed $value, Constraint $constraint) : void {
if (!$constraint instanceof Expression) {
throw new UnexpectedTypeException($constraint, Expression::class);
}
$variables = $constraint->values;
$variables['value'] = $value;
$variables['this'] = $this->context
->getObject();
$variables['context'] = $this->context;
if ($constraint->negate xor $this->getExpressionLanguage()
->evaluate($constraint->expression, $variables)) {
$this->context
->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value, self::OBJECT_TO_STRING))
->setCode(Expression::EXPRESSION_FAILED_ERROR)
->addViolation();
}
}