Total Complexity | 7 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | class MnsPromise |
||
11 | { |
||
12 | private $response; |
||
13 | private $promise; |
||
14 | |||
15 | public function __construct(PromiseInterface &$promise, BaseResponse &$response) |
||
16 | { |
||
17 | $this->promise = $promise; |
||
18 | $this->response = $response; |
||
19 | } |
||
20 | |||
21 | public function isCompleted() |
||
22 | { |
||
23 | return $this->promise->getState() != 'pending'; |
||
24 | } |
||
25 | |||
26 | public function getResponse() |
||
27 | { |
||
28 | return $this->response; |
||
29 | } |
||
30 | |||
31 | public function wait() |
||
32 | { |
||
33 | try { |
||
34 | $res = $this->promise->wait(); |
||
35 | if ($res instanceof ResponseInterface) |
||
36 | { |
||
37 | $this->response->parseResponse($res->getStatusCode(), $res->getBody()); |
||
38 | } |
||
39 | } catch (TransferException $e) { |
||
40 | $message = $e->getMessage(); |
||
41 | if ($e->hasResponse()) { |
||
42 | $message = $e->getResponse()->getBody(); |
||
43 | } |
||
44 | $this->response->parseErrorResponse($e->getCode(), $message); |
||
45 | } |
||
46 | return $this->response; |
||
47 | } |
||
51 |