File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
lib/OpenCloud/LoadBalancer/Collection Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace OpenCloud \LoadBalancer \Collection ;
4
+
5
+ use OpenCloud \Common \Collection \PaginatedIterator ;
6
+
7
+ class LoadBalancerIterator extends PaginatedIterator
8
+ {
9
+ private $ nextElement ;
10
+
11
+ public function constructNextUrl ()
12
+ {
13
+ $ url = parent ::constructNextUrl ();
14
+
15
+ // We need to return n+1 items in order to grab the relevant marker value
16
+ $ query = $ url ->getQuery ();
17
+ $ query ['limit ' ] = $ query ['limit ' ] + 1 ;
18
+ $ url ->setQuery ($ query );
19
+
20
+ return $ url ;
21
+ }
22
+
23
+ public function updateMarkerToCurrent ()
24
+ {
25
+ $ this ->setMarkerFromElement ($ this ->nextElement );
26
+ }
27
+
28
+ public function parseResponseBody ($ body )
29
+ {
30
+ $ response = parent ::parseResponseBody ($ body );
31
+
32
+ if (count ($ response ) >= $ this ->getOption ('limit.page ' )) {
33
+ // Save last element (we will need it for the next marker)
34
+ $ this ->nextElement = end ($ response );
35
+
36
+ // Since we previously asked for n+1 elements, pop the unwanted element
37
+ array_pop ($ response );
38
+ reset ($ response );
39
+ }
40
+
41
+ return $ response ;
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments