Environments

$envless->environments->iterate()

Stream environments page by page

php
/** @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,
): \Generator

Yields 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

php
use Envless\Envless;

$envless = new Envless();

foreach ($envless->environments->iterate('api') as $environment) {
    echo $environment['slug'], PHP_EOL;
}

Parameters

ParameterTypeRequiredDescription
$projectstringYesProject slug or uniqueId that owns the environments.
$productstringNoProduct slug that disambiguates an ambiguous project slug.
$limitintNoPage size used for each underlying request, capped at 100.
$offsetintNoRow to start the walk from.
$searchstringNoCase insensitive substring match on the environment name or slug.
$orderstringNoasc or desc sorts by creation time, oldest or newest first. Anything else, or nothing, sorts by name.
$timeoutint|floatNoSeconds 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.