- md5
- 17e990e971028fb1199bc6807947621b
- sha1
- 3100f4b03691b8a5cfeb54532fd8dc046da5127b
- sha256
- 31536807acb2a991bcdacffb2683afe54f95c1011f54eb81961b0307b48525a3
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\SyntaxError;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Exception\UnexpectedValueException;
/**
* @author Andrey Sevastianov <[email protected]>
*/
class ExpressionSyntaxValidator extends ConstraintValidator
{
private ?ExpressionLanguage $expressionLanguage;
public function __construct(?ExpressionLanguage $expressionLanguage = null)
{
$this->expressionLanguage = $expressionLanguage;
}
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)) {
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();
}
}
}
The same content is in 136 releases, Joomla 5.1.0-beta1 to 6.3.0-alpha1. See them all, or every version of this file.