Pagerfanta Doctrine ORM Adapter

Pagerfanta adapter that paginates Doctrine ORM Query and QueryBuilder results

Library
Composer
vv4.8.0
42stars
Custom / Unknown

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
23/100Needs Attention
Development Activity4
Maintenance0
Community16
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
68/100Good
Architecture65
Code Quality72
Innovation45
Learning Curve90

The Pagerfanta Doctrine ORM Adapter plugs Doctrine ORM into the Pagerfanta pagination library by implementing Pagerfanta’s AdapterInterface around Doctrine’s native Paginator. It accepts either a Doctrine Query or QueryBuilder and handles both counting total results and slicing a specific page’s worth of results, including correctly handling joined collections that would otherwise skew count queries.

As a thin, single-class adapter (QueryAdapter), it lets applications already using Doctrine ORM add pagination to any query with a couple of lines of code, delegating all the pagination UI/logic to Pagerfanta’s core library while this adapter handles only the Doctrine-specific counting and fetching mechanics.

What You Get

  • A QueryAdapter class implementing Pagerfanta’s AdapterInterface for Doctrine Query/QueryBuilder objects
  • Correct result counting via Doctrine’s Paginator, including queries with joined collections (fetchJoinCollection)
  • Configurable output-walker usage for advanced query pagination scenarios
  • Direct integration point with Pagerfanta’s Pagerfanta core class for rendering paginated views

Common Use Cases

  • Paginating a Doctrine ORM entity listing (e.g. admin panels, search results) with correct joined-collection counts
  • Adding page-based navigation to any Doctrine QueryBuilder-driven listing endpoint
  • Building paginated API responses backed by Doctrine ORM queries
  • Combining with Pagerfanta’s Twig extension to render pagination controls for Doctrine-backed listings

Under The Hood

Architecture The adapter is a single class, QueryAdapter, that wraps a Doctrine Query or QueryBuilder in a Doctrine ORM Paginator at construction time, then implements Pagerfanta’s two-method AdapterInterface contract: getNbResults() delegates to count($paginator), and getSlice($offset, $length) sets setFirstResult/setMaxResults on the underlying query before returning the paginator’s iterator. This keeps all pagination-specific logic (page math, view rendering) in Pagerfanta’s core, with this package responsible only for correctly counting/fetching from Doctrine.

Tech Stack PHP 8.1+ with a direct dependency on doctrine/orm (for Query, QueryBuilder, and the Tools\Pagination\Paginator) and pagerfanta/core for the AdapterInterface contract. Tests use PHPUnit against in-memory Doctrine test entities.

Code Quality The package is intentionally minimal — one production class (QueryAdapter.php, under 60 lines) paired with a focused test suite (QueryAdapterTest.php plus supporting test entities), which keeps its surface area small and easy to audit; there is no dead code or unused abstraction given the narrow scope.

API Design The adapter requires only wrapping an existing Doctrine Query/QueryBuilder in new QueryAdapter(...) and handing it to Pagerfanta’s core Pagerfanta class — a near-zero learning curve for developers already using both libraries.

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