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