Variables

$envless->variables->iterate()

Stream variables one page at a time

php
/** @return \Generator<int, VariableResource, mixed, void> */
public function iterate(
    string $project,
    string $environment,
    ?int $limit = null,
    ?int $offset = null,
    ?string $product = null,
    int|float|null $timeout = null,
): \Generator

Returns a Generator that yields variables one at a time and fetches the next page only when the current one is exhausted. Nothing is requested until you start consuming it, so calling it without a foreach does no work.

Breaking out of the loop ends the walk and no further requests are made. The generator advances offset by the number of items it actually received, so a concurrent write between pages can shift rows and make the walk skip or repeat one. When you need a consistent picture, read with listAll and send every row to apply as the baseline, which turns a concurrent change into a 409 instead of a silent skip.

Example

php
use Envless\Envless;

$envless = new Envless();

foreach ($envless->variables->iterate('api', 'production') as $variable) {
    echo "{$variable['name']} {$variable['updatedAt']}", PHP_EOL;
}

Parameters

ParameterTypeRequiredDescription
$projectstringYesProject slug the environment belongs to.
$environmentstringYesEnvironment slug to read variables from.
$limitintNoPage size for each underlying request, clamped to 100.
$offsetintNoOffset the walk starts from, defaults to 0.
$productstringNoProduct slug, needed when the project slug is not unique in the workspace.
$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

Generator<int, VariableResource> yielding one variable per iteration.

Reads the variables 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

  • Memory stays flat at one page, which is the reason to pick this over listAll for large environments.

Required scopes

variables:read

Underlying endpoint

GET /projects/{slug}/environments/{environmentSlug}/variables

Request and response schema, every error code, and a live playground.

In TypeScript

envless.variables.iterate()

The same method in @goenvless/sdk, with the same request, retries and errors.