Versions

$envless->versions->iterateEntries()

Stream version entries one at a time

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

Yields version entries individually, fetching the next page only once the current one is drained. Use it to rotate a large environment without holding its whole encrypted history in memory.

It returns a Generator, so put the call straight into a foreach loop. reencryptEntries rewrites only value and defaultValue and never adds or removes rows, so writing back mid stream does not shift the window. Publishing a version mid walk does shift it, because the new entries land in the same flat set.

Example

php
use Envless\Envless;

$envless = new Envless();

$ids = [];

foreach ($envless->versions->iterateEntries('api', 'production') as $entry) {
    if ($entry['value'] !== null) {
        $ids[] = $entry['id'];
    }
}

echo count($ids), PHP_EOL;

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 VersionEntryResource values until the pages run out.

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

  • Buffer the yielded entries and write them back in batches. One reencryptEntries call per entry works but costs a request each.
  • Freeze publishing while a rotation walk is in flight, otherwise a new version adds entries encrypted under the old key after you have already passed that offset.

Required scopes

versions:read and variables:read

Underlying endpoint

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

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

In TypeScript

envless.versions.iterateEntries()

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