1 | <?php |
||
12 | class CursorBasedPagination |
||
13 | { |
||
14 | const LINK_REGEX = '/<(.*page_info=([a-z0-9\-]+).*)>; rel="?{type}"?/i'; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $resource; |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $query; |
||
25 | |||
26 | /** |
||
27 | * @var ManagerInterface |
||
28 | */ |
||
29 | protected $manager; |
||
30 | |||
31 | /** |
||
32 | * @var Client |
||
33 | */ |
||
34 | protected $client; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $links = []; |
||
40 | |||
41 | public function __construct(ManagerInterface $manager, $resource, $query) |
||
48 | |||
49 | /** |
||
50 | * Gets the current page data. |
||
51 | * |
||
52 | * @return ModelInterface[] |
||
53 | */ |
||
54 | public function current() |
||
60 | |||
61 | /** |
||
62 | * Get the next page of data. |
||
63 | * |
||
64 | * @return ModelInterface[] |
||
65 | */ |
||
66 | public function next() |
||
74 | |||
75 | /** |
||
76 | * Checks whether has next page. |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | public function hasNext() |
||
84 | |||
85 | /** |
||
86 | * Get the previous page of data. |
||
87 | * |
||
88 | * @return ModelInterface[] |
||
89 | */ |
||
90 | public function prev() |
||
97 | |||
98 | /** |
||
99 | * Checks whether has previous page. |
||
100 | * |
||
101 | * @return bool |
||
102 | */ |
||
103 | public function hasPrev() |
||
107 | |||
108 | protected function fetchResource($url) |
||
118 | |||
119 | protected function extractHeaderLink(ResponseInterface $response) |
||
140 | } |