Skip to content

[Routing] Allow using services in the route condition #16775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2022
Merged
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
[Routing] Allow using services in the route condition
Update routing.rst

Co-authored-by: Wouter de Jong <wouterj@users.noreply.github.com>

Update routing.rst

Co-authored-by: Wouter de Jong <wouterj@users.noreply.github.com>
  • Loading branch information
renanbr and wouterj committed May 4, 2022
commit c2478da3d6e2ed8364bba1a01a9bc05c9d0bba4f
12 changes: 11 additions & 1 deletion routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,21 @@ and can use any of these variables created by Symfony:

The ``params`` variable was introduced in Symfony 6.1.

You can also use this function:
You can also use these functions:

``env(string $name)``
Returns the value of a variable using :doc:`Environment Variable Processors <configuration/env_var_processors>`

``service(string $alias)``
Returns a routing condition service.
You'll have to add the ``#[AsRoutingConditionService]`` attribute or ``routing.condition_service``
tag to your service if you want to use it in the condition.

.. versionadded:: 6.1

The ``service(string $alias)`` function and ``#[AsRoutingConditionService]`` attribute
was introduced in Symfony 6.1.

Behind the scenes, expressions are compiled down to raw PHP. Because of this,
using the ``condition`` key causes no extra overhead beyond the time it takes
for the underlying PHP to execute.
Expand Down