client = $client; $this->method = $method; $this->parameters = $parameters; } private function execute(): void { $parameters = $this->parameters; if ($this->cursor !== null) { $parameters['after'] = $this->cursor['after']; } $response = $this->client->callMethodSynchronous($this->method, $parameters); $this->current = new ArrayIterator($response['data']); $this->cursor = $response['cursor']; } private function getResults(): ArrayIterator { if ($this->current === null) { $this->execute(); } return $this->current; } /* -( Iterator )----------------------------------------------------------- */ public function current() { return $this->getResults()->current(); } public function key() { return $this->getResults()->key(); } public function next(): void { $this->getResults()->next(); } public function rewind(): void { $this->current = null; $this->cursor = null; } public function valid(): bool { $valid = $this->getResults()->valid(); if (!$valid) { if ($this->cursor['after'] === null) { return false; } $this->execute(); return true; } return $valid; } }