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 array |
||
33 | */ |
||
34 | protected $links = []; |
||
35 | |||
36 | public function __construct(ManagerInterface $manager, $resource, $query = []) |
||
42 | |||
43 | /** |
||
44 | * Gets the current page data. |
||
45 | * |
||
46 | * @param string $pageInfo |
||
47 | * @return ModelInterface[] |
||
48 | */ |
||
49 | public function current($pageInfo = null) |
||
61 | |||
62 | protected function extractHeaderLink(ResponseInterface $response) |
||
84 | |||
85 | /** |
||
86 | * Get the next page of data. |
||
87 | * |
||
88 | * @return ModelInterface[] |
||
89 | */ |
||
90 | public function next() |
||
98 | |||
99 | /** |
||
100 | * Checks whether has next page. |
||
101 | * |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function hasNext() |
||
108 | |||
109 | /** |
||
110 | * Gets the next page info. |
||
111 | * |
||
112 | * @return string|null |
||
113 | */ |
||
114 | public function getNextPageInfo() |
||
118 | |||
119 | /** |
||
120 | * Get the previous page of data. |
||
121 | * |
||
122 | * @return ModelInterface[] |
||
123 | */ |
||
124 | public function prev() |
||
132 | |||
133 | /** |
||
134 | * Checks whether has previous page. |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | public function hasPrev() |
||
142 | |||
143 | /** |
||
144 | * Gets the previous page info. |
||
145 | * |
||
146 | * @return string|null |
||
147 | */ |
||
148 | public function getPrevPageInfo() |
||
152 | } |