From 3958595e9ff27162ae918db1453ddecd4840d481 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Mon, 22 Aug 2016 15:49:38 +0200 Subject: [PATCH] compatibility with 2.6.0 and 3.1.0 --- lib/API.php | 13 ++++++++++--- lib/API/Call.php | 21 +++++++++------------ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/API.php b/lib/API.php index ba384c5..1fd3da0 100644 --- a/lib/API.php +++ b/lib/API.php @@ -3,6 +3,7 @@ namespace seekat; use Countable; +use Exception; use Generator; use http\{ Client, @@ -155,10 +156,16 @@ class API implements IteratorAggregate, Countable { } /* fetch resource, unless already localized, and try for {$method}_url */ - return $this->$method->get(...$args)->otherwise(function(Throwable $error) use($method, $args) { + return $this->$method->get(...$args)->otherwise(function($error) use($method, $args) { + if ($error instanceof Throwable) { + $message = $error->getMessage(); + } else { + $message = $error; + $error = new Exception($error); + } if ($this->exists($method."_url", $url)) { - $this->__log->info(__FUNCTION__."($method): ". $error->getMessage(), [ + $this->__log->info(__FUNCTION__."($method): ". $message, [ "url" => (string) $this->__url ]); @@ -166,7 +173,7 @@ class API implements IteratorAggregate, Countable { return $this->withUrl($url)->get(...$args); } - $this->__log->error(__FUNCTION__."($method): ". $error->getMessage(), [ + $this->__log->error(__FUNCTION__."($method): ". $message, [ "url" => (string) $this->__url ]); diff --git a/lib/API/Call.php b/lib/API/Call.php index 787f98d..26a52ee 100644 --- a/lib/API/Call.php +++ b/lib/API/Call.php @@ -56,7 +56,14 @@ class Call extends Deferred implements SplObserver }); $client->attach($this); - $client->enqueue($request); + $client->enqueue($request, function(Response $response) { + $this->response = $response; + $this->complete( + [$this, "resolve"], + [$this, "reject"] + ); + return true; + }); /* start off */ $client->once(); } @@ -76,14 +83,6 @@ class Call extends Deferred implements SplObserver } $this->notify((object) compact("client", "request", "progress")); - - if ($progress->info === "finished") { - $this->response = $this->client->getResponse(); - $this->complete( - [$this, "resolve"], - [$this, "reject"] - ); - } } /** @@ -101,10 +100,8 @@ class Call extends Deferred implements SplObserver $reject($e); } } else { - $reject($this->client->getTransferInfo($this->request)["error"]); + $reject($this->client->getTransferInfo($this->request)->error); } - - $this->client->dequeue($this->request); } /** -- 2.30.2