summaryrefslogtreecommitdiff
path: root/inc/mailgun/php-http/httplug/src/Promise/HttpRejectedPromise.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/mailgun/php-http/httplug/src/Promise/HttpRejectedPromise.php')
-rw-r--r--inc/mailgun/php-http/httplug/src/Promise/HttpRejectedPromise.php56
1 files changed, 56 insertions, 0 deletions
diff --git a/inc/mailgun/php-http/httplug/src/Promise/HttpRejectedPromise.php b/inc/mailgun/php-http/httplug/src/Promise/HttpRejectedPromise.php
new file mode 100644
index 0000000..bfb0738
--- /dev/null
+++ b/inc/mailgun/php-http/httplug/src/Promise/HttpRejectedPromise.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Http\Client\Promise;
+
+use Http\Client\Exception;
+use Http\Promise\Promise;
+
+final class HttpRejectedPromise implements Promise
+{
+ /**
+ * @var Exception
+ */
+ private $exception;
+
+ /**
+ * @param Exception $exception
+ */
+ public function __construct(Exception $exception)
+ {
+ $this->exception = $exception;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function then(callable $onFulfilled = null, callable $onRejected = null)
+ {
+ if (null === $onRejected) {
+ return $this;
+ }
+
+ try {
+ return new HttpFulfilledPromise($onRejected($this->exception));
+ } catch (Exception $e) {
+ return new self($e);
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getState()
+ {
+ return Promise::REJECTED;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function wait($unwrap = true)
+ {
+ if ($unwrap) {
+ throw $this->exception;
+ }
+ }
+}