private function read() { if (\file_exists($this->cachePath)) { print "Reading cache from {$this->cachePath}\n"; $json = JSON::decode(\file_get_contents($this->cachePath), true); $this->files = $json['files']; } else { print "Cache not found at {$this->cachePath}\n"; print "Starting with empty cache\n"; } }
/** * @param string $path * @param int|null $limit * @return array */ function get($path, $limit) { $limit = $limit === null ? PHP_INT_MAX : $limit; $result = []; $uri = new Uri($path); while ($uri && count($result) < $limit) { $response = $this->client->get($uri); $result = array_merge($result, \PureJSON\JSON::decode($response->getBody()->getContents())); $uri = null; foreach ($response->getHeader('link') as $link_) { foreach (explode(',', $link_) as $link) { list($l, $r) = explode('; ', $link, 2); if ($r === 'rel="next"') { $uri = new Uri(substr($l, 1, -1)); $uri = $uri->withScheme(null)->withHost(null); break; } } } } $result = array_slice($result, 0, $limit); return $result; }