1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Curler; |
4: | |
5: | use Psr\Http\Message\RequestInterface; |
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: | public function __construct( |
33: | array $entities, |
34: | ?RequestInterface $nextRequest = null, |
35: | ?array $nextQuery = null, |
36: | ?int $current = null, |
37: | ?int $total = null |
38: | ) { |
39: | $this->Entities = $entities; |
40: | $this->Current = $current; |
41: | $this->Total = $total; |
42: | $this->NextRequest = $nextRequest |
43: | ? new CurlerPageRequest($nextRequest, $nextQuery) |
44: | : null; |
45: | } |
46: | |
47: | |
48: | |
49: | |
50: | public function getEntities(): array |
51: | { |
52: | return $this->Entities; |
53: | } |
54: | |
55: | |
56: | |
57: | |
58: | public function hasNextRequest(): bool |
59: | { |
60: | return (bool) $this->NextRequest; |
61: | } |
62: | |
63: | |
64: | |
65: | |
66: | public function getNextRequest() |
67: | { |
68: | if (!$this->NextRequest) { |
69: | throw new OutOfRangeException('No more pages'); |
70: | } |
71: | return $this->NextRequest; |
72: | } |
73: | |
74: | |
75: | |
76: | |
77: | public function getCurrent(): ?int |
78: | { |
79: | return $this->Current; |
80: | } |
81: | |
82: | |
83: | |
84: | |
85: | public function getTotal(): ?int |
86: | { |
87: | return $this->Total; |
88: | } |
89: | } |
90: | |