Skip to content

Instantly share code, notes, and snippets.

@MDrollette
Created June 26, 2012 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MDrollette/2992394 to your computer and use it in GitHub Desktop.
Save MDrollette/2992394 to your computer and use it in GitHub Desktop.
<?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 <matt@drollette.com>
*/
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