Skip to content

Commit d8079d9

Browse files
committed
also provide request itself in expressions
1 parent 95d6a2b commit d8079d9

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

EventListener/InvalidationSubscriber.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,19 @@ private function invalidatePaths(array $pathConfigurations)
202202
*/
203203
private function invalidateRoutes(array $routes, Request $request)
204204
{
205+
$values = $request->attributes->all();
206+
// if there is an attribute called "request", it needs to be accessed through the request.
207+
$values['request'] = $request;
208+
$expressionLanguage = $this->getExpressionLanguage();
209+
205210
foreach ($routes as $route) {
206211
$params = array();
207212

208213
if (null !== $route->getParams()) {
209214
// Iterate over route params and try to evaluate their values
210215
foreach ($route->getParams() as $key => $value) {
211216
if (is_array($value)) {
212-
$value = $this->getExpressionLanguage()->evaluate($value['expression'], $request->attributes->all());
217+
$value = $expressionLanguage->evaluate($value['expression'], $values);
213218
}
214219

215220
$params[$key] = $value;

EventListener/TagSubscriber.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,11 @@ private function getAnnotationTags(Request $request)
146146
*/
147147
private function evaluateTag($expression, Request $request)
148148
{
149-
return $this->getExpressionLanguage()->evaluate(
150-
$expression,
151-
$request->attributes->all()
152-
);
149+
$values = $request->attributes->all();
150+
// if there is an attribute called "request", it needs to be accessed through the request.
151+
$values['request'] = $request;
152+
153+
return $this->getExpressionLanguage()->evaluate($expression, $values);
153154
}
154155

155156
/**

Resources/doc/reference/annotations.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ route ``articles`` with the ``number`` parameter set to ``123``, do::
5959
// Assume $request->attributes->get('id') returns 123
6060
}
6161

62+
The expression has access to all request attributes and the request itself
63+
under the name ``request``.
64+
6265
See :doc:`/features/invalidation` for more information.
6366

6467
.. _tag:

Resources/doc/reference/configuration/tags.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,7 @@ tag ``articles-123`` with the following configuration:
8383
tags: [articles]
8484
tag_expressions: ["'article-'~id"]
8585
86+
The expression has access to all request attributes and the request itself
87+
under the name ``request``.
88+
8689
You can combine ``tags`` and ``tag_expression`` in one rule.

0 commit comments

Comments
 (0)