Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ExpressionSyntaxValidator.php

function ExpressionSyntaxValidator::validate

Overrides ConstraintValidatorInterface::validate

File

vendor/symfony/validator/Constraints/ExpressionSyntaxValidator.php, line 31

Class

ExpressionSyntaxValidator
@author Andrey Sevastianov <mrpkmail@gmail.com>

Namespace

Symfony\Component\Validator\Constraints

Code

public function validate(mixed $expression, Constraint $constraint) : void {
    if (!$constraint instanceof ExpressionSyntax) {
        throw new UnexpectedTypeException($constraint, ExpressionSyntax::class);
    }
    if (null === $expression || '' === $expression) {
        return;
    }
    if (!\is_string($expression) && !$expression instanceof \Stringable) {
        throw new UnexpectedValueException($expression, 'string');
    }
    $this->expressionLanguage ??= new ExpressionLanguage();
    try {
        $this->expressionLanguage
            ->lint($expression, $constraint->allowedVariables);
    } catch (SyntaxError $exception) {
        $this->context
            ->buildViolation($constraint->message)
            ->setParameter('{{ syntax_error }}', $this->formatValue($exception->getMessage()))
            ->setInvalidValue((string) $expression)
            ->setCode(ExpressionSyntax::EXPRESSION_SYNTAX_ERROR)
            ->addViolation();
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal