Page MenuHomePhabricator
Authored By
joshuaspence
Jul 18 2019, 10:33 PM
Size
1 KB
Referenced Files
None
Subscribers
None
<?php
final class ConduitIterator implements Iterator {
private $client;
private $method;
private $parameters;
private $current;
private $cursor;
public function __construct(ConduitClient $client, string $method, array $parameters) {
$this->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;
}
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
1718087
Default Alt Text
raw.txt (1 KB)

Event Timeline