I\'m quite new to Symfony so forgive me if it seems obvious for you :)
For my project, i need to perform some actions depending on the url. I use kernel events, more
So I did a bit more research. It's not that the kernel event is being fired twice but rather that once your original page is sent to the browser a bit of javascript initiates a second _wdt request for additional information. So you actually have two independent requests. You can see this by pressing F12 in your browser and then selecting the network tab and refreshing.
It is easy enough to filter the debug request since the name of the route will always be _wdt. And you can also get the host directly from the request. Still want to check for the master request because eventually your code might trigger sub requests.
public function onRequest(GetResponseEvent $event)
{
// Only master
if (!$event->isMasterRequest()) {
return;
}
$request = $event->getRequest();
// Ignore toolbar
if ($request->attributes->get('_route') === '_wdt') {
return;
}
// Avoid parsing urls and other stuff, the request object should have
// all the info you need
$host = $request->getHost();
}