Example #1
0
 /**
  * @param RoleInterface|null $role
  * @return $this
  */
 public function setRoleId(RoleInterface $role = null)
 {
     if ($role) {
         $this->roleId = $role->getRoleId();
     }
     return $this;
 }
 /**
  * Returns true if and only if the Role exists in the registry
  *
  * The $role parameter can either be a Role or a Role identifier.
  *
  * @param  RoleInterface|string $role
  * @return bool
  */
 public function has($role)
 {
     if ($role instanceof RoleInterface) {
         $roleId = $role->getRoleId();
     } else {
         $roleId = (string) $role;
     }
     return isset($this->roles[$roleId]);
 }
Example #3
0
 /**
  * Returns true if and only if the assertion conditions are met
  *
  * This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the
  * $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or
  * privileges, respectively.
  *
  * @param  Acl $acl
  * @param  RoleInterface $role
  * @param  ResourceInterface $resource
  * @param  string $privilege
  * @return bool
  */
 public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     if ($this->inWhitelist($role->getRoleId(), $resource->getResourceId(), $privilege)) {
         return false;
     }
     $rows = $this->getRolesAndResources($role->getRoleId(), $resource->getResourceId());
     foreach ($rows as $row) {
         $methods = explode(',', $row['methods']);
         if (!in_array($privilege, $methods)) {
             return false;
         }
     }
     return true;
 }
Example #4
0
 public function getPermissions(RoleInterface $role)
 {
     $final = array();
     foreach ($this->permissions as $perm) {
         if ($perm['role'] instanceof RoleInterface && $role->getRoleId() != $perm['role']->getRoleId()) {
             continue;
         } elseif (is_string($perm['role']) && $role->getRoleId() != $perm['role']) {
             continue;
         }
         array_push($final, $perm);
     }
     return $final;
 }