sajad torkamani

When is it dispatched?

Dispatched just before a controller is called.

Use cases

  • Configure the arguments passed to the controller (e.g., map URL route params to the corresponding named arguments or pass the current request object when the Request type-hint is used).

Example

use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;

public function onKernelControllerArguments(ControllerArgumentsEvent $event)
{
    // ...

    // get controller and request arguments
    $namedArguments = $event->getRequest()->attributes->all();
    $controllerArguments = $event->getArguments();

    // set the controller arguments to modify the original arguments or add new ones
    $event->setArguments($newArguments);
}

List event listeners

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

Sources

Tagged: Symfony