compatibility with 2.6.0 and 3.1.0
authorMichael Wallner <mike@php.net>
Mon, 22 Aug 2016 13:49:38 +0000 (15:49 +0200)
committerMichael Wallner <mike@php.net>
Mon, 22 Aug 2016 13:49:38 +0000 (15:49 +0200)
lib/API.php
lib/API/Call.php

index ba384c5ad4eb0d591ebc3a1aa671099b841214b9..1fd3da011150fdfa0c3d20216b69da24a95553df 100644 (file)
@@ -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
                        ]);
 
index 787f98db3b24238654bf1a42e0d628247cdc1ed5..26a52ee0995fbff2807d3e4ab850ca97f157eea9 100644 (file)
@@ -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);
        }
 
        /**