Pagerfanta
A PHP pagination library that calculates and renders paginated lists from many data providers
Repository Health
Technical Analysis
Pagerfanta is a PHP library that helps with calculating and rendering paginated lists. Its core (pagerfanta/core) provides a Pagerfanta object that wraps an adapter for a data source, exposing current page, per-page, total counts, and the current page’s results.
Through a broad set of adapters it paginates plain arrays, Doctrine ORM/DBAL/Collections, Elastica, Solarium, and more, and it ships view classes plus Twig integration to render pagination controls. It is a continuation of the original White October Pagerfanta package.
What You Get
- A Pagerfanta object exposing current page, per-page, total count, and result slicing
- An adapter interface with implementations for arrays and callbacks
- Optional adapters for Doctrine ORM, DBAL, Collections, Elastica, and Solarium
- View classes and Twig integration for rendering pagination markup
- Configurable out-of-range and max-per-page behavior with clear exceptions
Common Use Cases
- Paginating database result sets from Doctrine ORM or DBAL queries
- Rendering page-number navigation in Symfony or plain PHP apps
- Paginating search results from Elasticsearch (Elastica) or Solr (Solarium)
- Slicing large in-memory arrays into pages for API responses
Under The Hood
Architecture - The core (lib/Core) defines a Pagerfanta object that holds an AdapterInterface and pagination parameters; the adapter reports the total item count and returns a slice for the current page, while the Pagerfanta object derives page counts, ranges, and navigation flags. View classes (and the Twig package under lib/Twig) render that state into markup, and provider-specific adapters live under lib/Adapter (Doctrine, Elastica, Solarium).
Tech Stack - Modern PHP distributed via Composer as a monorepo of split packages (pagerfanta/core plus per-provider adapter packages), each with its own composer.json; tooling includes PHPUnit, PHPStan with a baseline, and Rector for automated refactoring.
Code Quality - The repository is organized into cleanly separated adapter packages, each with dedicated Tests directories, backed by PHPStan static analysis, a maintained CHANGELOG, and documented upgrade guides (UPGRADE-4.0.md), signalling a well-engineered and testable design.
API Design - The public API is minimal and intuitive: construct a Pagerfanta with an adapter, set the current page and max-per-page, then read getNbPages(), getCurrentPageResults(), and related accessors. Swapping data sources means swapping adapters, which keeps calling code stable and onboarding straightforward.
Used by 2 apps in this directory
Shlink
Developer Tools · Marketing
Self-hosted PHP URL shortener with a full REST API, dynamic redirect rules, and real-time visit analytics under your own domain.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.