I have functionm onKernelRequest when i want to add some custom header(in my case api=true
||$request->headers->set('api', "true")
) and in all Request $request
i can get that header but when i try it on annotation its fail:
public function onKernelRequest(RequestEvent $event)
{
if (!$event->isMasterRequest()) { return; }
$request = $event->getRequest();
$request->headers->set('api', "true");
return;
}
/* @Route(
* "/user/info/",
* name="get_user_info",
* methods={"GET"},
* condition="request.headers.get('api')"
* )
Path almost matches, but Condition "request.headers.get('api')" does not evaluate to "true"
The router listener is being called before your listener.
The router [https://github.com/symfony/http-kernel/blob/master/EventListener/RouterListener.php#L158](listener listen has a priority of 32) where as your listener has a priority of 0 (the default).
If you set your listener to have a higher priority than the router listener it should work.
An example using YAML
services:
App\EventListener\YourListener:
tags:
-
name: kernel.event_listener
event: kernel.request
priority: 40