32bf1cb0c89bd7e46aa9c0ad70727c55fb8afd06
3 namespace app\Github\API
;
18 * @var \app\Gituhub\API
38 * Queue this call to the API client
40 abstract function enqueue(callable
$callback);
46 function __construct(API
$api, array $args = null) {
48 $this->config
= $this->api
->getConfig();
49 $this->url
= new Url($this->config
->api
->url
, null, 0);
54 if (isset($this->config
->api
->call
->{$this}->args
)) {
55 $this->args +
= $this->config
->api
->call
->{$this}->args
->toArray();
59 function __invoke(callable
$callback) {
60 if ($this->readFromCache($cached)) {
61 call_user_func_array($callback, $cached);
63 $this->enqueue($callback);
72 function __toString() {
73 $parts = explode("\\", get_class($this));
74 return strtolower(end($parts));
81 return $this->api
->getClient()->send();
85 * Get associated cache storage
86 * @param int $ttl out param of configure ttl
89 function getCache(&$ttl = null) {
90 if (isset($this->config
->storage
->cache
->{$this}->ttl
)) {
91 $ttl = $this->config
->storage
->cache
->{$this}->ttl
;
93 return $this->api
->getCacheStorage();
96 function getCacheKey() {
98 unset($args["fresh"]);
100 return sprintf("%s:%s:%s", $this->api
->getToken(), $this,
101 new QueryString($args));
104 function readFromCache(array &$cached = null, &$ttl = null) {
105 if (empty($this->args
["fresh"]) && ($cache = $this->api
->getCacheStorage())) {
106 $key = $this->getCacheKey();
107 return $cache->get($key, $cached, $ttl);
112 function saveToCache(array $fresh) {
113 if (($cache = $this->api
->getCacheStorage())) {
114 if (isset($this->config
->storage
->cache
->{$this}->ttl
)) {
115 $ttl = $this->config
->storage
->cache
->{$this}->ttl
;
120 $key = $this->getCacheKey();
121 $cache->set($key, $fresh, $ttl);
125 function dropFromCache() {
126 if (($cache = $this->api
->getCacheStorage())) {
127 $key = $this->getCacheKey();