Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 42e6a4e

Browse filesBrowse files
committed
[ExpressionLanguage] Added expression language syntax validator
- move expression language syntax constraints to validator component
1 parent d01fdc9 commit 42e6a4e
Copy full SHA for 42e6a4e

File tree

6 files changed

+21
-13
lines changed
Filter options

6 files changed

+21
-13
lines changed

‎src/Symfony/Component/ExpressionLanguage/Parser.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/Parser.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function __construct(array $functions)
9393
public function parse(TokenStream $stream, array $names = [])
9494
{
9595
$this->lint = false;
96+
9697
return $this->doParse($stream, $names);
9798
}
9899

@@ -116,7 +117,7 @@ protected function doParse(TokenStream $stream, ?array $names = [])
116117
$this->names = $names;
117118

118119
$node = $this->parseExpression();
119-
if (!$this->stream->isEOF()) {
120+
if (!$stream->isEOF()) {
120121
throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s"', $stream->current->type, $stream->current->value), $stream->current->cursor, $stream->getExpression());
121122
}
122123

‎src/Symfony/Component/ExpressionLanguage/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/ExpressionLanguage/composer.json
-6Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
"symfony/cache": "^4.4|^5.0",
2121
"symfony/service-contracts": "^1.1|^2"
2222
},
23-
"require-dev": {
24-
"symfony/validator": "^4.4|^5.0"
25-
},
26-
"suggest": {
27-
"symfony/validator": "For using the expression language syntax constraint"
28-
},
2923
"autoload": {
3024
"psr-4": { "Symfony\\Component\\ExpressionLanguage\\": "" },
3125
"exclude-from-classmap": [
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\ExpressionLanguage\Validator\Constraints;
12+
namespace Symfony\Component\Validator\Constraints;
1313

1414
use Symfony\Component\Validator\Constraint;
1515

1616
/**
1717
* @Annotation
1818
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
19+
*
20+
* @author Andrey Sevastianov <mrpkmail@gmail.com>
1921
*/
2022
class ExpressionLanguageSyntax extends Constraint
2123
{
24+
const EXPRESSION_LANGUAGE_SYNTAX_ERROR = '1766a3f3-ff03-40eb-b053-ab7aa23d988a';
25+
26+
protected static $errorNames = [
27+
self::EXPRESSION_LANGUAGE_SYNTAX_ERROR => 'EXPRESSION_LANGUAGE_SYNTAX_ERROR',
28+
];
29+
2230
public $message = 'This value should have correct expression language syntax.';
2331
public $service;
2432
public $validateNames = true;
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\ExpressionLanguage\Validator\Constraints;
12+
namespace Symfony\Component\Validator\Constraints;
1313

1414
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1515
use Symfony\Component\ExpressionLanguage\SyntaxError;
1616
use Symfony\Component\Validator\Constraint;
1717
use Symfony\Component\Validator\ConstraintValidator;
1818
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1919

20+
/**
21+
* @author Andrey Sevastianov <mrpkmail@gmail.com>
22+
*/
2023
class ExpressionLanguageSyntaxValidator extends ConstraintValidator
2124
{
2225
private $expressionLanguage;
@@ -45,6 +48,7 @@ public function validate($expression, Constraint $constraint): void
4548
$this->context->buildViolation($constraint->message)
4649
->setParameter('{{ syntax_error }}', $this->formatValue($exception->getMessage()))
4750
->setInvalidValue((string) $expression)
51+
->setCode(ExpressionLanguageSyntax::EXPRESSION_LANGUAGE_SYNTAX_ERROR)
4852
->addViolation();
4953
}
5054
}
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\ExpressionLanguage\Tests\Validator\Constraints;
12+
namespace Symfony\Component\Validator\Tests\Constraints;
1313

1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1616
use Symfony\Component\ExpressionLanguage\SyntaxError;
17-
use Symfony\Component\ExpressionLanguage\Validator\Constraints\ExpressionLanguageSyntax;
18-
use Symfony\Component\ExpressionLanguage\Validator\Constraints\ExpressionLanguageSyntaxValidator;
17+
use Symfony\Component\Validator\Constraints\ExpressionLanguageSyntax;
18+
use Symfony\Component\Validator\Constraints\ExpressionLanguageSyntaxValidator;
1919
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
2020

2121
class ExpressionLanguageSyntaxTest extends ConstraintValidatorTestCase
@@ -77,6 +77,7 @@ public function testExpressionIsNotValid(): void
7777

7878
$this->buildViolation('myMessage')
7979
->setParameter('{{ syntax_error }}', '"Test exception around position 42."')
80+
->setCode(ExpressionLanguageSyntax::EXPRESSION_LANGUAGE_SYNTAX_ERROR)
8081
->assertRaised();
8182
}
8283

‎src/Symfony/Component/Validator/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"egulias/email-validator": "Strict (RFC compliant) email validation",
6161
"symfony/property-access": "For accessing properties within comparison constraints",
6262
"symfony/property-info": "To automatically add NotNull and Type constraints",
63-
"symfony/expression-language": "For using the Expression validator"
63+
"symfony/expression-language": "For using the Expression validator and ExpressionLanguageSyntax constraints"
6464
},
6565
"autoload": {
6666
"psr-4": { "Symfony\\Component\\Validator\\": "" },

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.