diff options
author | Avi Goldman <avrahamymgoldman@gmail.com> | 2017-01-06 09:09:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-06 09:09:36 -0500 |
commit | f4cb5267c58cbd0b3a4bd06d22aca5c52c2ff765 (patch) | |
tree | 590ea1a6299fba349d0b720c0ac9f9309a7121dd /lib/SparkPost/SparkPostPromise.php | |
parent | c54abe82f41d7a6f1b857adf4610d82dba020426 (diff) | |
parent | 1abdc8bde168614ce055f9709de5dc788a7a46b9 (diff) | |
download | php-sparkpost-f4cb5267c58cbd0b3a4bd06d22aca5c52c2ff765.zip php-sparkpost-f4cb5267c58cbd0b3a4bd06d22aca5c52c2ff765.tar.gz php-sparkpost-f4cb5267c58cbd0b3a4bd06d22aca5c52c2ff765.tar.bz2 |
Added debug option
Added debug option
Diffstat (limited to 'lib/SparkPost/SparkPostPromise.php')
-rw-r--r-- | lib/SparkPost/SparkPostPromise.php | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/SparkPost/SparkPostPromise.php b/lib/SparkPost/SparkPostPromise.php index df715d5..b7ded0c 100644 --- a/lib/SparkPost/SparkPostPromise.php +++ b/lib/SparkPost/SparkPostPromise.php @@ -12,13 +12,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 = null) { $this->promise = $promise; + $this->request = $request; } /** @@ -29,13 +35,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 +72,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); } } } |