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 / HttpFulfilledPromise.php

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

55 lines 1018 B
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 use Psr\Http\Message\ResponseInterface;
8
9 final class HttpFulfilledPromise implements Promise
10 {
11 /**
12 * @var ResponseInterface
13 */
14 private $response;
15
16 public function __construct(ResponseInterface $response)
17 {
18 $this->response = $response;
19 }
20
21 /**
22 * {@inheritdoc}
23 */
24 public function then(callable $onFulfilled = null, callable $onRejected = null)
25 {
26 if (null === $onFulfilled) {
27 return $this;
28 }
29
30 try {
31 return new self($onFulfilled($this->response));
32 } catch (Exception $e) {
33 return new HttpRejectedPromise($e);
34 }
35 }
36
37 /**
38 * {@inheritdoc}
39 */
40 public function getState()
41 {
42 return Promise::FULFILLED;
43 }
44
45 /**
46 * {@inheritdoc}
47 */
48 public function wait($unwrap = true)
49 {
50 if ($unwrap) {
51 return $this->response;
52 }
53 }
54 }
55