@@ -56,6 +56,11 @@ class HttpClient implements HttpClientInterface
56
56
*/
57
57
protected $ browser ;
58
58
59
+ /**
60
+ * @var array
61
+ */
62
+ private $ lastResponse ;
63
+
59
64
/**
60
65
* Instantiated a new http client
61
66
*
@@ -101,6 +106,18 @@ public function setOption($name, $value)
101
106
return $ this ;
102
107
}
103
108
109
+ /**
110
+ * @return null|array
111
+ */
112
+ public function getPagination ()
113
+ {
114
+ if (null === $ this ->lastResponse ) {
115
+ return null ;
116
+ }
117
+
118
+ return $ this ->lastResponse ['pagination ' ];
119
+ }
120
+
104
121
/**
105
122
* {@inheritDoc}
106
123
*/
@@ -162,9 +179,9 @@ public function request($path, array $parameters = array(), $httpMethod = 'GET',
162
179
));
163
180
164
181
// get encoded response
165
- $ response = $ this ->doRequest ($ url , $ parameters , $ httpMethod , $ options );
182
+ $ this -> lastResponse = $ this ->doRequest ($ url , $ parameters , $ httpMethod , $ options );
166
183
167
- return $ this ->decodeResponse ($ response ['response ' ]);
184
+ return $ this ->decodeResponse ($ this -> lastResponse ['response ' ]);
168
185
}
169
186
170
187
/**
@@ -186,11 +203,36 @@ protected function doRequest($url, array $parameters = array(), $httpMethod = 'G
186
203
return array (
187
204
'response ' => $ response ->getContent (),
188
205
'headers ' => $ response ->getHeaders (),
206
+ 'pagination ' => $ this ->decodePagination ($ response ),
189
207
'errorNumber ' => '' ,
190
208
'errorMessage ' => ''
191
209
);
192
210
}
193
211
212
+ /**
213
+ * @param MessageInterface $response
214
+ *
215
+ * @return array|null
216
+ */
217
+ protected function decodePagination (MessageInterface $ response )
218
+ {
219
+ $ header = $ response ->getHeader ('Link ' );
220
+ if (empty ($ header )) {
221
+ return null ;
222
+ }
223
+
224
+ $ pagination = array ();
225
+ foreach (explode ("\n" , $ header ) as $ link ) {
226
+ preg_match ('/<(.*)>; rel="(.*)"/i ' , trim ($ link , ', ' ), $ match );
227
+
228
+ if (3 === count ($ match )) {
229
+ $ pagination [$ match [2 ]] = $ match [1 ];
230
+ }
231
+ }
232
+
233
+ return $ pagination ;
234
+ }
235
+
194
236
/**
195
237
* {@inheritDoc}
196
238
*/
0 commit comments