@@ -48,7 +48,7 @@ class TagListener extends AbstractRuleListener implements EventSubscriberInterfa
4848 private $ symfonyResponseTagger ;
4949
5050 /**
51- * @var ExpressionLanguage
51+ * @var ExpressionLanguage|null
5252 */
5353 private $ expressionLanguage ;
5454
@@ -76,7 +76,7 @@ public function __construct(
7676 $ this ->symfonyResponseTagger = $ tagHandler ;
7777 $ this ->cacheableRule = $ cacheableRule ;
7878 $ this ->mustInvalidateRule = $ mustInvalidateRule ;
79- $ this ->expressionLanguage = $ expressionLanguage ?: new ExpressionLanguage () ;
79+ $ this ->expressionLanguage = $ expressionLanguage ;
8080 }
8181
8282 /**
@@ -173,6 +173,19 @@ private function evaluateTag($expression, Request $request)
173173 // if there is an attribute called "request", it needs to be accessed through the request.
174174 $ values ['request ' ] = $ request ;
175175
176- return $ this ->expressionLanguage ->evaluate ($ expression , $ values );
176+ return $ this ->getExpressionLanguage ()->evaluate ($ expression , $ values );
177+ }
178+
179+ private function getExpressionLanguage (): ExpressionLanguage
180+ {
181+ if (!$ this ->expressionLanguage ) {
182+ // the expression comes from controller annotations, we can't detect whether they use expressions while building the configuration
183+ if (!class_exists (ExpressionLanguage::class)) {
184+ throw new \RuntimeException ('Using the tag annotation requires the ' .ExpressionLanguage::class.' to be available. ' );
185+ }
186+ $ this ->expressionLanguage = new ExpressionLanguage ();
187+ }
188+
189+ return $ this ->expressionLanguage ;
177190 }
178191}
0 commit comments