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

Breadcrumb

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

class ExpressionValidator

@author Fabien Potencier <fabien@symfony.com> @author Bernhard Schussek <bschussek@symfony.com>

Hierarchy

  • class \Symfony\Component\Validator\ConstraintValidator implements \Symfony\Component\Validator\ConstraintValidatorInterface
    • class \Symfony\Component\Validator\Constraints\ExpressionValidator extends \Symfony\Component\Validator\ConstraintValidator

Expanded class hierarchy of ExpressionValidator

1 file declares its use of ExpressionValidator
ConstraintValidatorFactory.php in vendor/symfony/validator/ConstraintValidatorFactory.php

File

vendor/symfony/validator/Constraints/ExpressionValidator.php, line 23

Namespace

Symfony\Component\Validator\Constraints
View source
class ExpressionValidator extends ConstraintValidator {
    private ExpressionLanguage $expressionLanguage;
    public function __construct(?ExpressionLanguage $expressionLanguage = null) {
        if ($expressionLanguage) {
            $this->expressionLanguage = $expressionLanguage;
        }
    }
    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();
        }
    }
    private function getExpressionLanguage() : ExpressionLanguage {
        if (!isset($this->expressionLanguage)) {
            $this->expressionLanguage = new ExpressionLanguage();
            $this->expressionLanguage
                ->registerProvider(new ExpressionLanguageProvider());
        }
        return $this->expressionLanguage;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ConstraintValidator::$context protected property
ConstraintValidator::formatTypeOf protected function Returns a string representation of the type of the value.
ConstraintValidator::formatValue protected function Returns a string representation of the value.
ConstraintValidator::formatValues protected function Returns a string representation of a list of values.
ConstraintValidator::initialize public function Initializes the constraint validator. Overrides ConstraintValidatorInterface::initialize
ConstraintValidator::OBJECT_TO_STRING public constant Whether to cast objects with a &quot;__toString()&quot; method to strings.
ConstraintValidator::PRETTY_DATE public constant Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter}
(if it is available) or as RFC-3339 dates (&quot;Y-m-d H:i:s&quot;).
ExpressionValidator::$expressionLanguage private property
ExpressionValidator::getExpressionLanguage private function
ExpressionValidator::validate public function Checks if the passed value is valid. Overrides ConstraintValidatorInterface::validate
ExpressionValidator::__construct public function
RSS feed
Powered by Drupal