Skip to content

Commit

Permalink
Implement total pages aware pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed Jan 11, 2024
1 parent 359f3a8 commit 63900f4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Paginations/TotalPagesAwarePagination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Cerbero\LazyJsonPages\Paginations;

use Cerbero\LazyJsonPages\Concerns\PaginationLengthAware;
use Traversable;

/**
* The pagination aware of the total number of pages.
*/
class TotalPagesAwarePagination extends Pagination
{
use PaginationLengthAware;

/**
* Determine whether the configuration matches this pagination.
*/
public function matches(): bool
{
return $this->config->totalPages !== null
&& $this->config->perPage === null;
}

/**
* Yield the paginated items.
*
* @return Traversable<string|int, mixed>
*/
public function getIterator(): Traversable
{
yield from $this->itemsByTotalPages($this->config->totalPages);

Check failure on line 33 in src/Paginations/TotalPagesAwarePagination.php

View workflow job for this annotation

GitHub Actions / Linting

Parameter #1 $pages of method Cerbero\LazyJsonPages\Paginations\TotalPagesAwarePagination::itemsByTotalPages() expects int, int|null given.
}
}

0 comments on commit 63900f4

Please sign in to comment.