/** @return \Generator<int, EnvironmentSummaryResource, mixed, void> */
public function iterate(
string $project,
?int $limit = null,
?int $offset = null,
?string $search = null,
?string $order = null,
?string $product = null,
int|float|null $timeout = null,
): \GeneratorYields environments one at a time and fetches the next page only when the current one is exhausted, so breaking out of the loop stops the remaining requests. Page size follows limit up to 100 and offset picks the starting row.
The walk advances its offset by the number of rows it just consumed, so creating or deleting environments in the same project mid-loop can skip a row or hand you one twice. Neither this nor listAll is a snapshot: both walk offsets, so a create or delete between pages can shift a row. Every yielded value is the summary shape, which carries exposed and updatedAt alongside the identifiers.
Example
use Envless\Envless;
$envless = new Envless();
foreach ($envless->environments->iterate('api') as $environment) {
echo $environment['slug'], PHP_EOL;
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$project | string | Yes | Project slug or uniqueId that owns the environments. |
$product | string | No | Product slug that disambiguates an ambiguous project slug. |
$limit | int | No | Page size used for each underlying request, capped at 100. |
$offset | int | No | Row to start the walk from. |
$search | string | No | Case insensitive substring match on the environment name or slug. |
$order | string | No | asc or desc sorts by creation time, oldest or newest first. Anything else, or nothing, sorts by name. |
$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 EnvironmentSummaryResource values, one per environment.
Reads the environments 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
- This returns a
Generator: no request is sent until the loop pulls the first value.
Required scopes
environments:read
Underlying endpoint
GET /projects/{slug}/environments
Request and response schema, every error code, and a live playground.
In TypeScript
envless.environments.iterate()
The same method in @goenvless/sdk, with the same request, retries and errors.