hasRole() public method

Returns TRUE if the Role exists in the list.
public hasRole ( $role ) : boolean
return boolean
Example #1
0
 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);
 }
Example #2
0
 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);
     }
 }
Example #3
0
 /**
  * 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;
 }