Esempio n. 1
0
 /**
  * @param $name
  * @param $description
  * @param bool $isRemovable
  * @throws Exception\InvalidRoleNameException
  * @return bool
  */
 public function add($name, $description, $isRemovable = true)
 {
     if (!$name) {
         throw new InvalidRoleNameException();
     }
     $role = new Role($name, $description);
     $role->setRemovable($isRemovable);
     $result = $this->adapter->addRole($role);
     return $result;
 }
Esempio n. 2
0
 /**
  * @param string|array $role
  * @return \Vegas\Security\Acl\Role
  * @throws Exception\RoleDoesNotExistException
  */
 public function getRole($role)
 {
     if ($role instanceof Role) {
         return $role;
     }
     $roleName = gettype($role) === 'array' ? $role['name'] : $role;
     $role = $this->getCollection('roles')->findOne(array('name' => $roleName));
     if (!$role) {
         throw new RoleDoesNotExistException($roleName);
     }
     $accessListArray = [];
     $accessList = $this->getRoleAccesses($role['name']);
     foreach ($accessList as $accessDocument) {
         $accessListArray[] = $accessDocument;
     }
     $roleObject = new Role($role['name'], $role['description']);
     $roleObject->setRemovable($role['removable']);
     $roleObject->setId($role['_id']);
     $roleObject->setAccessList((array) $accessList);
     $role = $roleObject;
     return $role;
 }
Esempio n. 3
0
 /**
  * Gets role with all its accesses
  * 
  * @param string $role
  * @return \Vegas\Security\Acl\Role
  */
 public function getRole($role)
 {
     if (!$role instanceof AclRole) {
         $role = $this->getRoleModel($role);
     }
     $roleObject = new Role($role->name, $role->description);
     $roleObject->setRemovable($role->removable);
     $roleObject->setId($role->id);
     foreach ($role->getAccessLists() as $access) {
         $roleObject->addAccess($access->toAccessArray());
     }
     return $roleObject;
 }
Esempio n. 4
0
 public function testGetId()
 {
     $id = 'foo';
     $this->obj->setId($id);
     $this->assertSame($id, $this->obj->getId());
 }