PHPackages                             bentools/pager - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. bentools/pager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bentools/pager
==============

A simple pager class with delta management

3.2.2(7y ago)52.5kMITPHPPHP &gt;=7.1

Since Dec 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/bpolaszek/bentools-pager)[ Packagist](https://packagist.org/packages/bentools/pager)[ Docs](https://github.com/bpolaszek/bentools-pager)[ RSS](/packages/bentools-pager/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (8)Versions (16)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/a318757cf318cd5524be1e4f80a03acaaf4ca5f2e2acb539efb28cd5429424b7/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f70616765722f762f737461626c65)](https://packagist.org/packages/bentools/pager)[![License](https://camo.githubusercontent.com/be35ac688bb517acad7b2ca07f472fb99d06ea46d96af6e95115a3867586dba3/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f70616765722f6c6963656e7365)](https://packagist.org/packages/bentools/pager)[![Build Status](https://camo.githubusercontent.com/e6d636bb5914d6849ca1d8cf7cc16eafc829da4606e5b388c5122e4e1e814cb4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62706f6c61737a656b2f62656e746f6f6c732d70616765722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/bpolaszek/bentools-pager)[![Coverage Status](https://camo.githubusercontent.com/26a8653a3a6784f4d742e669e5c59bf372232ec034156588602c3b5b86d7154f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f62706f6c61737a656b2f62656e746f6f6c732d70616765722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/bpolaszek/bentools-pager?branch=master)[![Quality Score](https://camo.githubusercontent.com/9fe44f3aefcab20c5548d4b915444a9c349ce293e4d398e0e00209035ed8ad9f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62706f6c61737a656b2f62656e746f6f6c732d70616765722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bpolaszek/bentools-pager)[![Total Downloads](https://camo.githubusercontent.com/eaf25fadc932339d2ff98cf55b797cd3e97cd8f7e50818193159208224cfeb35/68747470733a2f2f706f7365722e707567782e6f72672f62656e746f6f6c732f70616765722f646f776e6c6f616473)](https://packagist.org/packages/bentools/pager)

bentools/pager
==============

[](#bentoolspager)

PHP7.1+ - A simple OOP pager, the way it should be, following [SOLID](https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)) principles.

Usage
-----

[](#usage)

You just need to provide 3 informations:

- The number of items per page
- The current page number (can be provided by factories reading the current Url)
- The total number of items.

```
use BenTools\Pager\Model\Pager;

foreach (new Pager($perPage, $currentPageNumber, $numFound) as $page) {
    $page->getPageNumber(); // Returns the page number
    $page->count(); // Returns the number of items the page contains
}
```

Shortcuts:

```
use BenTools\Pager\Model\Pager;

foreach (new Pager($perPage, $currentPageNumber, $numFound) as $page) {
    (string) $page; // $page->getPageNumber() shortcut
    count($page); // $page->count() shortcut
}
```

Example
-------

[](#example)

```
# http://localhost/?page_number=3

require_once __DIR__ . '/vendor/autoload.php';

use BenTools\Pager\Model\Factory\PageParameterUrlBuilder;

$perPage = 10;
// It will look for a page_number param in the request URI (and sets current page to #1 if not found)
$urlBuilder = PageParameterUrlBuilder::fromRequestUri($perPage, 'page_number');
$pager = $urlBuilder->createPager();
$pager->setNumFound(53);

printf('Total number of pages: %s' . PHP_EOL, count($pager));
printf('Current page number: %s' . PHP_EOL, $pager->getCurrentPage());

print PHP_EOL;

printf('First page number: %s' . PHP_EOL, $pager->getFirstPage());
printf('Previous page number: %s' . PHP_EOL, $pager->getPreviousPage());
printf('Next page number: %s' . PHP_EOL, $pager->getNextPage());
printf('Last page number: %s' . PHP_EOL, $pager->getLastPage());

print PHP_EOL;

foreach ($pager as $page) {
    printf(
            'Page %s contains %d items. - Url: %s' . PHP_EOL,
            $page,
            count($page),
            $pager->getUrl($page)
        );
}
```

Output:

```
Total number of pages: 6
Current page number: 1

First page number: 1
Previous page number:
Next page number: 2
Last page number: 6

Page 1 contains 10 items. - Url: /?page_number=1
Page 2 contains 10 items. - Url: /?page_number=2
Page 3 contains 10 items. - Url: /?page_number=3
Page 4 contains 10 items. - Url: /?page_number=4
Page 5 contains 10 items. - Url: /?page_number=5
Page 6 contains 3 items. - Url: /?page_number=6

```

Delta Management
----------------

[](#delta-management)

When you have a huge number of pages, you can use the `DeltaPager` decorator to show only relevant pages.

```
# http://localhost/?page=30

require_once __DIR__ . '/vendor/autoload.php';

use BenTools\Pager\Model\DeltaPager;
use BenTools\Pager\Model\Factory\PageParameterUrlBuilder;

$perPage = 10;
$pager = PageParameterUrlBuilder::fromRequestUri($perPage)->createPager();
$pager->setNumFound(500);

printf('Total number of pages: %s' . PHP_EOL, count($pager));
printf('Current page number: %s' . PHP_EOL, $pager->getCurrentPage());

print PHP_EOL;

printf('First page number: %s' . PHP_EOL, $pager->getFirstPage());
printf('Previous page number: %s' . PHP_EOL, $pager->getPreviousPage());
printf('Next page number: %s' . PHP_EOL, $pager->getNextPage());
printf('Last page number: %s' . PHP_EOL, $pager->getLastPage());

print PHP_EOL;

$previous = null;
$delta = 2;
foreach (new DeltaPager($pager, $delta) as $page) {
    if (null !== $previous && $previous->getPageNumber() != $page->getPageNumber() - 1) {
        print '...' . PHP_EOL;
    }
    printf('Page %s' . PHP_EOL, $page);
    $previous = $page;
}
```

Output:

```
Total number of pages: 50
Current page number: 30

First page number: 1
Previous page number: 29
Next page number: 31
Last page number: 50

Page 1
...
Page 28
Page 29
Page 30
Page 31
Page 32
...
Page 50

```

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

[](#installation)

> composer require bentools/pager

Tests
-----

[](#tests)

> ./vendor/bin/phpunit

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 89.3% 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 ~100 days

Recently: every ~95 days

Total

15

Last Release

2761d ago

Major Versions

1.0 → 2.02015-01-14

2.2.3 → 3.02017-07-19

PHP version history (4 changes)1.0PHP &gt;=5.3

2.0PHP &gt;=5.4

2.2.2PHP &gt;=5.4.0

3.0PHP &gt;=7.1

### Community

Maintainers

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

---

Top Contributors

[![bpolaszek](https://avatars.githubusercontent.com/u/5569077?v=4)](https://github.com/bpolaszek "bpolaszek (25 commits)")[![ben-synapse](https://avatars.githubusercontent.com/u/36077477?v=4)](https://github.com/ben-synapse "ben-synapse (3 commits)")

---

Tags

pagepagerpaginationdelta

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/bentools-pager/health.svg)

```
[![Health](https://phpackages.com/badges/bentools-pager/health.svg)](https://phpackages.com/packages/bentools-pager)
```

###  Alternatives

[aplus/pagination

Aplus Framework Pagination Library

2091.6M3](/packages/aplus-pagination)[kop/yii2-scroll-pager

Infinite AJAX scrolling for Yii2 ListView widget

180706.5k10](/packages/kop-yii2-scroll-pager)[beberlei/porpaginas

Library that generically solves several pagination issues with DAO/repository abstractions.

163612.6k11](/packages/beberlei-porpaginas)[ashleydawson/simple-pagination

Simple, lightweight and universal service that implements pagination on collections of things

18161.2k2](/packages/ashleydawson-simple-pagination)[soup/paginator

Paginator is a simple class that allows you to create pagination. It doesn't require any database connection. It is compatible with Twitter's Bootstrap Framework, by using the CSS class pagination that is also attached.

351.5k](/packages/soup-paginator)[ttskch/paginator-bundle

The most thin, simple and customizable paginator bundle for Symfony

1113.2k](/packages/ttskch-paginator-bundle)

PHPackages © 2026

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