/** @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,
): \GeneratorYields 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
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
| Parameter | Type | Required | Description |
|---|---|---|---|
$project | string | Yes | Project slug or project uniqueId. |
$environment | string | Yes | Environment slug, since an environment uniqueId will not resolve here. |
$product | string | No | Product slug used to disambiguate a project slug shared across products. |
$limit | int | No | Page size fetched behind the scenes, clamped to 100. |
$offset | int | No | Row to start streaming from. |
$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 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.