Last active
December 28, 2015 08:48
-
-
Save metalvarez/7473735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\CommonsBundle\Kernel\EventListener; | |
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; | |
use Symfony\Component\Security\Core\SecurityContextInterface; | |
use Acme\CommonsBundle\Model\Controller\InitializableControllerInterface; | |
/** | |
* @author Víctor Hugo Álvarez <metalvarez@gmail.com> | |
*/ | |
class BeforeControllerActionListener | |
{ | |
public function onKernelController(FilterControllerEvent $event) | |
{ | |
$controller = $event->getController(); | |
if (!is_array($controller)) { | |
// prevenimos ejecutar algo que no sea un controlador | |
return; | |
} | |
$controllerObject = $controller[0]; | |
// saltamos la inicialización de excepciones | |
if ($controllerObject instanceof ExceptionController) { | |
return; | |
} | |
if ($controllerObject instanceof InitializableControllerInterface) { | |
// este es el método de la interface | |
$controllerObject->initialize(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment