Skip to content

Instantly share code, notes, and snippets.

@eminetto
Created November 4, 2012 14:08
Show Gist options
  • Save eminetto/4012068 to your computer and use it in GitHub Desktop.
Save eminetto/4012068 to your computer and use it in GitHub Desktop.
/**
* Faz a autorização do usuário para acessar o recurso
* @param string $moduleName Nome do módulo sendo acessado
* @param string $controllerName Nome do controller
* @param string $actionName Nome da ação
* @return boolean
*/
public function authorize($moduleName, $controllerName, $actionName)
{
$auth = new AuthenticationService();
$role = 'visitante';
if ($auth->hasIdentity()) {
$session = $this->getServiceManager()->get('Session');
$user = $session->offsetGet('user');
$role = $user->role;
}
$resource = $controllerName . '.' . $actionName;
$acl = $this->getServiceManager()->get('Core\Acl\Builder')->build();
if ($acl->isAllowed($role, $resource)) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment