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) |
||
62 | |||
63 | protected function extractHeaderLink(ResponseInterface $response) |
||
85 | |||
86 | /** |
||
87 | * Get the next page of data. |
||
88 | * |
||
89 | * @return ModelInterface[] |
||
90 | */ |
||
91 | public function next() |
||
99 | |||
100 | /** |
||
101 | * Checks whether has next page. |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function hasNext() |
||
109 | |||
110 | /** |
||
111 | * Gets the next page info. |
||
112 | * |
||
113 | * @return string|null |
||
114 | */ |
||
115 | public function getNextPageInfo() |
||
116 | { |
||
117 | return isset($this->links['next']) ? $this->links['next'] : null; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Get the previous page of data. |
||
122 | * |
||
123 | * @return ModelInterface[] |
||
124 | */ |
||
125 | public function prev() |
||
133 | |||
134 | /** |
||
135 | * Checks whether has previous page. |
||
136 | * |
||
137 | * @return bool |
||
138 | */ |
||
139 | public function hasPrev() |
||
143 | |||
144 | /** |
||
145 | * Gets the previous page info. |
||
146 | * |
||
147 | * @return string|null |
||
148 | */ |
||
149 | public function getPrevPageInfo() |
||
153 | } |