X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fseekat;a=blobdiff_plain;f=lib%2FAPI%2FCall.php;h=a913bdaffb6c49c4f7031576342af864960a2f84;hp=ba51ca3fe23dbe2d74ef60a2b3bc9afe6974bf00;hb=HEAD;hpb=f4aa6beaf2e1f0dc9c877782cbbad5a989194517 diff --git a/lib/API/Call.php b/lib/API/Call.php index ba51ca3..a913bda 100644 --- a/lib/API/Call.php +++ b/lib/API/Call.php @@ -2,49 +2,19 @@ namespace seekat\API; -use AsyncInterop\Promise; use http\Url; use seekat\API; -use seekat\Exception; -final class Call -{ - /** - * @var API - */ - private $api; - - /** - * @var string - */ - private $call; - - function __construct(API $api, string $call) { - $this->api = $api; - $this->call = $call; +final class Call { + function __construct(private readonly API $api, private readonly string $call) { } - function __invoke(array $args) : Promise { - $promise = $this->api->{$this->call}->get(...$args); - - /* fetch resource, unless already localized, and try for {$method}_url */ - if (!$this->api->exists($this->call)) { - $promise->when(function($error, $value) use($args) { - if (!isset($error)) { - return $value; - } - if ($this->api->exists($this->call."_url", $url)) { - $url = new Url(uri_template($url, (array)current($args))); - return $this->api->withUrl($url)->get(...$args); - } - - $message = Exception\message($error); - $this->api->getLogger()->error("call($this->call): " . $message, [ - "url" => (string) $this->api->getUrl() - ]); - - throw $error; - }); + function __invoke(array $args) { + if ($this->api->exists($this->call."_url", $url)) { + $url = new Url(uri_template($url, (array) current($args))); + $promise = $this->api->withUrl($url)->get(...$args); + } else { + $promise = $this->api->{$this->call}->get(...$args); } return $promise;