1
0
Fork
You've already forked PagerWave
0
No description
  • PHP 100%
Emma 6749513077
All checks were successful
/ test (7.3) (push) Successful in 31s
/ test (7.2) (push) Successful in 32s
/ test (7.4) (push) Successful in 30s
/ test (8.0) (push) Successful in 29s
/ test (8.2) (push) Successful in 31s
/ test (8.1) (push) Successful in 33s
/ test (8.4) (push) Successful in 41s
/ test (8.3) (push) Successful in 43s
/ test (8.5) (push) Successful in 29s
add forgejo-runner ci
2026年05月08日 13:11:11 +02:00
.forgejo/workflows add forgejo-runner ci 2026年05月08日 13:11:11 +02:00
docs split out Doctrine ORM support to separate package 2020年09月27日 20:55:36 +02:00
src support php 8.4 2024年11月22日 17:53:27 +01:00
tests remove unused doctrine annotations 2022年10月13日 19:37:59 +02:00
.editorconfig add forgejo-runner ci 2026年05月08日 13:11:11 +02:00
.gitattributes add .gitattributes 2020年04月25日 20:44:54 +02:00
.gitignore initial commit 2020年04月22日 16:37:41 +02:00
.php_cs.dist initial commit 2020年04月22日 16:37:41 +02:00
CHANGELOG.md support php 8.5 2026年02月10日 14:02:45 +01:00
composer.json support php 8.5 2026年02月10日 14:02:45 +01:00
LICENSE initial commit 2020年04月22日 16:37:41 +02:00
phpunit.xml.dist initial commit 2020年04月22日 16:37:41 +02:00
README.md prepare 1.3.0 release 2020年11月29日 21:54:17 +01:00

PagerWave

PagerWave is a pagination library for PHP.

It differs from most pagination libraries in that it uses key sets to keep track of the current location. Where traditional paginators use a page number to calculate an offset into your collection, PagerWave fetches n + 1 items when paging, then uses the n + 1th item to determine the starting point of the next page.

This difference is most obvious in the generated URLs. Offset-based paginators will give you a URL like /posts/1, while PagerWave will give you a URL like /posts/?next[date]=2020年04月20日&[id]=455. While uglier, this has several performance and practical benefits compared to offset-based pagination:

  • The items on a page won't change as you add new items. This makes it ideal for infinite scroll scenarios, as adding or deleting items while someone is scrolling won't cause duplicate or skipped items, respectively.

  • It is fast with large databases, as key sets can take advantage of column indexes. Offset-based pagination, on the other hand, does not scale well as the database grows.

Currently, PagerWave has these drawbacks:

  • Backwards navigation is not supported.

  • Retrieving total item count is not supported.

  • Sorting by text might work, but is sketchy as the text would have to appear in the URL.

These may or may not be solved in the future.

Example

<?php
use PagerWave\Definition;
use PagerWave\EntryReader\SimpleEntryReader;
use PagerWave\QueryReader\NativeQueryReader;
use PagerWave\Extension\DoctrineOrm\QueryBuilderAdapter;
use PagerWave\Paginator;
use PagerWave\UrlGenerator\NativeUrlGenerator;
$paginator = new Paginator(
 new SimpleEntryReader(),
 new NativeQueryReader(),
 new NativeUrlGenerator()
);
$queryBuilder = $em->createQueryBuilder()
 ->select('p')
 ->from(\App\Entity\Post::class, 'p');
$adapter = new QueryBuilderAdapter($queryBuilder);
$definition = new Definition(['rank' => 'DESC', 'id' => 'ASC']);
$cursor = $paginator->paginate($adapter, 100, $definition);
foreach ($cursor as $post) {
 printf("Title: %s (rank: %d)\n", $post->getTitle(), $post->getRank());
}
if ($cursor->hasNextPage()) {
 printf('<a href="%s">Show more</a>', $cursor->getNextPageUrl());
}

Supported paginatable collections

Supported HTTP abstractions

Acknowledgements

PagerWave is based on theory from Use the Index, Luke, and has taken inspiration from the Pagerfanta library.

Licence

This project is released under the Zlib licence.