From c2478da3d6e2ed8364bba1a01a9bc05c9d0bba4f Mon Sep 17 00:00:00 2001 From: Renan Date: Tue, 3 May 2022 23:14:26 +0200 Subject: [PATCH] [Routing] Allow using services in the route condition Update routing.rst Co-authored-by: Wouter de Jong Update routing.rst Co-authored-by: Wouter de Jong --- routing.rst | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/routing.rst b/routing.rst index 7aa8c3d30ce..379e5092020 100644 --- a/routing.rst +++ b/routing.rst @@ -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 ` +``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.