Example #1
0
 /**
  * Set a role by array
  * @param array $array The role's info
  * @param string|null $name The role name (for overwrite the array info)
  * @throws Exception Name must exist
  * @return Role The role
  */
 public static function fromArray(array $array, $name = null)
 {
     if ($name === null && !array_key_exists('name', $array)) {
         throw new \Exception("You must give a name for the role", E_USER_ERROR);
     }
     // Get info
     $name = $name !== null ? $name : $array['name'];
     $access = array_key_exists('access', $array) ? $array['access'] : array();
     $parents = array_key_exists('parents', $array) ? $array['parents'] : array();
     // Create role
     $role = new Role($name, $parents);
     $role->setAccess($access);
     return $role;
 }
Example #2
0
 /**
  * Deny a role to this resource
  * @param Role $role The role
  * @return Acl\Resource resource
  */
 public function deny(Role $role)
 {
     $role->deny($this);
     return $this;
 }
Example #3
0
 /**
  * Deny a role to resource
  * @param Acl\Role $role The role
  * @param Acl\Resource $resource The resource
  * @throws Exception The role don't exist
  * @return \Acl\Acl ACL
  */
 public function deny(Role $role, Resource $resource)
 {
     $role->deny($resource);
     return $this;
 }