The PageIterator class implements the PHP Iterator interface to allow iterating through all pages of a list response without manually managing page numbers.
Usage #
Use listAll() on any resource class to get a PageIterator:
$iterator = $client->licenses->listAll(['filter' => ['status' => 'active']]);
foreach ($iterator as $license) {
// Each iteration yields one license record (not a page)
echo $license['id'] . PHP_EOL;
}
Behavior #
- Pages are loaded lazily: the next page is only fetched when the iterator exhausts the current page’s records.
- The default page size is
per_page = 100. - The iterator stops automatically when there are no more pages (
nextlink is null in the pagination response).
Counting Total Records #
The total record count is available after the first page has loaded:
$iterator = $client->licenses->listAll();
$iterator->rewind(); // triggers first page load
echo $iterator->getTotal(); // total records across all pages
