/** @return \Generator<int, WorkspaceResource, mixed, void> */
public function iterate(
?int $limit = null,
?int $offset = null,
int|float|null $timeout = null,
): \GeneratorReturns a Generator that yields workspaces individually and fetches the next page only when the current one runs out. Breaking out of the loop stops the requests, which makes this the cheapest way to find one workspace by slug or plan.
The generator defaults to the maximum page size of 100 and caps anything larger, so limit only ever makes pages smaller. Each page is a separate request, so a membership added while you are mid walk may or may not appear.
Example
use Envless\Envless;
$envless = new Envless();
foreach ($envless->workspaces->iterate() as $workspace) {
if ($workspace['slug'] === 'billing') {
echo "{$workspace['id']} {$workspace['plan']}", PHP_EOL;
break;
}
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$limit | int | No | Page size per request, capped at 100 and defaulting to 100. |
$offset | int | No | Row the walk starts at, advancing by the number of items each page returns. |
$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
Generator<int, WorkspaceResource> yielding one workspace per step.
Reads the workspaces 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 generator is lazy, so no request is sent until you start consuming it.
Required scopes
workspace:read
Underlying endpoint
GET /workspaces
Request and response schema, every error code, and a live playground.
In TypeScript
envless.workspaces.iterate()
The same method in @goenvless/sdk, with the same request, retries and errors.