Versions

$envless->versions->iterate()

Stream versions one row at a time

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

Yields versions individually, fetching the next page only once the current one is drained. This is the right shape for scanning history for a particular label or note, because it stops fetching the moment you break.

It returns a Generator, so put the call straight into a foreach loop. No request goes out until the first iteration.

Example

php
use Envless\Envless;

$envless = new Envless();

foreach ($envless->versions->iterate('api', 'production') as $version) {
    if (str_contains($version['note'] ?? '', 'migration')) {
        echo $version['id'], PHP_EOL;

        break;
    }
}

Parameters

ParameterTypeRequiredDescription
$projectstringYesProject slug or project uniqueId.
$environmentstringYesEnvironment slug, since an environment uniqueId will not resolve here.
$productstringNoProduct slug used to disambiguate a project slug shared across products.
$limitintNoPage size fetched behind the scenes, clamped to 100.
$offsetintNoRow to start streaming from.
$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 VersionResource values until the pages run out.

Reads the versions 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 publishing a version mid walk shifts the window and can repeat a row.
  • On the Free plan only the latest version is listed; the older ones are stored but need Dev or above to be read, and reading one there is 402 plan.upgrade_required.

Required scopes

versions:read

Underlying endpoint

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

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

In TypeScript

envless.versions.iterate()

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