flush
[m6w6/seekat] / lib / API / Call.php
1 <?php
2
3 namespace seekat\API;
4
5 use AsyncInterop\Promise;
6 use http\Url;
7 use seekat\API;
8 use seekat\Exception;
9
10 final class Call
11 {
12 /**
13 * @var API
14 */
15 private $api;
16
17 /**
18 * @var string
19 */
20 private $call;
21
22 function __construct(API $api, string $call) {
23 $this->api = $api;
24 $this->call = $call;
25 }
26
27 function __invoke(array $args) : Promise {
28 if ($this->api->exists($this->call."_url", $url)) {
29 $url = new Url(uri_template($url, (array)current($args)));
30 $promise = $this->api->withUrl($url)->get(...$args);
31 } else {
32 $promise = $this->api->{$this->call}->get(...$args);
33 }
34
35 return $promise;
36 }
37 }