I have written my own ExceptionController and want to inject the debug token as part of the output.
I had a look on the WebProfilerToolbarListener, which is similar to my case but it seems that the exception/error response has another lifecycle.
The ProfilerCollector is always called after my listener, which is on the response event.
My Listener needs to be called after the ProfilerCollector.
How can I achieve it?

I have tried to use different priorities, but it seems that you need to clear the cache completly. It isn't sufficient to reload the page in development mode.
After changing the priority to -150 like below it works.
profiler_link_listener:
class:Nerdhive\TheNetwork\TwigBundle\EventListener\ProfilerLinkListener
priority: -150
tags:
- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }

You can retrieve the debug token like below:
public function onKernelResponse(FilterResponseEvent $event)
{
$response = $event->getResponse();
$token = $response->headers->get('X-Debug-Token');
// Do here your stuff
}
In general -129 should also work regarding the WebDebugToolbarListener or documentation:
public static function getSubscribedEvents()
{
return array(
KernelEvents::RESPONSE => array('onKernelResponse', -128),
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With