AzuraCast/src/Paginator.php

241 lines
6.8 KiB
PHP
Raw Normal View History

<?php
2021-07-19 07:53:45 +02:00
declare(strict_types=1);
namespace App;
use App\Http\Response;
use App\Http\RouterInterface;
use App\Http\ServerRequest;
2021-06-10 05:22:13 +02:00
use Countable;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
2021-06-10 05:22:13 +02:00
use IteratorAggregate;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Doctrine\Collections\CollectionAdapter;
use Pagerfanta\Doctrine\ORM\QueryAdapter;
use Pagerfanta\Pagerfanta;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Traversable;
2021-06-10 05:22:13 +02:00
class Paginator implements IteratorAggregate, Countable
{
protected RouterInterface $router;
Dependency Update Changelogs summary: - pyrech/composer-changelogs updated from v1.8.0 to v1.8.1 patch See changes: https://github.com/pyrech/composer-changelogs/compare/v1.8.0...v1.8.1 Release notes: https://github.com/pyrech/composer-changelogs/releases/tag/v1.8.1 - james-heinrich/getid3 updated from dev-master@a440175 to dev-master@1e18087 See changes: https://github.com/JamesHeinrich/getID3/compare/a440175...1e18087 - doctrine/inflector updated from 2.0.3 to 2.0.4 patch See changes: https://github.com/doctrine/inflector/compare/2.0.3...2.0.4 Release notes: https://github.com/doctrine/inflector/releases/tag/2.0.4 - doctrine/common updated from 3.1.2 to 3.2.0 minor See changes: https://github.com/doctrine/common/compare/3.1.2...3.2.0 Release notes: https://github.com/doctrine/common/releases/tag/3.2.0 - doctrine/orm updated from 2.10.1 to 2.10.2 patch See changes: https://github.com/doctrine/orm/compare/2.10.1...2.10.2 Release notes: https://github.com/doctrine/orm/releases/tag/2.10.2 - behat/gherkin updated from v4.8.0 to v4.9.0 minor See changes: https://github.com/Behat/Gherkin/compare/v4.8.0...v4.9.0 Release notes: https://github.com/Behat/Gherkin/releases/tag/v4.9.0 - phpdocumentor/reflection-docblock updated from 5.2.2 to 5.3.0 minor See changes: https://github.com/phpDocumentor/ReflectionDocBlock/compare/5.2.2...5.3.0 Release notes: https://github.com/phpDocumentor/ReflectionDocBlock/releases/tag/5.3.0 - guzzlehttp/psr7 updated from 1.8.3 to 2.1.0 major See changes: https://github.com/guzzle/psr7/compare/1.8.3...2.1.0 Release notes: https://github.com/guzzle/psr7/releases/tag/2.1.0 - guzzlehttp/promises updated from 1.5.0 to 1.5.1 patch See changes: https://github.com/guzzle/promises/compare/1.5.0...1.5.1 Release notes: https://github.com/guzzle/promises/releases/tag/1.5.1 - guzzlehttp/guzzle updated from 7.3.0 to 7.4.0 minor See changes: https://github.com/guzzle/guzzle/compare/7.3.0...7.4.0 Release notes: https://github.com/guzzle/guzzle/releases/tag/7.4.0 - doctrine/migrations updated from 3.2.1 to 3.3.0 minor See changes: https://github.com/doctrine/migrations/compare/3.2.1...3.3.0 Release notes: https://github.com/doctrine/migrations/releases/tag/3.3.0 - gettext/gettext updated from v4.8.5 to v4.8.6 patch See changes: https://github.com/php-gettext/Gettext/compare/v4.8.5...v4.8.6 Release notes: https://github.com/php-gettext/Gettext/releases/tag/v4.8.6 - graham-campbell/guzzle-factory updated from v5.0.0 to v5.0.2 patch See changes: https://github.com/GrahamCampbell/Guzzle-Factory/compare/v5.0.0...v5.0.2 Release notes: https://github.com/GrahamCampbell/Guzzle-Factory/releases/tag/v5.0.2 - aws/aws-sdk-php updated from 3.198.0 to 3.199.2 minor See changes: https://github.com/aws/aws-sdk-php/compare/3.198.0...3.199.2 Release notes: https://github.com/aws/aws-sdk-php/releases/tag/3.199.2 - pagerfanta/core updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/core/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/core/releases/tag/v3.3.1 - pagerfanta/doctrine-collections-adapter updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/doctrine-collections-adapter/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/doctrine-collections-adapter/releases/tag/v3.3.1 - pagerfanta/doctrine-orm-adapter updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/doctrine-orm-adapter/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/doctrine-orm-adapter/releases/tag/v3.3.1 - ramsey/collection updated from 1.2.1 to 1.2.2 patch See changes: https://github.com/ramsey/collection/compare/1.2.1...1.2.2 Release notes: https://github.com/ramsey/collection/releases/tag/1.2.2 - squizlabs/php_codesniffer updated from 3.6.0 to 3.6.1 patch See changes: https://github.com/squizlabs/PHP_CodeSniffer/compare/3.6.0...3.6.1 Release notes: https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.6.1 - phpstan/phpdoc-parser updated from 0.5.6 to 1.2.0 major See changes: https://github.com/phpstan/phpdoc-parser/compare/0.5.6...1.2.0 Release notes: https://github.com/phpstan/phpdoc-parser/releases/tag/1.2.0 - slevomat/coding-standard updated from 7.0.15 to 7.0.16 patch See changes: https://github.com/slevomat/coding-standard/compare/7.0.15...7.0.16 Release notes: https://github.com/slevomat/coding-standard/releases/tag/7.0.16 - egulias/email-validator updated from 3.1.1 to 3.1.2 patch See changes: https://github.com/egulias/EmailValidator/compare/3.1.1...3.1.2 Release notes: https://github.com/egulias/EmailValidator/releases/tag/3.1.2 - graham-campbell/result-type updated from v1.0.2 to v1.0.3 patch See changes: https://github.com/GrahamCampbell/Result-Type/compare/v1.0.2...v1.0.3 Release notes: https://github.com/GrahamCampbell/Result-Type/releases/tag/v1.0.3
2021-10-24 03:16:44 +02:00
/** @var int<1,max> The maximum number of records that can be viewed per page for unauthenticated users. */
protected int $maxPerPage = 25;
/** @var bool Whether the current request is from jQuery Bootgrid */
protected bool $isBootgrid = false;
/** @var bool Whether the user is currently authenticated on this request. */
protected bool $isAuthenticated = false;
/** @var bool Whether to show pagination controls. */
protected bool $isDisabled = true;
/** @var callable|null A callable postprocessor that can be run on each result. */
protected $postprocessor;
public function __construct(
protected Pagerfanta $paginator,
ServerRequestInterface $request
) {
$this->router = $request->getAttribute(ServerRequest::ATTR_ROUTER);
$user = $request->getAttribute(ServerRequest::ATTR_USER);
$this->isAuthenticated = ($user !== null);
$params = $request->getQueryParams();
$this->isBootgrid = isset($params['rowCount']) || isset($params['searchPhrase']);
if ($this->isBootgrid) {
if (isset($params['rowCount'])) {
$this->setPerPage((int)$params['rowCount']);
}
if (isset($params['current'])) {
$this->setCurrentPage((int)$params['current']);
}
} else {
if (isset($params['per_page'])) {
$this->setPerPage((int)$params['per_page']);
}
if (isset($params['page'])) {
$this->setCurrentPage((int)$params['page']);
}
}
}
public function getCurrentPage(): int
{
return $this->paginator->getCurrentPage();
}
public function setCurrentPage(int $currentPage): void
{
$this->paginator->setCurrentPage(
($currentPage >= 1) ? $currentPage : 1
);
}
public function setMaxPerPage(int $maxPerPage): void
{
$this->maxPerPage = ($maxPerPage > 0) ? $maxPerPage : 1;
$this->isDisabled = false;
}
public function getPerPage(): int
{
return $this->paginator->getMaxPerPage();
}
public function setPerPage(int $perPage): void
{
if ($perPage <= 0) {
$perPage = PHP_INT_MAX;
}
Dependency Update Changelogs summary: - pyrech/composer-changelogs updated from v1.8.0 to v1.8.1 patch See changes: https://github.com/pyrech/composer-changelogs/compare/v1.8.0...v1.8.1 Release notes: https://github.com/pyrech/composer-changelogs/releases/tag/v1.8.1 - james-heinrich/getid3 updated from dev-master@a440175 to dev-master@1e18087 See changes: https://github.com/JamesHeinrich/getID3/compare/a440175...1e18087 - doctrine/inflector updated from 2.0.3 to 2.0.4 patch See changes: https://github.com/doctrine/inflector/compare/2.0.3...2.0.4 Release notes: https://github.com/doctrine/inflector/releases/tag/2.0.4 - doctrine/common updated from 3.1.2 to 3.2.0 minor See changes: https://github.com/doctrine/common/compare/3.1.2...3.2.0 Release notes: https://github.com/doctrine/common/releases/tag/3.2.0 - doctrine/orm updated from 2.10.1 to 2.10.2 patch See changes: https://github.com/doctrine/orm/compare/2.10.1...2.10.2 Release notes: https://github.com/doctrine/orm/releases/tag/2.10.2 - behat/gherkin updated from v4.8.0 to v4.9.0 minor See changes: https://github.com/Behat/Gherkin/compare/v4.8.0...v4.9.0 Release notes: https://github.com/Behat/Gherkin/releases/tag/v4.9.0 - phpdocumentor/reflection-docblock updated from 5.2.2 to 5.3.0 minor See changes: https://github.com/phpDocumentor/ReflectionDocBlock/compare/5.2.2...5.3.0 Release notes: https://github.com/phpDocumentor/ReflectionDocBlock/releases/tag/5.3.0 - guzzlehttp/psr7 updated from 1.8.3 to 2.1.0 major See changes: https://github.com/guzzle/psr7/compare/1.8.3...2.1.0 Release notes: https://github.com/guzzle/psr7/releases/tag/2.1.0 - guzzlehttp/promises updated from 1.5.0 to 1.5.1 patch See changes: https://github.com/guzzle/promises/compare/1.5.0...1.5.1 Release notes: https://github.com/guzzle/promises/releases/tag/1.5.1 - guzzlehttp/guzzle updated from 7.3.0 to 7.4.0 minor See changes: https://github.com/guzzle/guzzle/compare/7.3.0...7.4.0 Release notes: https://github.com/guzzle/guzzle/releases/tag/7.4.0 - doctrine/migrations updated from 3.2.1 to 3.3.0 minor See changes: https://github.com/doctrine/migrations/compare/3.2.1...3.3.0 Release notes: https://github.com/doctrine/migrations/releases/tag/3.3.0 - gettext/gettext updated from v4.8.5 to v4.8.6 patch See changes: https://github.com/php-gettext/Gettext/compare/v4.8.5...v4.8.6 Release notes: https://github.com/php-gettext/Gettext/releases/tag/v4.8.6 - graham-campbell/guzzle-factory updated from v5.0.0 to v5.0.2 patch See changes: https://github.com/GrahamCampbell/Guzzle-Factory/compare/v5.0.0...v5.0.2 Release notes: https://github.com/GrahamCampbell/Guzzle-Factory/releases/tag/v5.0.2 - aws/aws-sdk-php updated from 3.198.0 to 3.199.2 minor See changes: https://github.com/aws/aws-sdk-php/compare/3.198.0...3.199.2 Release notes: https://github.com/aws/aws-sdk-php/releases/tag/3.199.2 - pagerfanta/core updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/core/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/core/releases/tag/v3.3.1 - pagerfanta/doctrine-collections-adapter updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/doctrine-collections-adapter/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/doctrine-collections-adapter/releases/tag/v3.3.1 - pagerfanta/doctrine-orm-adapter updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/doctrine-orm-adapter/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/doctrine-orm-adapter/releases/tag/v3.3.1 - ramsey/collection updated from 1.2.1 to 1.2.2 patch See changes: https://github.com/ramsey/collection/compare/1.2.1...1.2.2 Release notes: https://github.com/ramsey/collection/releases/tag/1.2.2 - squizlabs/php_codesniffer updated from 3.6.0 to 3.6.1 patch See changes: https://github.com/squizlabs/PHP_CodeSniffer/compare/3.6.0...3.6.1 Release notes: https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.6.1 - phpstan/phpdoc-parser updated from 0.5.6 to 1.2.0 major See changes: https://github.com/phpstan/phpdoc-parser/compare/0.5.6...1.2.0 Release notes: https://github.com/phpstan/phpdoc-parser/releases/tag/1.2.0 - slevomat/coding-standard updated from 7.0.15 to 7.0.16 patch See changes: https://github.com/slevomat/coding-standard/compare/7.0.15...7.0.16 Release notes: https://github.com/slevomat/coding-standard/releases/tag/7.0.16 - egulias/email-validator updated from 3.1.1 to 3.1.2 patch See changes: https://github.com/egulias/EmailValidator/compare/3.1.1...3.1.2 Release notes: https://github.com/egulias/EmailValidator/releases/tag/3.1.2 - graham-campbell/result-type updated from v1.0.2 to v1.0.3 patch See changes: https://github.com/GrahamCampbell/Result-Type/compare/v1.0.2...v1.0.3 Release notes: https://github.com/GrahamCampbell/Result-Type/releases/tag/v1.0.3
2021-10-24 03:16:44 +02:00
/** @var int<1,max> $maxPerPage */
$maxPerPage = $this->isAuthenticated
? $perPage
: min($perPage, $this->maxPerPage);
$this->paginator->setMaxPerPage($maxPerPage);
$this->isDisabled = false;
}
public function isFromBootgrid(): bool
{
return $this->isBootgrid;
}
public function setPostprocessor(callable $postprocessor): void
{
$this->postprocessor = $postprocessor;
}
public function isDisabled(): bool
{
return $this->isDisabled;
}
public function setIsDisabled(bool $isDisabled): void
{
$this->isDisabled = $isDisabled;
}
public function getIterator(): Traversable
{
return $this->paginator->getIterator();
}
public function count(): int
{
return $this->paginator->getNbResults();
}
public function write(Response $response): ResponseInterface
{
if ($this->isDisabled) {
Dependency Update Changelogs summary: - pyrech/composer-changelogs updated from v1.8.0 to v1.8.1 patch See changes: https://github.com/pyrech/composer-changelogs/compare/v1.8.0...v1.8.1 Release notes: https://github.com/pyrech/composer-changelogs/releases/tag/v1.8.1 - james-heinrich/getid3 updated from dev-master@a440175 to dev-master@1e18087 See changes: https://github.com/JamesHeinrich/getID3/compare/a440175...1e18087 - doctrine/inflector updated from 2.0.3 to 2.0.4 patch See changes: https://github.com/doctrine/inflector/compare/2.0.3...2.0.4 Release notes: https://github.com/doctrine/inflector/releases/tag/2.0.4 - doctrine/common updated from 3.1.2 to 3.2.0 minor See changes: https://github.com/doctrine/common/compare/3.1.2...3.2.0 Release notes: https://github.com/doctrine/common/releases/tag/3.2.0 - doctrine/orm updated from 2.10.1 to 2.10.2 patch See changes: https://github.com/doctrine/orm/compare/2.10.1...2.10.2 Release notes: https://github.com/doctrine/orm/releases/tag/2.10.2 - behat/gherkin updated from v4.8.0 to v4.9.0 minor See changes: https://github.com/Behat/Gherkin/compare/v4.8.0...v4.9.0 Release notes: https://github.com/Behat/Gherkin/releases/tag/v4.9.0 - phpdocumentor/reflection-docblock updated from 5.2.2 to 5.3.0 minor See changes: https://github.com/phpDocumentor/ReflectionDocBlock/compare/5.2.2...5.3.0 Release notes: https://github.com/phpDocumentor/ReflectionDocBlock/releases/tag/5.3.0 - guzzlehttp/psr7 updated from 1.8.3 to 2.1.0 major See changes: https://github.com/guzzle/psr7/compare/1.8.3...2.1.0 Release notes: https://github.com/guzzle/psr7/releases/tag/2.1.0 - guzzlehttp/promises updated from 1.5.0 to 1.5.1 patch See changes: https://github.com/guzzle/promises/compare/1.5.0...1.5.1 Release notes: https://github.com/guzzle/promises/releases/tag/1.5.1 - guzzlehttp/guzzle updated from 7.3.0 to 7.4.0 minor See changes: https://github.com/guzzle/guzzle/compare/7.3.0...7.4.0 Release notes: https://github.com/guzzle/guzzle/releases/tag/7.4.0 - doctrine/migrations updated from 3.2.1 to 3.3.0 minor See changes: https://github.com/doctrine/migrations/compare/3.2.1...3.3.0 Release notes: https://github.com/doctrine/migrations/releases/tag/3.3.0 - gettext/gettext updated from v4.8.5 to v4.8.6 patch See changes: https://github.com/php-gettext/Gettext/compare/v4.8.5...v4.8.6 Release notes: https://github.com/php-gettext/Gettext/releases/tag/v4.8.6 - graham-campbell/guzzle-factory updated from v5.0.0 to v5.0.2 patch See changes: https://github.com/GrahamCampbell/Guzzle-Factory/compare/v5.0.0...v5.0.2 Release notes: https://github.com/GrahamCampbell/Guzzle-Factory/releases/tag/v5.0.2 - aws/aws-sdk-php updated from 3.198.0 to 3.199.2 minor See changes: https://github.com/aws/aws-sdk-php/compare/3.198.0...3.199.2 Release notes: https://github.com/aws/aws-sdk-php/releases/tag/3.199.2 - pagerfanta/core updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/core/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/core/releases/tag/v3.3.1 - pagerfanta/doctrine-collections-adapter updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/doctrine-collections-adapter/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/doctrine-collections-adapter/releases/tag/v3.3.1 - pagerfanta/doctrine-orm-adapter updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/doctrine-orm-adapter/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/doctrine-orm-adapter/releases/tag/v3.3.1 - ramsey/collection updated from 1.2.1 to 1.2.2 patch See changes: https://github.com/ramsey/collection/compare/1.2.1...1.2.2 Release notes: https://github.com/ramsey/collection/releases/tag/1.2.2 - squizlabs/php_codesniffer updated from 3.6.0 to 3.6.1 patch See changes: https://github.com/squizlabs/PHP_CodeSniffer/compare/3.6.0...3.6.1 Release notes: https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.6.1 - phpstan/phpdoc-parser updated from 0.5.6 to 1.2.0 major See changes: https://github.com/phpstan/phpdoc-parser/compare/0.5.6...1.2.0 Release notes: https://github.com/phpstan/phpdoc-parser/releases/tag/1.2.0 - slevomat/coding-standard updated from 7.0.15 to 7.0.16 patch See changes: https://github.com/slevomat/coding-standard/compare/7.0.15...7.0.16 Release notes: https://github.com/slevomat/coding-standard/releases/tag/7.0.16 - egulias/email-validator updated from 3.1.1 to 3.1.2 patch See changes: https://github.com/egulias/EmailValidator/compare/3.1.1...3.1.2 Release notes: https://github.com/egulias/EmailValidator/releases/tag/3.1.2 - graham-campbell/result-type updated from v1.0.2 to v1.0.3 patch See changes: https://github.com/GrahamCampbell/Result-Type/compare/v1.0.2...v1.0.3 Release notes: https://github.com/GrahamCampbell/Result-Type/releases/tag/v1.0.3
2021-10-24 03:16:44 +02:00
/** @var int<1,max> $maxPerPage */
$maxPerPage = PHP_INT_MAX;
$this->paginator->setCurrentPage(1);
Dependency Update Changelogs summary: - pyrech/composer-changelogs updated from v1.8.0 to v1.8.1 patch See changes: https://github.com/pyrech/composer-changelogs/compare/v1.8.0...v1.8.1 Release notes: https://github.com/pyrech/composer-changelogs/releases/tag/v1.8.1 - james-heinrich/getid3 updated from dev-master@a440175 to dev-master@1e18087 See changes: https://github.com/JamesHeinrich/getID3/compare/a440175...1e18087 - doctrine/inflector updated from 2.0.3 to 2.0.4 patch See changes: https://github.com/doctrine/inflector/compare/2.0.3...2.0.4 Release notes: https://github.com/doctrine/inflector/releases/tag/2.0.4 - doctrine/common updated from 3.1.2 to 3.2.0 minor See changes: https://github.com/doctrine/common/compare/3.1.2...3.2.0 Release notes: https://github.com/doctrine/common/releases/tag/3.2.0 - doctrine/orm updated from 2.10.1 to 2.10.2 patch See changes: https://github.com/doctrine/orm/compare/2.10.1...2.10.2 Release notes: https://github.com/doctrine/orm/releases/tag/2.10.2 - behat/gherkin updated from v4.8.0 to v4.9.0 minor See changes: https://github.com/Behat/Gherkin/compare/v4.8.0...v4.9.0 Release notes: https://github.com/Behat/Gherkin/releases/tag/v4.9.0 - phpdocumentor/reflection-docblock updated from 5.2.2 to 5.3.0 minor See changes: https://github.com/phpDocumentor/ReflectionDocBlock/compare/5.2.2...5.3.0 Release notes: https://github.com/phpDocumentor/ReflectionDocBlock/releases/tag/5.3.0 - guzzlehttp/psr7 updated from 1.8.3 to 2.1.0 major See changes: https://github.com/guzzle/psr7/compare/1.8.3...2.1.0 Release notes: https://github.com/guzzle/psr7/releases/tag/2.1.0 - guzzlehttp/promises updated from 1.5.0 to 1.5.1 patch See changes: https://github.com/guzzle/promises/compare/1.5.0...1.5.1 Release notes: https://github.com/guzzle/promises/releases/tag/1.5.1 - guzzlehttp/guzzle updated from 7.3.0 to 7.4.0 minor See changes: https://github.com/guzzle/guzzle/compare/7.3.0...7.4.0 Release notes: https://github.com/guzzle/guzzle/releases/tag/7.4.0 - doctrine/migrations updated from 3.2.1 to 3.3.0 minor See changes: https://github.com/doctrine/migrations/compare/3.2.1...3.3.0 Release notes: https://github.com/doctrine/migrations/releases/tag/3.3.0 - gettext/gettext updated from v4.8.5 to v4.8.6 patch See changes: https://github.com/php-gettext/Gettext/compare/v4.8.5...v4.8.6 Release notes: https://github.com/php-gettext/Gettext/releases/tag/v4.8.6 - graham-campbell/guzzle-factory updated from v5.0.0 to v5.0.2 patch See changes: https://github.com/GrahamCampbell/Guzzle-Factory/compare/v5.0.0...v5.0.2 Release notes: https://github.com/GrahamCampbell/Guzzle-Factory/releases/tag/v5.0.2 - aws/aws-sdk-php updated from 3.198.0 to 3.199.2 minor See changes: https://github.com/aws/aws-sdk-php/compare/3.198.0...3.199.2 Release notes: https://github.com/aws/aws-sdk-php/releases/tag/3.199.2 - pagerfanta/core updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/core/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/core/releases/tag/v3.3.1 - pagerfanta/doctrine-collections-adapter updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/doctrine-collections-adapter/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/doctrine-collections-adapter/releases/tag/v3.3.1 - pagerfanta/doctrine-orm-adapter updated from v3.3.0 to v3.3.1 patch See changes: https://github.com/Pagerfanta/doctrine-orm-adapter/compare/pagerfanta-packages:v3.3.0...Pagerfanta:v3.3.1 Release notes: https://github.com/Pagerfanta/doctrine-orm-adapter/releases/tag/v3.3.1 - ramsey/collection updated from 1.2.1 to 1.2.2 patch See changes: https://github.com/ramsey/collection/compare/1.2.1...1.2.2 Release notes: https://github.com/ramsey/collection/releases/tag/1.2.2 - squizlabs/php_codesniffer updated from 3.6.0 to 3.6.1 patch See changes: https://github.com/squizlabs/PHP_CodeSniffer/compare/3.6.0...3.6.1 Release notes: https://github.com/squizlabs/PHP_CodeSniffer/releases/tag/3.6.1 - phpstan/phpdoc-parser updated from 0.5.6 to 1.2.0 major See changes: https://github.com/phpstan/phpdoc-parser/compare/0.5.6...1.2.0 Release notes: https://github.com/phpstan/phpdoc-parser/releases/tag/1.2.0 - slevomat/coding-standard updated from 7.0.15 to 7.0.16 patch See changes: https://github.com/slevomat/coding-standard/compare/7.0.15...7.0.16 Release notes: https://github.com/slevomat/coding-standard/releases/tag/7.0.16 - egulias/email-validator updated from 3.1.1 to 3.1.2 patch See changes: https://github.com/egulias/EmailValidator/compare/3.1.1...3.1.2 Release notes: https://github.com/egulias/EmailValidator/releases/tag/3.1.2 - graham-campbell/result-type updated from v1.0.2 to v1.0.3 patch See changes: https://github.com/GrahamCampbell/Result-Type/compare/v1.0.2...v1.0.3 Release notes: https://github.com/GrahamCampbell/Result-Type/releases/tag/v1.0.3
2021-10-24 03:16:44 +02:00
$this->paginator->setMaxPerPage($maxPerPage);
}
$iterator = $this->getIterator();
$total = $this->count();
$totalPages = $this->paginator->getNbPages();
if ($this->postprocessor) {
$results = [];
$postprocessor = $this->postprocessor;
foreach ($iterator as $result) {
$results[] = $postprocessor($result, $this);
}
} else {
$results = iterator_to_array($iterator, false);
}
if ($this->isDisabled) {
return $response->withJson($results);
}
if ($this->isBootgrid) {
return $response->withJson(
[
'current' => $this->getCurrentPage(),
'rowCount' => $this->getPerPage(),
'total' => $total,
'rows' => $results,
]
);
}
$pageLinks = [];
2022-05-08 20:05:02 +02:00
$pageLinks['first'] = (string)$this->router->fromHereWithQuery(null, [], ['page' => 1]);
2022-05-08 20:05:02 +02:00
$prevPage = $this->paginator->hasPreviousPage()
? $this->paginator->getPreviousPage()
: 1;
2022-05-08 20:05:02 +02:00
$pageLinks['previous'] = (string)$this->router->fromHereWithQuery(null, [], ['page' => $prevPage]);
2022-05-08 20:05:02 +02:00
$nextPage = $this->paginator->hasNextPage()
? $this->paginator->getNextPage()
: $this->paginator->getNbPages();
2022-05-08 20:05:02 +02:00
$pageLinks['next'] = (string)$this->router->fromHereWithQuery(null, [], ['page' => $nextPage]);
2022-05-08 20:05:02 +02:00
$pageLinks['last'] = (string)$this->router->fromHereWithQuery(null, [], ['page' => $totalPages]);
return $response->withJson(
[
'page' => $this->getCurrentPage(),
'per_page' => $this->getPerPage(),
'total' => $total,
'total_pages' => $totalPages,
'links' => $pageLinks,
'rows' => $results,
]
);
}
public static function fromArray(array $input, ServerRequestInterface $request): self
{
return new self(
new Pagerfanta(new ArrayAdapter($input)),
$request
);
}
public static function fromCollection(Collection $collection, ServerRequestInterface $request): self
{
return new self(
new Pagerfanta(new CollectionAdapter($collection)),
$request,
);
}
public static function fromQueryBuilder(QueryBuilder $qb, ServerRequestInterface $request): self
{
return new self(
new Pagerfanta(new QueryAdapter($qb)),
$request
);
}
public static function fromQuery(Query $query, ServerRequestInterface $request): self
{
return new self(
new Pagerfanta(new QueryAdapter($query)),
$request
);
}
}