1 | <?php |
||
30 | class Paginator extends Nette\Object implements \Iterator |
||
31 | { |
||
32 | const PER_PAGE_MAX = 100; |
||
33 | |||
34 | /** |
||
35 | * @var ApiCall |
||
36 | */ |
||
37 | private $client; |
||
38 | |||
39 | /** |
||
40 | * @var IPub\OAuth\HttpClient |
||
41 | */ |
||
42 | private $httpClient; |
||
43 | |||
44 | /** |
||
45 | * @var int |
||
46 | */ |
||
47 | private $firstPage; |
||
48 | |||
49 | /** |
||
50 | * @var int |
||
51 | */ |
||
52 | private $perPage; |
||
53 | |||
54 | /** |
||
55 | * @var int|NULL |
||
56 | */ |
||
57 | private $maxResults; |
||
58 | |||
59 | /** |
||
60 | * @var array |
||
61 | */ |
||
62 | private $resources = []; |
||
63 | |||
64 | /** |
||
65 | * @var IPub\OAuth\Api\Response[] |
||
66 | */ |
||
67 | private $responses = []; |
||
68 | |||
69 | /** |
||
70 | * @var int |
||
71 | */ |
||
72 | private $itemCursor; |
||
73 | |||
74 | /** |
||
75 | * @var int |
||
76 | */ |
||
77 | private $pageCursor; |
||
78 | |||
79 | /** |
||
80 | * @param ApiCall $client |
||
81 | * @param IPub\OAuth\Api\Response $response |
||
82 | */ |
||
83 | public function __construct(ApiCall $client, IPub\OAuth\Api\Response $response) |
||
98 | |||
99 | /** |
||
100 | * If you setup maximum number of results, the pagination will stop after fetching the desired number. |
||
101 | * If you have per_page=50 and wan't to fetch 200 results, it will make 4 requests in total. |
||
102 | * |
||
103 | * @param int $maxResults |
||
104 | * |
||
105 | * @return $this |
||
106 | */ |
||
107 | public function limitResults($maxResults) |
||
113 | |||
114 | public function rewind() |
||
119 | |||
120 | public function valid() |
||
125 | |||
126 | /** |
||
127 | * @return bool |
||
128 | */ |
||
129 | public function loadedMaxResults() |
||
137 | |||
138 | public function current() |
||
146 | |||
147 | public function next() |
||
190 | |||
191 | public function key() |
||
195 | |||
196 | /** |
||
197 | * @param array $response |
||
198 | * |
||
199 | * @return array |
||
200 | */ |
||
201 | private function findCollection(array $response) |
||
209 | } |