Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion EventListener/InvalidationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,19 @@ private function invalidatePaths(array $pathConfigurations)
*/
private function invalidateRoutes(array $routes, Request $request)
{
$values = $request->attributes->all();
// if there is an attribute called "request", it needs to be accessed through the request.
$values['request'] = $request;
$expressionLanguage = $this->getExpressionLanguage();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means that you now require the ExpressionLanguage to be available even when no route is using it.

given the private getter caches it anyway, it does not have much value to use a local variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ouch, that was not intended!

will fix that after lunch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omg @stof, you’re everywhere, thanks for the catch! 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #145


foreach ($routes as $route) {
$params = array();

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

$params[$key] = $value;
Expand Down
9 changes: 5 additions & 4 deletions EventListener/TagSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ private function getAnnotationTags(Request $request)
*/
private function evaluateTag($expression, Request $request)
{
return $this->getExpressionLanguage()->evaluate(
$expression,
$request->attributes->all()
);
$values = $request->attributes->all();
// if there is an attribute called "request", it needs to be accessed through the request.
$values['request'] = $request;

return $this->getExpressionLanguage()->evaluate($expression, $values);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions Resources/doc/reference/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ route ``articles`` with the ``number`` parameter set to ``123``, do::
// Assume $request->attributes->get('id') returns 123
}

The expression has access to all request attributes and the request itself
under the name ``request``.

See :doc:`/features/invalidation` for more information.

.. _tag:
Expand Down
3 changes: 3 additions & 0 deletions Resources/doc/reference/configuration/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,7 @@ tag ``articles-123`` with the following configuration:
tags: [articles]
tag_expressions: ["'article-'~id"]

The expression has access to all request attributes and the request itself
under the name ``request``.

You can combine ``tags`` and ``tag_expression`` in one rule.