<?php
// para ver los listener afiliados a un evento por consola :
// $ php app/console debug:event-dispatcher kernel.exception
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\Response;
// el tipo de eventos que recibiremos:
//--------------------------------------------------------------
// > las excepciones
// > se reciben las respuestas al cliente
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
// > El controlador
use AppBundle\AppInterfaces\InitializerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class KernelSubscriber implements EventSubscriberInterface
{
/**
> El mapping de los eventos con sus métodos a llamar
*/
public static function getSubscribedEvents()
{
// return the subscribed events, their methods and priorities
return [ KernelEvents::CONTROLLER => 'onKernelController' ];
}
public function onKernelController(FilterControllerEvent $event)
{
// metodo por security context:
$controller = $event->getController();
if (!is_array($controller)) {
// not a object but a different kind of callable. Do nothing
return;
}
$controllerObject = $controller[0];
// skip initializing for exceptions
if ($controllerObject instanceof ExceptionController) {
return;
}
if ($controllerObject instanceof InitializerInterface) {
// this method is the one that is part of the interface.
$controllerObject->initialize(
$event->getRequest()
//,$this->security_context
);
}
}
}