Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created November 4, 2012 14:07
Show Gist options
  • Save eminetto/4012065 to your computer and use it in GitHub Desktop.
Save eminetto/4012065 to your computer and use it in GitHub Desktop.
/**
* Verifica se precisa fazer a autorização do acesso
* @param MvcEvent $event Evento
* @return boolean
*/
public function mvcPreDispatch($event)
{
$di = $event->getTarget()->getServiceLocator();
$routeMatch = $event->getRouteMatch();
$moduleName = $routeMatch->getParam('module');
$controllerName = $routeMatch->getParam('controller');
$actionName = $routeMatch->getParam('action');
$authService = $di->get('Admin\Service\Auth');
if (! $authService->authorize($moduleName, $controllerName, $actionName)) {
throw new \Exception('Você não tem permissão para acessar este recurso');
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment