/** * 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; }
/** * @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; }
public function testGetId() { $id = 'foo'; $this->obj->setId($id); $this->assertSame($id, $this->obj->getId()); }