diff options
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); } } } |