diff --git a/composer.json b/composer.json index e0e9cb9..78a5a2a 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": ">=5.4", - "php-http/httplug": "^1.0.0-alpha2", + "php-http/httplug": "1.0.0-alpha3", "php-http/message-factory": "^0.4@dev", "react/http-client": "^0.4.8", "react/dns": "^0.4.1", diff --git a/src/ReactHttpAdapter.php b/src/ReactHttpAdapter.php index db07dd3..567c131 100644 --- a/src/ReactHttpAdapter.php +++ b/src/ReactHttpAdapter.php @@ -9,9 +9,9 @@ use React\HttpClient\Response as ReactResponse; use Http\Client\HttpClient; use Http\Client\HttpAsyncClient; -use Http\Client\Promise; use Http\Client\Exception\HttpException; use Http\Client\Exception\RequestException; +use Http\Promise\Promise; use Http\Message\MessageFactory; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\StreamInterface; @@ -62,13 +62,8 @@ public function __construct( public function sendRequest(RequestInterface $request) { $promise = $this->sendAsyncRequest($request); - $promise->wait(); - if ($promise->getState() == Promise::REJECTED) { - throw $promise->getException(); - } - - return $promise->getResponse(); + return $promise->wait(); } /** diff --git a/src/ReactPromiseAdapter.php b/src/ReactPromiseAdapter.php index 7701aaf..70d5d0a 100644 --- a/src/ReactPromiseAdapter.php +++ b/src/ReactPromiseAdapter.php @@ -4,8 +4,8 @@ use React\EventLoop\LoopInterface; use React\Promise\PromiseInterface as ReactPromise; -use Http\Client\Promise; use Http\Client\Exception; +use Http\Promise\Promise; use Psr\Http\Message\ResponseInterface; /** @@ -91,22 +91,6 @@ public function getState() return $this->state; } - /** - * {@inheritdoc} - */ - public function getResponse() - { - return $this->response; - } - - /** - * {@inheritdoc} - */ - public function getException() - { - return $this->exception; - } - /** * Set EventLoop used for synchronous processing * @param LoopInterface $loop @@ -121,7 +105,7 @@ public function setLoop(LoopInterface $loop) /** * {@inheritdoc} */ - public function wait() + public function wait($unwrap = true) { if (null === $this->loop) { throw new \LogicException("You must set the loop before wait!"); @@ -129,5 +113,13 @@ public function wait() while (Promise::PENDING === $this->getState()) { $this->loop->tick(); } + + if ($unwrap) { + if (Promise::REJECTED == $this->getState()) { + throw $this->exception; + } + + return $this->response; + } } }