Total Complexity | 5 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
10 | final class EchoerAdapter implements Adapter |
||
11 | { |
||
12 | // 1 - key |
||
13 | // 2 - value |
||
14 | private const TEMPLATE = "\033[36m| \033[1m%s : \033[0;36m%s\033[0m\n"; |
||
15 | |||
16 | public function introspect(MessageInterface $message, array $headers): void |
||
17 | { |
||
18 | if (!$this->supports($message)) { |
||
19 | throw new UnsupportedMessage($message, ResponseInterface::class); |
||
20 | } |
||
21 | |||
22 | echo "\n"; |
||
23 | |||
24 | printf(self::TEMPLATE, 'Response status', "{$message->getStatusCode()} {$message->getReasonPhrase()}"); |
||
25 | |||
26 | foreach ($headers as $header) { |
||
27 | printf(self::TEMPLATE, "Response {$header}", $message->getHeaderLine($header)); |
||
28 | } |
||
29 | |||
30 | $body = (string) $message->getBody(); |
||
31 | |||
32 | if (!empty($body)) { |
||
33 | echo "\n{$body}"; |
||
34 | } |
||
35 | |||
36 | echo "\n"; |
||
37 | } |
||
38 | |||
39 | public function supports(MessageInterface $message): bool |
||
42 | } |
||
43 | } |
||
44 |