sajad torkamani

When is it dispatched?

The kernel.response event is dispatched after the controller or a kernel.view listener returns a Response object.

Use cases

  • Modify or replace the response (e.g., add/modify HTTP headers or add cookies).

Event class

Listeners to kernel.response will receive a ResponseEvent object.


use Symfony\Component\HttpKernel\Event\ResponseEvent;

public function onKernelResponse(ResponseEvent $event)
    $response = $event->getResponse();

    // ... modify the response object

List event listeners

php bin/console debug:event-dispatcher kernel.response

Sources / related

Tagged: Symfony