@@ -45,26 +45,33 @@ public function validate(mixed $value, Constraint $constraint): void
45
45
46
46
$ value = (string ) $ value ;
47
47
48
- if (!$ constraint ->skipDeprecations ) {
49
- $ prevErrorHandler = set_error_handler (static function ($ level , $ message , $ file , $ line ) use (&$ prevErrorHandler ) {
50
- if (\E_USER_DEPRECATED !== $ level ) {
51
- return $ prevErrorHandler ? $ prevErrorHandler ($ level , $ message , $ file , $ line ) : false ;
52
- }
53
-
54
- $ templateLine = 0 ;
55
- if (preg_match ('/ at line (\d+)[ .]/ ' , $ message , $ matches )) {
56
- $ templateLine = $ matches [1 ];
57
- }
58
-
59
- throw new Error ($ message , $ templateLine );
60
- });
61
- }
62
-
63
48
$ realLoader = $ this ->twig ->getLoader ();
64
49
try {
65
50
$ temporaryLoader = new ArrayLoader ([$ value ]);
66
51
$ this ->twig ->setLoader ($ temporaryLoader );
67
- $ this ->twig ->parse ($ this ->twig ->tokenize (new Source ($ value , '' )));
52
+
53
+ if (!$ constraint ->skipDeprecations ) {
54
+ $ prevErrorHandler = set_error_handler (static function ($ level , $ message , $ file , $ line ) use (&$ prevErrorHandler ) {
55
+ if (\E_USER_DEPRECATED !== $ level ) {
56
+ return $ prevErrorHandler ? $ prevErrorHandler ($ level , $ message , $ file , $ line ) : false ;
57
+ }
58
+
59
+ $ templateLine = 0 ;
60
+ if (preg_match ('/ at line (\d+)[ .]/ ' , $ message , $ matches )) {
61
+ $ templateLine = $ matches [1 ];
62
+ }
63
+
64
+ throw new Error ($ message , $ templateLine );
65
+ });
66
+ }
67
+
68
+ try {
69
+ $ this ->twig ->parse ($ this ->twig ->tokenize (new Source ($ value , '' )));
70
+ } finally {
71
+ if (!$ constraint ->skipDeprecations ) {
72
+ restore_error_handler ();
73
+ }
74
+ }
68
75
} catch (Error $ e ) {
69
76
$ this ->context ->buildViolation ($ constraint ->message )
70
77
->setParameter ('{{ error }} ' , $ e ->getMessage ())
@@ -73,9 +80,6 @@ public function validate(mixed $value, Constraint $constraint): void
73
80
->addViolation ();
74
81
} finally {
75
82
$ this ->twig ->setLoader ($ realLoader );
76
- if (!$ constraint ->skipDeprecations ) {
77
- restore_error_handler ();
78
- }
79
83
}
80
84
}
81
85
}
0 commit comments