Total Complexity | 6 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
11 | final class EchoerAdapter implements Adapter |
||
12 | { |
||
13 | // 1 - key |
||
14 | // 2 - value |
||
15 | private const TEMPLATE = "\033[36m| \033[1m%s : \033[0;36m%s\033[0m\n"; |
||
16 | |||
17 | /** @var iterable<string> */ |
||
18 | private $headers; |
||
19 | |||
20 | /** @param iterable<string> $headers */ |
||
21 | public function __construct(iterable $headers) |
||
24 | } |
||
25 | |||
26 | public function introspect(MessageInterface $message): void |
||
27 | { |
||
28 | if (!$this->supports($message)) { |
||
29 | throw new UnsupportedMessage($message, RequestInterface::class); |
||
30 | } |
||
31 | |||
32 | assert($message instanceof RequestInterface); |
||
33 | |||
34 | echo "\n"; |
||
35 | |||
36 | printf(self::TEMPLATE, 'Request', "{$message->getMethod()} {$message->getUri()}"); |
||
37 | |||
38 | foreach ($this->headers as $header) { |
||
39 | printf(self::TEMPLATE, "Request {$header}", $message->getHeaderLine($header)); |
||
40 | } |
||
41 | |||
42 | $body = (string) $message->getBody(); |
||
43 | |||
44 | if (!empty($body)) { |
||
45 | echo "\n{$body}"; |
||
46 | } |
||
47 | |||
48 | echo "\n"; |
||
49 | } |
||
50 | |||
51 | public function supports(MessageInterface $message): bool |
||
54 | } |
||
55 | } |
||
56 |