diff options
author | Avi Goldman <avrahamymgoldman@gmail.com> | 2017-01-04 09:15:43 -0500 |
---|---|---|
committer | Avi Goldman <avrahamymgoldman@gmail.com> | 2017-01-04 09:15:43 -0500 |
commit | ac95fe18ba4f58d713e2f04c6b0807b63947dd89 (patch) | |
tree | a4667c1fcdb20740a7e1ca3116636a2660517d8a | |
parent | 264fa95625382ee546465e892b2b9bb5b5090d24 (diff) | |
download | php-sparkpost-ac95fe18ba4f58d713e2f04c6b0807b63947dd89.zip php-sparkpost-ac95fe18ba4f58d713e2f04c6b0807b63947dd89.tar.gz php-sparkpost-ac95fe18ba4f58d713e2f04c6b0807b63947dd89.tar.bz2 |
pass request through to response or error
-rw-r--r-- | lib/SparkPost/SparkPostPromise.php | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/SparkPost/SparkPostPromise.php b/lib/SparkPost/SparkPostPromise.php index df715d5..42187ca 100644 --- a/lib/SparkPost/SparkPostPromise.php +++ b/lib/SparkPost/SparkPostPromise.php @@ -3,6 +3,7 @@ namespace SparkPost; use Http\Promise\Promise as HttpPromise; +use Psr\Http\Message\RequestInterface as RequestInterface; class SparkPostPromise implements HttpPromise { @@ -12,13 +13,19 @@ class SparkPostPromise implements HttpPromise private $promise; /** + * Array with the request values sent + */ + private $request; + + /** * set the promise to be wrapped. * * @param HttpPromise $promise */ - public function __construct(HttpPromise $promise) + public function __construct(HttpPromise $promise, $request) { $this->promise = $promise; + $this->request = $request; } /** @@ -29,13 +36,15 @@ class SparkPostPromise implements HttpPromise */ public function then(callable $onFulfilled = null, callable $onRejected = null) { - return $this->promise->then(function ($response) use ($onFulfilled) { + $request = $this->request; + + return $this->promise->then(function ($response) use ($onFulfilled, $request) { if (isset($onFulfilled)) { - $onFulfilled(new SparkPostResponse($response)); + $onFulfilled(new SparkPostResponse($response, $request)); } - }, function ($exception) use ($onRejected) { + }, function ($exception) use ($onRejected, $request) { if (isset($onRejected)) { - $onRejected(new SparkPostException($exception)); + $onRejected(new SparkPostException($exception, $request)); } }); } @@ -64,9 +73,9 @@ class SparkPostPromise implements HttpPromise try { $response = $this->promise->wait($unwrap); - return $response ? new SparkPostResponse($response) : $response; + return $response ? new SparkPostResponse($response, $this->request) : $response; } catch (\Exception $exception) { - throw new SparkPostException($exception); + throw new SparkPostException($exception, $this->request); } } } |