for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Quantum PHP Framework
*
* An open source software development framework for PHP
* @package Quantum
* @author Arman Ag. <[email protected]>
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
* @link http://quantum.softberg.org/
* @since 2.9.7
*/
namespace Quantum\Paginator\Adapters;
use Quantum\Paginator\Contracts\PaginatorInterface;
use Quantum\Paginator\Traits\PaginatorTrait;
* Class ArrayPaginator
* @package Quantum\Paginator
class ArrayPaginator implements PaginatorInterface
{
use PaginatorTrait;
* @var array
private $items;
* @param array $items
* @param int $perPage
* @param int $page
public function __construct(array $items, int $perPage, int $page = 1)
$this->initialize($perPage, $page);
$this->items = $items;
$this->total = count($items);
}
* @param array $params
* @return PaginatorInterface
public static function fromArray(array $params): PaginatorInterface
return new self(
$params['items'],
$params['perPage'] ?? 10,
$params['page'] ?? 1
);
* @inheritDoc
public function data(): array
return array_slice(
$this->items,
($this->page - 1) * $this->perPage,
$this->perPage
public function firstItem()
$data = $this->data();
if (empty($data)) {
return null;
return reset($data);
public function lastItem()
return end($data);