hasRole() public method

Returns TRUE if the Role exists in the list.
public hasRole ( $role ) : boolean
return boolean
コード例 #1
0
ファイル: Acl.php プロジェクト: zaxcms/framework
 public function isAllowed($role = IAuthorizator::ALL, $resource = IAuthorizator::ALL, $privilege = IAuthorizator::ALL)
 {
     if (!$this->acl->hasRole($role)) {
         $this->onUndefinedRole($role);
     }
     if (!$this->acl->hasResource($resource)) {
         $this->onUndefinedResource($resource);
     }
     return $this->acl->isAllowed($role, $resource, $privilege);
 }
コード例 #2
0
ファイル: AclHelper.php プロジェクト: v108b/nette-acl
 public function check($resource, $privilege)
 {
     if ($this->user->isInRole(static::ROOT_ROLE)) {
         return true;
     }
     if (!array_reduce($this->user->getRoles(), function ($prev, $role) use($resource, $privilege) {
         return $this->acl->hasRole($role) && $this->acl->hasResource($resource) && $this->acl->isAllowed($role, $resource, $privilege) || $prev;
     }, false)) {
         throw new \AclException("Unauthorized access to resource '{$resource}' privilege '{$privilege}' :(", 403);
     }
 }
コード例 #3
0
ファイル: AuthorizatorFactory.php プロジェクト: svobodni/web
 /**
  * Get raw permissions without privileges.
  *
  * @return Permission
  */
 public function getRawPermissions()
 {
     $permission = new Permission();
     foreach ($this->scanResources() as $resource => $privileges) {
         $permission->addResource($resource);
     }
     foreach ($this->defaultRoles as $role) {
         if (!$permission->hasRole($role)) {
             $permission->addRole($role);
         }
     }
     return $permission;
 }