11
11
12
12
namespace Symfony \Component \Validator \Constraints ;
13
13
14
- use Symfony \Component \ExpressionLanguage \ExpressionFunction ;
15
- use Symfony \Component \ExpressionLanguage \ExpressionFunctionProviderInterface ;
16
14
use Symfony \Component \ExpressionLanguage \ExpressionLanguage ;
17
15
use Symfony \Component \Validator \Constraint ;
18
16
use Symfony \Component \Validator \ConstraintValidator ;
22
20
* @author Fabien Potencier <[email protected] >
23
21
* @author Bernhard Schussek <[email protected] >
24
22
*/
25
- class ExpressionValidator extends ConstraintValidator implements ExpressionFunctionProviderInterface
23
+ class ExpressionValidator extends ConstraintValidator
26
24
{
27
25
private ExpressionLanguage $ expressionLanguage ;
28
26
29
27
public function __construct (ExpressionLanguage $ expressionLanguage = null )
30
28
{
31
29
if ($ expressionLanguage ) {
32
- $ this ->expressionLanguage = clone $ expressionLanguage ;
33
- $ this ->expressionLanguage ->registerProvider ($ this );
30
+ $ this ->expressionLanguage = $ expressionLanguage ;
34
31
}
35
32
}
36
33
@@ -56,25 +53,11 @@ public function validate(mixed $value, Constraint $constraint)
56
53
}
57
54
}
58
55
59
- public function getFunctions (): array
60
- {
61
- return [
62
- new ExpressionFunction ('is_valid ' , function (...$ arguments ) {
63
- return sprintf (
64
- '0 === $context->getValidator()->inContext($context)->validate(%s)->getViolations()->count() ' ,
65
- implode (', ' , $ arguments )
66
- );
67
- }, function (array $ variables , ...$ arguments ): bool {
68
- return 0 === $ variables ['context ' ]->getValidator ()->inContext ($ variables ['context ' ])->validate (...$ arguments )->getViolations ()->count ();
69
- }),
70
- ];
71
- }
72
-
73
56
private function getExpressionLanguage (): ExpressionLanguage
74
57
{
75
58
if (!isset ($ this ->expressionLanguage )) {
76
59
$ this ->expressionLanguage = new ExpressionLanguage ();
77
- $ this ->expressionLanguage ->registerProvider ($ this );
60
+ $ this ->expressionLanguage ->registerProvider (new ExpressionLanguageProvider () );
78
61
}
79
62
80
63
return $ this ->expressionLanguage ;
0 commit comments