Created
June 26, 2012 00:51
-
-
Save MDrollette/2992394 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 SOTB\CoreBundle\EventListener; | |
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; | |
use Symfony\Component\Security\Core\SecurityContextInterface; | |
use SOTB\CoreBundle\Model\InitializableControllerInterface; | |
/** | |
* @author Matt Drollette <[email protected]> | |
*/ | |
class BeforeControllerListener | |
{ | |
private $security_context; | |
public function __construct(SecurityContextInterface $security_context) | |
{ | |
$this->security_context = $security_context; | |
} | |
public function onKernelController(FilterControllerEvent $event) | |
{ | |
$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 InitializableControllerInterface) { | |
// this method is the one that is part of the interface. | |
$controllerObject->initialize($event->getRequest(), $this->security_context); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment