componenta/http-paginate-interceptor

HTTP pagination result interceptor for Componenta

Maintainers

Package info

github.com/componenta/http-paginate-interceptor

pkg:composer/componenta/http-paginate-interceptor

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-17 11:21 UTC

This package is auto-updated.

Last update: 2026-06-17 15:43:59 UTC


README

HTTP interceptor for componenta/interceptor that turns PaginatorInterface into Componenta\Http\ResourcePaginator with prev / next links.

Русская документация

Boundary

This package contains one attribute: #[Paginate]. The attribute itself implements InterceptorInterface, so it does not need a separate #[Intercept(...)].

It does not fetch data and does not create paginators. The route handler must return Componenta\Stdlib\PaginatorInterface.

Installation

composer require componenta/http-paginate-interceptor

Quick Start

use Componenta\Interceptor\Http\Attribute\Respond;
use Componenta\Interceptor\Http\Paginate;

final class PostController
{
    #[Respond(200, 'application/json')]
    #[Paginate]
    public function index(PostListQuery $query): PaginatorInterface
    {
        return $this->posts->list($query);
    }
}

If the result does not implement PaginatorInterface, #[Paginate] returns it unchanged.

Response Fields

By default ResourcePaginator receives:

count, prev, next, range, page, results

You can keep only selected metadata fields. results is always added automatically:

use Componenta\Interceptor\Http\Paginate;

#[Paginate(Paginate::FIELD_COUNT, Paginate::FIELD_NEXT)]
public function index(): PaginatorInterface {}

HTTP Request In Context

prev and next generation requires the current ServerRequestInterface. componenta/router-app passes the HTTP request into callable context when executing route handlers. If #[Paginate] receives a paginator without that request attribute, it throws LogicException.

Scope

#[Paginate] is restricted to Scope::HTTP.

License

MIT