Created
April 8, 2015 19:01
-
-
Save ftdysa/0f7fc9ae49e5af95df46 to your computer and use it in GitHub Desktop.
response from controller event
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
class SudoListener { | |
public function onKernelController(FilterControllerEvent $event) { | |
$controller = $event->getController(); | |
$token = $this->tokenStorage->getToken(); | |
if ($token === null || ($user = $token->getUser()) === null) { | |
return; | |
} | |
if (!is_array($controller)) { | |
return; | |
} | |
if ($controller[0] instanceof SudoControllerInterface) { | |
$key = UserCacheHelper::getSudoKey($user); | |
$value = $this->client->get($key); | |
if (!$value || $value === null) { | |
$redirect = $this->router->generate('user_sudo'); | |
$event->setController(function() use ($redirect) { | |
return new RedirectResponse($redirect); | |
}); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment