cerbero90 /
lazy-json-pages
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Cerbero\LazyJsonPages\Paginations; |
||
| 6 | |||
| 7 | use Cerbero\LazyJsonPages\Exceptions\InvalidPaginationException; |
||
| 8 | use Traversable; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * The user-defined pagination. |
||
| 12 | */ |
||
| 13 | class CustomPagination extends Pagination |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Determine whether this pagination matches the configuration. |
||
| 17 | */ |
||
| 18 | 48 | public function matches(): bool |
|
| 19 | { |
||
| 20 | 48 | return $this->config->pagination !== null; |
|
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Yield the paginated items. |
||
| 25 | * |
||
| 26 | * @return Traversable<int, mixed> |
||
| 27 | */ |
||
| 28 | 5 | public function getIterator(): Traversable |
|
| 29 | { |
||
| 30 | 5 | if (!is_subclass_of($this->config->pagination, Pagination::class)) { |
|
| 31 | 1 | throw new InvalidPaginationException($this->config->pagination); |
|
| 32 | } |
||
| 33 | |||
| 34 | 4 | yield from new ($this->config->pagination)($this->source, $this->client, $this->config); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 35 | } |
||
| 36 | } |
||
| 37 |