tal7aouy/pagify

There is no license information available for the latest version (v1.0.0) of this package.

A PHP library for JSON pagination with various features.

v1.0.0 2024-08-20 11:29 UTC

This package is auto-updated.

Last update: 2024-11-20 12:01:42 UTC


README

GitHub Workflow Status Packagist License PHP

Pagify is a modern PHP library for handling JSON pagination efficiently. Designed to be simple yet powerful, this library helps you paginate data seamlessly for APIs and web applications.

Features

  • Easy Integration: Simple to use with minimal setup.
  • Flexible Configuration: Customize page size and pagination behavior.
  • Error Handling: Graceful handling of invalid parameters.
  • CLI Tool: Command-line utility for quick testing and usage.
  • Logging: Built-in logging for debugging and monitoring.

Installation

You can install Pagify using Composer:

composer require tal7aouy/pagify

Usage

Basic Usage

use Tal7aouy\Pagify\JsonPaginator;
use Tal7aouy\Pagify\PaginatorFactory;

$items = range(1, 100); // Example data
$totalItems = count($items);
$paginator = PaginatorFactory::createPaginator($items, $totalItems, 1, 10);

echo $paginator->toJson();

CLI Tool

To use the CLI tool, run:

./pagify <currentPage> <perPage>

Example:

./pagify 2 10

Configuration

You can configure default settings in config/paginator.php:

return [
    'default_per_page' => 10,
];

Testing

Unit Tests

Run unit tests with PestPHP:

composer test

Example Test

it('paginates data correctly', function () {
    // Test code here...
});

Contributing

Contributions are welcome! Please open an issue or submit a pull request. For more details, see CONTRIBUTING.md.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Made with ❤️ by Mhammed Talhaouy