I have this listener:
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Request;
class ControllerListener
{
public function onKernelController( FilterControllerEvent $event, Request $request )
{
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
$controllers = $event->getController();
if (is_array( $controllers )) {
$controller = $controllers[0];
if (is_object( $controller )) {
if (method_exists( $controller, 'parControl' )) {
$controller->parControl(
$controller->getRequest(),
$controller->getRequest()->get( 'action' ),
$controller->getRequest()->get( 'context' ),
$controller->getRequest()->get( 'page' ),
$controller->getRequest()->get( 'case' ),
$controller->getRequest()->get( 'subset' )
);
}
if (method_exists( $controller, 'adminProjectControl' )) {
// to this method I need to pass Request $request
$controller->adminProjectControl($request);
}
if (method_exists( $controller, 'accessControl' )) {
$controller->accessControl();
}
}
}
}
}
public function onKernelResponse( FilterResponseEvent $event )
{
Utilities::flashDebugLoginMessage();
}
}
And it's defined as a service at services.yml
:
pdone.listener.preexecute:
class: GroupDCA\PDOneBundle\Listener\ControllerListener
arguments: [@request]
public: true
scope: request
tags:
- { name: kernel.event_listener, event: kernel.controller, method: onKernelController }
- { name: kernel.event_listener, event: kernel.response, method: onKernelResponse }
But I should doing something wrong since I got this three errors:
ContextErrorException in ControllerListener.php line 12: Catchable Fatal Error: Argument 2 passed to GroupDCA\PDOneBundle\Listener\ControllerListener::onKernelController() must be an instance of Symfony\Component\HttpFoundation\Request, string given
ContextErrorException in ControllerListener.php line 12: Catchable Fatal Error: Argument 2 passed to GroupDCA\PDOneBundle\Listener\ControllerListener::onKernelController() must be an instance of Symfony\Component\HttpFoundation\Request, string given
LogicException in bootstrap.php.cache line 3118: No listeners of the "kernel.exception" event set a Response
So, how do I inject the Request to the listener? Can I do that? I have read also this post here but not get how to do this.