sajad torkamani

When is it dispatched

Dispatched after the control has been resolved but before it’s executed.

Use cases

  • Initialize things later needed by the controller (e.g., param converters).
  • Change the controller entirely.

Example

use Symfony\Component\HttpKernel\Event\ControllerEvent;

public function onKernelController(ControllerEvent $event)
{
    // ...

    // the controller can be changed to any PHP callable
    $event->setController($myCustomController);
}

List event listeners

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

Sources / related

Tagged: Symfony

Leave a comment

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