/** @return \Generator<int, RoleResource, mixed, void> */
public function iterate(
?int $limit = null,
?int $offset = null,
?string $search = null,
?string $sortBy = null,
int|float|null $timeout = null,
): \GeneratorYields roles individually, fetching the next page only once the current one is drained. Role sets are small, so this exists mainly for symmetry with the other collections and for the ability to stop as soon as you find the row you wanted.
It returns a Generator, so put the call straight into a foreach loop. No request is issued until the first iteration, and breaking out of the loop leaves any remaining pages unfetched.
Example
use Envless\Envless;
$envless = new Envless();
foreach ($envless->roles->iterate() as $role) {
if (!$role['isSystem']) {
echo $role['name'], ' ', count($role['permissions']), PHP_EOL;
}
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$limit | int | No | Page size fetched behind the scenes, clamped to 100. |
$offset | int | No | Row to start streaming from. |
$search | string | No | Case insensitive substring match against role name and description. |
$sortBy | string | No | Order within each group: name (the default) is A to Z, updated and created are newest first. System roles always come first. |
$timeout | int|float | No | Seconds each attempt of this call may take, the response body included, before it throws Envless\Exception\NetworkException with isTimeout() true. Overrides the client's timeout for this call, and 0 turns the limit off. |
Returns
A Generator that yields RoleResource values until the pages run out.
Reads the roles collection. list returns one page as an Envless\Result\Page with items and pagination, listAll collects every page into an array, and iterate returns a Generator that yields one item at a time, fetching the next page only when the loop gets there.
Worth knowing
- The offset advances by the number of rows actually received, so a role created mid walk can shift the window.
- System roles are yielded before custom roles, so a loop that breaks on the first row always sees a system role.
Required scopes
roles:read
Underlying endpoint
GET /roles
Request and response schema, every error code, and a live playground.
In TypeScript
envless.roles.iterate()
The same method in @goenvless/sdk, with the same request, retries and errors.