In Symfony 5.3, I have an EventSubscriber to the KernelEvents::CONTROLLER event.
class PrivateAPIEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
KernelEvents::CONTROLLER => ['onKernelController', 2],
];
}
public function onKernelController(ControllerEvent $event): void
{
$controller = $event->getController();
dd($controller);
The issue I have is that for most of my requests, the getController() method returns array like this:
PrivateAPIEventSubscriber.php on line 42:
array:2 [▼
0 => App\Controller\CP\SecurityController {#241 ▶}
1 => "login"
]
the 0th element is the $controller object and the 1st element is the function.
But for an error page (e.g. no route)
PrivateAPIEventSubscriber.php on line 42:
Symfony\Component\HttpKernel\Controller\ErrorController {#468 ▼
-kernel: Symfony\Component\HttpKernel\HttpKernel {#141 ▶}
-controller: "error_controller"
-errorRenderer: Symfony\Component\ErrorHandler\ErrorRenderer\SerializerErrorRenderer {#469 ▶}
}
I cannot find documentation for this method, the source code is not helpful (the $controller variable inside ConrtrollerEvent is not typed) and I am worried that there might be some more cases which I am not handling (like return of larger arrays or multi-dimensional arrays)
So what are all the expected return types?