Skip to content

Commit 4e72ef3

Browse files
ThomasLandauerjaviereguiluz
authored andcommitted
[Routing] Adding full example for a Service in Route Condition
1 parent 1a7913d commit 4e72ef3

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

routing.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,27 @@ You can also use these functions:
379379
``service(string $alias)``
380380
Returns a routing condition service.
381381
You'll have to add the ``#[AsRoutingConditionService]`` attribute or ``routing.condition_service``
382-
tag to your service if you want to use it in the condition.
382+
tag to your service if you want to use it in the condition::
383+
384+
385+
// Controller (using an alias):
386+
#[Route(condition: "service('route_checker').check(request)")]
387+
// Or without alias:
388+
#[Route(condition: "service('Ap\\\Service\\\RouteChecker').check(request)")]
389+
390+
.. code-block:: php
391+
392+
use Symfony\Bundle\FrameworkBundle\Routing\Attribute\AsRoutingConditionService;
393+
use Symfony\Component\HttpFoundation\Request;
394+
395+
#[AsRoutingConditionService(alias: 'route_checker')]
396+
class RouteChecker
397+
{
398+
public function check(Request $request): bool
399+
{
400+
// ...
401+
}
402+
}
383403
384404
.. versionadded:: 6.1
385405

0 commit comments

Comments
 (0)