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: // Pop last element and save (we will need it for the next marker)
34: $this->nextElement = array_pop($response);
35: }
36:
37: return $response;
38: }
39: }
40: