8b0f62fd726d67ca30f4c6dcbacfc57469d55d41
[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 /**
11 * @var API
12 */
13 private $api;
14
15 /**
16 * @var string
17 */
18 private $call;
19
20 function __construct(API $api, string $call) {
21 $this->api = $api;
22 $this->call = $call;
23 }
24
25 function __invoke(array $args) {
26 if ($this->api->exists($this->call."_url", $url)) {
27 $url = new Url(uri_template($url, (array)current($args)));
28 $promise = $this->api->withUrl($url)->get(...$args);
29 } else {
30 $promise = $this->api->{$this->call}->get(...$args);
31 }
32
33 return $promise;
34 }
35 }