| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Curler; |
| 4: | |
| 5: | use Psr\Http\Message\RequestInterface as PsrRequestInterface; |
| 6: | use Salient\Contract\Curler\CurlerPageInterface; |
| 7: | use OutOfRangeException; |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | class CurlerPage implements CurlerPageInterface |
| 15: | { |
| 16: | |
| 17: | protected array $Entities; |
| 18: | protected ?int $Current; |
| 19: | protected ?int $Total; |
| 20: | protected ?CurlerPageRequest $NextRequest; |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | public function __construct( |
| 35: | array $entities, |
| 36: | ?PsrRequestInterface $nextRequest = null, |
| 37: | ?array $nextQuery = null, |
| 38: | ?int $current = null, |
| 39: | ?int $total = null |
| 40: | ) { |
| 41: | $this->Entities = $entities; |
| 42: | $this->Current = $current; |
| 43: | $this->Total = $total; |
| 44: | $this->NextRequest = $nextRequest |
| 45: | ? new CurlerPageRequest($nextRequest, $nextQuery) |
| 46: | : null; |
| 47: | } |
| 48: | |
| 49: | |
| 50: | |
| 51: | |
| 52: | public function getEntities(): array |
| 53: | { |
| 54: | return $this->Entities; |
| 55: | } |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | public function hasNextRequest(): bool |
| 61: | { |
| 62: | return (bool) $this->NextRequest; |
| 63: | } |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: | public function getNextRequest() |
| 69: | { |
| 70: | if (!$this->NextRequest) { |
| 71: | throw new OutOfRangeException('No more pages'); |
| 72: | } |
| 73: | return $this->NextRequest; |
| 74: | } |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | public function getCurrent(): ?int |
| 80: | { |
| 81: | return $this->Current; |
| 82: | } |
| 83: | |
| 84: | |
| 85: | |
| 86: | |
| 87: | public function getTotal(): ?int |
| 88: | { |
| 89: | return $this->Total; |
| 90: | } |
| 91: | } |
| 92: | |