@@ -14,43 +14,54 @@ class ResultPaginator
14
14
15
15
protected $ pagination = null ;
16
16
17
- public function __construct ( Client $ client ) {
17
+ public function __construct ( Client $ client )
18
+ {
18
19
$ this ->client = $ client ;
19
20
}
20
21
21
- public function fetchAll ( ApiInterface $ api , $ method , $ parameters ) {
22
+ public function fetchAll ( ApiInterface $ api , $ method , $ parameters )
23
+ {
22
24
$ result = array ();
23
- $ result = call_user_func_array ( array ($ api ,$ method ), $ parameters );
25
+ $ result = call_user_func_array (array ($ api , $ method ), $ parameters );
26
+
24
27
$ this ->postFetch ();
25
28
26
29
while ($ this ->hasNext ()) {
27
30
$ result = array_merge ($ result , $ this ->fetchNext ());
28
31
}
32
+
29
33
return $ result ;
30
34
}
31
35
32
- protected function postFetch () {
36
+ protected function postFetch ()
37
+ {
33
38
$ this ->pagination = $ this ->client ->getHttpClient ()->getLastResponse ()->getPagination ();
34
- var_dump ($ this ->pagination );
35
39
}
36
40
37
- public function fetchNext () {
41
+ public function fetchNext ()
42
+ {
38
43
$ result = $ this ->client ->getHttpClient ()->get ($ this ->pagination ['next ' ]);
44
+
39
45
$ this ->postFetch ();
46
+
40
47
return $ result ->getContent ();
41
48
}
42
49
43
- public function hasNext () {
50
+ public function hasNext ()
51
+ {
44
52
if (!empty ($ this ->pagination ) and isset ($ this ->pagination ['next ' ])) {
45
53
return true ;
46
54
}
55
+
47
56
return false ;
48
57
}
49
58
50
- public function hasPrevious () {
59
+ public function hasPrevious ()
60
+ {
51
61
if (!empty ($ this ->pagination ) and isset ($ this ->pagination ['previous ' ])) {
52
62
return true ;
53
63
}
64
+
54
65
return false ;
55
66
}
56
67
0 commit comments