kgilden / pager
A paginator library to split results into multiple pages
Installs: 16 826
Dependents: 1
Suggesters: 0
Security: 0
Stars: 13
Watchers: 2
Forks: 2
Open Issues: 3
Requires
- php: ^7.4|^8.0
Requires (Dev)
- doctrine/orm: ^2.4
- phpunit/phpunit: ^8.2.3
- ruflin/elastica: >=0.90.1.0
- symfony/config: ^4.4|^5.4
- symfony/dependency-injection: ^4.4|^5.4
- symfony/http-foundation: ^4.4|^5.4
- symfony/http-kernel: ^4.4|^5.4
- symfony/yaml: ^5.1
- twig/twig: ^2.7|^3
Suggests
- ext-mongo: to use MongoAdapter
- doctrine/orm: ^2.4, if you're using DqlAdapter
- ruflin/elastica: >=0.90.1.0 to use ElasticaAdapter
- symfony/http-foundation: ^4.4|^5.4 for automatic current page detection
- twig/twig: ^2.7|^3 to use the Twig Extension
Conflicts
- doctrine/orm: <2.3
- ruflin/elastica: <0.90.1.0
- symfony/http-foundation: <4.4|<5.4,>=5
- twig/twig: <2.7|>=4
This package is auto-updated.
Last update: 2024-12-07 22:09:07 UTC
README
Pager is a library to split results to multiple pages - any way you want them!
Features
- 5 built-in adapters for arrays, Doctrine ORM, ElasticSearch & MongoDB;
- safe subset of methods to not even count items;
- strategies to split pages inequally (i.e. 2 last pages merged);
- integrates nicely with Symfony's
HttpKernel
to infer the current page; - provides a bundle to seamlessly integrate with Symfony;
Documentation
Usage
Two objects work together to split a set of items to pages: pager and adapter. Pagers act as factories for pages. Adapters allow concrete item sets to be paged (for example there's an adapter for Doctrine queries).
Here's an example with arrays (check out the docs for more):
<?php use KG\Pager\Pager; use KG\Pager\Adapter\ArrayAdapter; $list = ['apple', 'banana', 'cucumber', 'dragonfruit', 'eggplant']; $itemsPerPage = 2; $currentPage = 3; $pager = new Pager(); $page = $pager->paginate(new ArrayAdapter($list), $itemsPerPage, $currentPage); $page->isFirst(); // false $page->isLast(); // true - there's a total of 3 pages $page->getNumber(); // 3 - it's $currentPage count($page->getItems()); // 1 $page->getItems(); // ["eggplant"] ?>
Installation
Install using composer: composer.phar require kgilden/pager
Testing
Simply run phpunit
in the root directory of the library for the full
test suite.
License
This library is under the MIT license.