PHPackages                             dzava/resource-iterator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dzava/resource-iterator

ActiveLibrary

dzava/resource-iterator
=======================

v1.3.0(4y ago)08MITPHPPHP ^7.4|^8.0CI failing

Since Apr 25Pushed 4y ago1 watchersCompare

[ Source](https://github.com/dzava/resource-iterator)[ Packagist](https://packagist.org/packages/dzava/resource-iterator)[ Docs](https://github.com/dzava/resource-iterator)[ RSS](/packages/dzava-resource-iterator/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

This package provides the foundation for iterating over paginated json apis.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require dzava/resource-iterator
```

Usage
-----

[](#usage)

```
use Dzava\ResourceIterator\PagedResourceIterator;

// Given a response with the following structure
// {
//     "total_pages": 4,
//     "data": []
// }
$users = (new PagedResourceIterator('https://example.com/api/users/'))->toArray();

// Given a response with the following structure
// {
//     "pagination: {
//         "total_pages": 4,
//     }
//     "data": []
// }
$users = (new PagedResourceIterator('https://example.com/api/users/'))
    ->withConfig(['totalPages' => 'pagination.total_pages'])
    ->toArray();
```

Use the `withConfig` method to override the default configuration.

```
[
    'page' => 'page', // name of the query param that indicates the current page
    'data' => 'data', // the response field that contains the data
    'totalPages' => 'total_pages' // the response field that contains the total number of pages
]
```

Custom iterators
----------------

[](#custom-iterators)

To create a custom iterator simply extend the `ResourceIterator` class and implement the `nextPage` method. The method should return the value of the `page` query parameter that points to the next page or `false` when there are no more pages. If the url for the next page is more complex you can override the `nextPageUrl` method and return the complete url for the next page or `false`.

```
use Dzava\ResourceIterator\ResourceIterator;

class GithubResourceIterator extends ResourceIterator
{
    public function __construct($url)
    {
        parent::__construct($url);

        $this->withConfig(['data' => null]);
    }

    protected function nextPageUrl()
    {
        preg_match('/.*?rel="next"/', $this->lastResponse->getHeader('Link')[0], $matches);

        return $matches[1] ?? false;
    }
}

$iterator = new GithubResourceIterator('https://api.github.com/orgs/laravel/repos');

foreach ($iterator->items() as $repo) {
    echo "{$repo->full_name}\n";
}
```

License
-------

[](#license)

The [MIT License (MIT)](LICENSE.md).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~309 days

Total

4

Last Release

1648d ago

PHP version history (2 changes)v1.0.0PHP ^7.1

v1.3.0PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/f5c257b625706f22f168252097c508646c5043227ea557da551221702702ccea?d=identicon)[dzava](/maintainers/dzava)

---

Top Contributors

[![dzava](https://avatars.githubusercontent.com/u/1516475?v=4)](https://github.com/dzava "dzava (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dzava-resource-iterator/health.svg)

```
[![Health](https://phpackages.com/badges/dzava-resource-iterator/health.svg)](https://phpackages.com/packages/dzava-resource-iterator)
```

###  Alternatives

[s-ichikawa/laravel-sendgrid-driver

This library adds a 'sendgrid' mail driver to Laravel.

4139.3M1](/packages/s-ichikawa-laravel-sendgrid-driver)[stechstudio/laravel-zipstream

A fast and simple streaming zip file downloader for Laravel.

4633.7M3](/packages/stechstudio-laravel-zipstream)[laravel-notification-channels/microsoft-teams

A Laravel Notification Channel for Microsoft Teams

1603.0M7](/packages/laravel-notification-channels-microsoft-teams)[spatie/laravel-export

Create a static site bundle from a Laravel app

646127.9k5](/packages/spatie-laravel-export)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
