api = $api; $this->config = $this->api->getConfig(); $this->url = new Url($this->config->api->url, null, 0); if ($args) { $this->args = $args; } if (isset($this->config->api->call->{$this}->args)) { $this->args += $this->config->api->call->{$this}->args->toArray(); } } function __invoke(callable $callback) { if (empty($this->args["fresh"]) && ($cache = $this->api->getCacheStorage())) { $key = $this->getCacheKey(); if ($cache->get($key, $cached)) { call_user_func_array($callback, $cached); return $this->api->getClient(); } } $this->enqueue($callback); return $this->api->getClient(); } /** * Get type of call * @return string */ function __toString() { $parts = explode("\\", get_class($this)); return strtolower(end($parts)); } /** * Get associated cache storage * @param int $ttl out param of configure ttl * @return Storage */ function getCache(&$ttl = null) { if (isset($this->config->storage->cache->{$this}->ttl)) { $ttl = $this->config->storage->cache->{$this}->ttl; } return $this->api->getCacheStorage(); } function getCacheKey() { return sprintf("github:%s:%s:%s", $this->api->getToken(), $this, new QueryString($this->args)); } function readFromCache(array &$cached = null, &$ttl = null) { if (empty($this->args["fresh"]) && ($cache = $this->api->getCacheStorage())) { $key = $this->getCacheKey(); return $cache->get($key, $cached, $ttl); } return false; } function saveToCache(array $fresh) { if (($cache = $this->api->getCacheStorage())) { if (isset($this->config->storage->cache->{$this}->ttl)) { $ttl = $this->config->storage->cache->{$this}->ttl; } else { $ttl = 0; } $key = $this->getCacheKey(); $cache->set($key, $fresh, $ttl); } } }