Pagerfanta

A PHP pagination library that calculates and renders paginated lists from many data providers

Library
Composer
vv4.8.0
424stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
54/100Fair
Development Activity44
Maintenance16
Community68
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture86
Code Quality84
Innovation72
Learning Curve82

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search