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 93248c9

Browse filesBrowse files
committed
Make ExpressionLanguageSyntax validator usable with annotation
1 parent a73523b commit 93248c9
Copy full SHA for 93248c9

File tree

2 files changed

+11
-11
lines changed
Filter options

2 files changed

+11
-11
lines changed

‎src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntax.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntax.php
-9Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ class ExpressionLanguageSyntax extends Constraint
2828
];
2929

3030
public $message = 'This value should be a valid expression.';
31-
public $service;
3231
public $validateNames = true;
3332
public $names = [];
34-
35-
/**
36-
* {@inheritdoc}
37-
*/
38-
public function validatedBy()
39-
{
40-
return $this->service;
41-
}
4233
}

‎src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/ExpressionLanguageSyntaxValidator.php
+11-2Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ExpressionLanguageSyntaxValidator extends ConstraintValidator
2424
{
2525
private $expressionLanguage;
2626

27-
public function __construct(ExpressionLanguage $expressionLanguage)
27+
public function __construct(ExpressionLanguage $expressionLanguage = null)
2828
{
2929
$this->expressionLanguage = $expressionLanguage;
3030
}
@@ -43,7 +43,7 @@ public function validate($expression, Constraint $constraint): void
4343
}
4444

4545
try {
46-
$this->expressionLanguage->lint($expression, ($constraint->validateNames ? ($constraint->names ?? []) : null));
46+
$this->getExpressionLanguage()->lint($expression, ($constraint->validateNames ? ($constraint->names ?? []) : null));
4747
} catch (SyntaxError $exception) {
4848
$this->context->buildViolation($constraint->message)
4949
->setParameter('{{ syntax_error }}', $this->formatValue($exception->getMessage()))
@@ -52,4 +52,13 @@ public function validate($expression, Constraint $constraint): void
5252
->addViolation();
5353
}
5454
}
55+
56+
private function getExpressionLanguage(): ExpressionLanguage
57+
{
58+
if (null === $this->expressionLanguage) {
59+
$this->expressionLanguage = new ExpressionLanguage();
60+
}
61+
62+
return $this->expressionLanguage;
63+
}
5564
}

0 commit comments

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