Download the PHP package zenstruck/porpaginas without Composer
On this page you can find all versions of the php package zenstruck/porpaginas. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zenstruck/porpaginas
More information about zenstruck/porpaginas
Files in zenstruck/porpaginas
Package porpaginas
Short Description Library that generically solves several pagination issues with DAO/repository abstractions.
License MIT
Informations about the package porpaginas
zenstruck/porpaginas
NOTE: This library is a fork of beberlei/porpaginas.
This library solves a bunch of issues that comes up with APIs of Repository classes alot:
- You need different methods for paginatable and non-paginatable finder methods.
- You need to expose the underlying data-source and return query objects from your repository.
- Serialization of paginators should be easily possible for REST APIs
Both Pagerfanta and KnpLabs Pager don't solve this issue and their APIs are really problematic in this regard. You need to return the query objects or adapters for paginators from your repositories to get it working and then use an API on the controller side to turn them into a paginated result set.
Porpaginas solves this by introducing a sane abstraction for paginated results. For rendering purposes you can integrate with either Pagerfanta or KnpLabs Pager, this library is not about reimplementating the view part of pagination.
Central part of this library is the interface Result
:
This API offers you two ways to iterate over the paginatable result,
either the full result or a paginated window of the result using take()
.
One drawback is that the query is always lazily executed inside
the Result
and not directly in the repository.
The Page
interface returned from Result::take()
looks like this:
Supported Backends
- Array
- Doctrine ORM
- Doctrine DBAL
Example
Take the following example using Doctrine ORM:
This library also comes with a pagination helper. Using the Pager
, the above controller's
porpaginasListAction()
could be re-written as follows: