ea9b59a70c461e7d0837e6e650c0eaf8c408e573
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 (empty($this->args
["fresh"]) && ($cache = $this->api
->getCacheStorage())) {
61 $key = $this->getCacheKey();
63 if ($cache->get($key, $cached)) {
64 call_user_func_array($callback, $cached);
65 return $this->api
->getClient();
69 $this->enqueue($callback);
77 function __toString() {
78 $parts = explode("\\", get_class($this));
79 return strtolower(end($parts));
86 return $this->api
->getClient()->send();
90 * Get associated cache storage
91 * @param int $ttl out param of configure ttl
94 function getCache(&$ttl = null) {
95 if (isset($this->config
->storage
->cache
->{$this}->ttl
)) {
96 $ttl = $this->config
->storage
->cache
->{$this}->ttl
;
98 return $this->api
->getCacheStorage();
101 function getCacheKey() {
103 unset($args["fresh"]);
105 return sprintf("github:%s:%s:%s", $this->api
->getToken(), $this,
106 new QueryString($args));
109 function readFromCache(array &$cached = null, &$ttl = null) {
110 if (empty($this->args
["fresh"]) && ($cache = $this->api
->getCacheStorage())) {
111 $key = $this->getCacheKey();
112 return $cache->get($key, $cached, $ttl);
117 function saveToCache(array $fresh) {
118 if (($cache = $this->api
->getCacheStorage())) {
119 if (isset($this->config
->storage
->cache
->{$this}->ttl
)) {
120 $ttl = $this->config
->storage
->cache
->{$this}->ttl
;
125 $key = $this->getCacheKey();
126 $cache->set($key, $fresh, $ttl);
130 function dropFromCache() {
131 if (($cache = $this->api
->getCacheStorage())) {
132 $key = $this->getCacheKey();