1 | <?php |
||
9 | class Stream |
||
10 | { |
||
11 | /** @var string */ |
||
12 | const STATUS_FULFILLED = 'FULFILLED'; |
||
13 | |||
14 | /** @var string */ |
||
15 | const STATUS_REJECTED = 'REJECTED'; |
||
16 | |||
17 | /** @var string */ |
||
18 | const STATUS_TIMEOUT = 'TIMEOUT'; |
||
19 | |||
20 | /** @var string */ |
||
21 | const STATUS_PENDING = 'PENDING'; |
||
22 | |||
23 | /** @var ResponseInterface */ |
||
24 | protected $response; |
||
25 | |||
26 | /** @var ChunkInterface */ |
||
27 | protected $chunk; |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $status = self::STATUS_PENDING; |
||
31 | |||
32 | /** @var TransportExceptionInterface */ |
||
33 | protected $exception; |
||
34 | |||
35 | /** |
||
36 | * @param ResponseInterface $response |
||
37 | * @param ChunkInterface $chunk |
||
38 | * |
||
39 | * @return Stream |
||
40 | */ |
||
41 | public static function from(ResponseInterface $response, ChunkInterface $chunk) |
||
45 | |||
46 | /** |
||
47 | * @param ResponseInterface $response |
||
48 | * @param ChunkInterface $chunk |
||
49 | */ |
||
50 | public function __construct(ResponseInterface $response, ChunkInterface $chunk) |
||
57 | |||
58 | protected function detectStatus(): void |
||
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | protected function getStatus() |
||
82 | |||
83 | /** |
||
84 | * @param string $status |
||
85 | * |
||
86 | * @return $this |
||
87 | */ |
||
88 | protected function setStatus(string $status) |
||
94 | |||
95 | /** |
||
96 | * @return bool |
||
97 | */ |
||
98 | protected function isPending(): bool |
||
102 | |||
103 | /** |
||
104 | * @return bool |
||
105 | */ |
||
106 | protected function isFulfilled(): bool |
||
110 | |||
111 | /** |
||
112 | * @return bool |
||
113 | */ |
||
114 | protected function isTimeout(): bool |
||
118 | |||
119 | /** |
||
120 | * @return bool |
||
121 | */ |
||
122 | protected function isRejected(): bool |
||
126 | |||
127 | /** |
||
128 | * @param callable $callback |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function then(callable $callback): self |
||
140 | |||
141 | /** |
||
142 | * @param callable $callback |
||
143 | * |
||
144 | * @return $this |
||
145 | */ |
||
146 | public function timeout(callable $callback): self |
||
154 | |||
155 | /** |
||
156 | * @param callable $callback |
||
157 | * |
||
158 | * @return $this |
||
159 | */ |
||
160 | public function catch(callable $callback): self |
||
168 | |||
169 | /** |
||
170 | * @return Response |
||
171 | */ |
||
172 | protected function response(): Response |
||
176 | } |
||
177 |