update to PHP-8.1
[m6w6/seekat] / lib / API / Call.php
index d84a24c673f71e438d2a5bb60cb14fceb28124aa..a913bdaffb6c49c4f7031576342af864960a2f84 100644 (file)
@@ -3,45 +3,18 @@
 namespace seekat\API;
 
 use http\Url;
-use React\Promise\ExtendedPromiseInterface;
 use seekat\API;
-use seekat\Exception;
 
-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) : ExtendedPromiseInterface {
-               $promise = $this->api->{$this->call}->get(...$args);
-
-               /* fetch resource, unless already localized, and try for {$method}_url */
-               if (!$this->api->exists($this->call)) {
-                       $promise = $promise->otherwise(function ($error) use($args) {
-                               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;