Created
October 12, 2012 19:25
-
-
Save sergeylunev/3880989 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 App\DefaultBundle\Listener; | |
use Doctrine\Common\Annotations\Reader; | |
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\RedirectResponse; | |
use App\DefaultBundle\Annotation\MinAccess; | |
class MinAccessListener | |
{ | |
private $reader; | |
private $security; | |
private $routing; | |
private $session; | |
public function __construct(Reader $reader, $security, $routing, $session) | |
{ | |
$this->reader = $reader; | |
$this->security = $security; | |
$this->routing = $routing; | |
$this->session = $session; | |
} | |
public function onKernelController(FilterControllerEvent $event) | |
{ | |
if (!is_array($controller = $event->getController())) { | |
return; | |
} | |
$method = new \ReflectionMethod($controller[0], $controller[1]); | |
foreach ($this->reader->getMethodAnnotations($method) as $annotation) { | |
if ($annotation instanceof MinAccess) { | |
if (!$annotation->execute($this->security, $this->session, $this->routing)) { | |
$this->session->setFlash('pre_organisation', 'common.message.pre_organisation'); | |
return new RedirectResponse($this->routing->generate('address_edit')); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment