Total Complexity | 6 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
10 | final class SapiEmitter implements EmitterInterface |
||
11 | { |
||
12 | private $withoutBody = false; |
||
13 | |||
14 | public function emit(ResponseInterface $response): bool |
||
15 | { |
||
16 | $status = $response->getStatusCode(); |
||
17 | |||
18 | foreach ($response->getHeaders() as $header => $values) { |
||
19 | foreach ($values as $value) { |
||
20 | header(sprintf( |
||
21 | '%s: %s', |
||
22 | $header, |
||
23 | $value |
||
24 | ), $header !== 'Set-Cookie', $status); |
||
25 | } |
||
26 | } |
||
27 | |||
28 | $reason = $response->getReasonPhrase(); |
||
29 | $status = $response->getStatusCode(); |
||
30 | |||
31 | header(sprintf( |
||
32 | 'HTTP/%s %d%s', |
||
33 | $response->getProtocolVersion(), |
||
34 | $status, |
||
35 | ($reason !== '' ? ' ' . $reason : '') |
||
36 | ), true, $status); |
||
37 | |||
38 | if (!$this->withoutBody) { |
||
39 | echo $response->getBody(); |
||
40 | } |
||
41 | |||
42 | return true; |
||
43 | } |
||
44 | |||
45 | public function withoutBody(): EmitterInterface |
||
50 | } |
||
51 | } |
||
52 |