private function write() { print "Writing cache to {$this->cachePath}\n"; \file_put_contents($this->cachePath, JSON::encode(array('files' => $this->files), true, true)); }
/** * @return string */ function json_last_error_msg() { return \PureJSON\JSON::getErrorMessage(json_last_error()); }
/** * @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; }