File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -378,8 +378,28 @@ You can also use these functions:
378378
379379``service(string $alias) ``
380380 Returns a routing condition service.
381- 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.
381+
382+ First, add the ``#[AsRoutingConditionService] `` attribute or ``routing.condition_service ``
383+ tag to the services that you want to use in route conditions::
384+
385+ use Symfony\Bundle\FrameworkBundle\Routing\Attribute\AsRoutingConditionService;
386+ use Symfony\Component\HttpFoundation\Request;
387+
388+ #[AsRoutingConditionService(alias: 'route_checker')]
389+ class RouteChecker
390+ {
391+ public function check(Request $request): bool
392+ {
393+ // ...
394+ }
395+ }
396+
397+ Then, use the ``service() `` function to refer to that service inside conditions::
398+
399+ // Controller (using an alias):
400+ #[Route(condition: "service('route_checker').check(request)")]
401+ // Or without alias:
402+ #[Route(condition: "service('Ap\\\Service\\\RouteChecker').check(request)")]
383403
384404.. versionadded :: 6.1
385405
You can’t perform that action at this time.
0 commit comments