PluginProbe
DecaLog / 4.4.0
DecaLog v4.4.0
3.0.2 3.1.0 3.10.0 3.2.0 3.3.0 3.4.0 3.4.1 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 3.7.1 3.8.0 3.9.0 3.9.1 4.0.0 4.1.0 4.2.0 4.3.0 4.3.1 4.4.0 4.5.0 All 75 releases
decalog / includes / libraries / http / client / Promise / HttpRejectedPromise.php

HttpRejectedPromise.php in DecaLog 4.4.0, at includes/libraries/http/client/Promise/HttpRejectedPromise.php

59 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Http\Client\Promise;
4
5 use Http\Client\Exception;
6 use Http\Promise\Promise;
7
8 final class HttpRejectedPromise implements Promise
9 {
10 /**
11 * @var Exception
12 */
13 private $exception;
14
15 public function __construct(Exception $exception)
16 {
17 $this->exception = $exception;
18 }
19
20 /**
21 * {@inheritdoc}
22 */
23 public function then(callable $onFulfilled = null, callable $onRejected = null)
24 {
25 if (null === $onRejected) {
26 return $this;
27 }
28
29 try {
30 $result = $onRejected($this->exception);
31 if ($result instanceof Promise) {
32 return $result;
33 }
34
35 return new HttpFulfilledPromise($result);
36 } catch (Exception $e) {
37 return new self($e);
38 }
39 }
40
41 /**
42 * {@inheritdoc}
43 */
44 public function getState()
45 {
46 return Promise::REJECTED;
47 }
48
49 /**
50 * {@inheritdoc}
51 */
52 public function wait($unwrap = true)
53 {
54 if ($unwrap) {
55 throw $this->exception;
56 }
57 }
58 }
59