/** * Checks if the passed value is valid. * * @param mixed $value The value that should be validated * @param Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { if (!$value instanceof RoleData) { return; } try { $role = $this->roleService->loadRoleByIdentifier($value->identifier); // It is of course OK to edit a draft of an existing Role :-) if ($role->id === $value->roleDraft->id) { return; } $this->context->buildViolation($constraint->message)->atPath('identifier')->setParameter('%identifier%', $value->identifier)->addViolation(); } catch (NotFoundException $e) { // Do nothing } }
/** * Loads list of roles * * @return \eZ\Publish\Core\REST\Server\Values\RoleList */ public function listRoles() { $roles = array(); if ($this->request->query->has('identifier')) { try { $role = $this->roleService->loadRoleByIdentifier($this->request->query->get('identifier')); $roles[] = $role; } catch (APINotFoundException $e) { // Do nothing } } else { $offset = $this->request->query->has('offset') ? (int) $this->request->query->get('offset') : 0; $limit = $this->request->query->has('limit') ? (int) $this->request->query->get('limit') : -1; $roles = array_slice($this->roleService->loadRoles(), $offset >= 0 ? $offset : 0, $limit >= 0 ? $limit : null); } return new Values\RoleList($roles, $this->request->getPathInfo()); }
/** * Loads a role for the given identifier. * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found * * @param string $identifier * * @return \eZ\Publish\API\Repository\Values\User\Role */ public function loadRoleByIdentifier($identifier) { return $this->service->loadRoleByIdentifier($identifier); }