1 | <?php |
||
7 | class Pagination |
||
8 | { |
||
9 | /** |
||
10 | * @var Provider |
||
11 | */ |
||
12 | private $provider; |
||
13 | |||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $bookmarks = []; |
||
18 | |||
19 | public function __construct(Provider $provider) |
||
23 | |||
24 | /** |
||
25 | * Iterate through results of Api function call. By |
||
26 | * default generator will return all pagination results. |
||
27 | * To limit result batches, set $batchesLimit. Call function |
||
28 | * of object to get data. |
||
29 | * |
||
30 | * @param array $params |
||
31 | * @param int $batchesLimit |
||
32 | * |
||
33 | * @return \Iterator |
||
34 | */ |
||
35 | public function getPaginatedData($method, $params, $batchesLimit = 0) |
||
53 | |||
54 | protected function callProviderRequest($method, array $params) |
||
66 | |||
67 | protected function getDataFromPaginatedResponse($response) |
||
77 | |||
78 | /** |
||
79 | * @param array $response |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | protected function responseHasData($response) |
||
87 | |||
88 | /** |
||
89 | * Check if we get batches limit in pagination. |
||
90 | * |
||
91 | * @param int $batchesLimit |
||
92 | * @param int $batchesNum |
||
93 | * |
||
94 | * @return bool |
||
95 | */ |
||
96 | protected function reachBatchesLimit($batchesLimit, $batchesNum) |
||
100 | |||
101 | /** |
||
102 | * Remove 'module' data from response. |
||
103 | * |
||
104 | * @param array $response |
||
105 | * |
||
106 | * @return array mixed |
||
107 | */ |
||
108 | protected function clearResponseFromMetaData($response) |
||
116 | |||
117 | /** |
||
118 | * @param $response |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | protected function getBookMarks($response) |
||
128 | |||
129 | protected function checkEndBookMarks() |
||
133 | } |
||
134 |