Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

microparts/paginateformatter-php

Repository files navigation

Paginate Formatter For PHP

CircleCI codecov

THIS PACKAGE PERMANENTLY MOVED TO https://github.com/spacetab-io/pagerfanta-adapt-php


This a simple formatter based on Pagerfanta library. Specially created for follow up corporate standards of pagination format.

Installation

composer install microparts/paginateformatter-php

Usage

Basic:

use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Microparts\PaginateFormatter\PaginateFormatter;

$adapter = new ArrayAdapter($array);
$pagerfanta = new Pagerfanta($adapter);
$paginate = new PaginateFormatter($pagerfanta);

$paginate->format(); // returns formatted output.

Replace current page results from Pagerfanta:

use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Microparts\PaginateFormatter\PaginateFormatter;

$adapter = new ArrayAdapter($array);
$pagerfanta = new Pagerfanta($adapter);
$paginate = new PaginateFormatter($pagerfanta);

$paginate->setItems($transformedModel)->format();

Depends

  • >= PHP 7.1
  • Composer for install package

Additional adapters

This package also add a new following adapters:

  • Microparts\PaginateFormatter\Adapters\BasePdoAdapter.php
  • Microparts\PaginateFormatter\Adapters\FluentPdoAdapter.php
  • Microparts\PaginateFormatter\Adapters\PaginatePdoAdapter.php

Output format

{
  "data": [{"foo": "bar"}],
  "meta": {
    "pagination": {
      "total": 6,
      "per_page": 1,
      "current_page": 1,
      "total_pages": 6,
      "prev_page": null,
      "next_page": 2
    }
  }
}

License

GNU GPL v3