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.

Example

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

Leave a comment

Your email address will not be published. Required fields are marked *