1 | <?php declare(strict_types=1); |
||
15 | class LoggerMiddleware implements MiddlewareInterface |
||
16 | { |
||
17 | const REQUEST = 'request'; |
||
18 | const RESPONSE = 'response'; |
||
19 | const ERROR = 'error'; |
||
20 | |||
21 | /** |
||
22 | * @var LoggerInterface |
||
23 | */ |
||
24 | private $logger; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $requestId; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | private $context = [ |
||
35 | self::REQUEST => [ |
||
36 | 'method' => null, |
||
37 | 'uri' => null, |
||
38 | 'protocol_version' => null, |
||
39 | 'headers' => [], |
||
40 | ], |
||
41 | self::RESPONSE => [ |
||
42 | 'status_code' => null, |
||
43 | 'status_reason' => null, |
||
44 | 'protocol_version' => null, |
||
45 | 'headers' => [], |
||
46 | ], |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * LogMiddleware constructor. |
||
51 | * @param LoggerInterface $logger |
||
52 | */ |
||
53 | public function __construct(LoggerInterface $logger) |
||
57 | |||
58 | /** |
||
59 | * @return int |
||
60 | */ |
||
61 | public function priority(): int |
||
65 | |||
66 | /** |
||
67 | * @param RequestInterface $request |
||
68 | * @param array $options |
||
69 | * @return CancellablePromiseInterface |
||
70 | */ |
||
71 | public function pre(RequestInterface $request, array $options = []): CancellablePromiseInterface |
||
87 | |||
88 | /** |
||
89 | * @param ResponseInterface $response |
||
90 | * @param array $options |
||
91 | * @return CancellablePromiseInterface |
||
92 | */ |
||
93 | public function post(ResponseInterface $response, array $options = []): CancellablePromiseInterface |
||
107 | |||
108 | /** |
||
109 | * @param Throwable $throwable |
||
110 | * @param array $options |
||
111 | * @return CancellablePromiseInterface |
||
112 | */ |
||
113 | public function error(Throwable $throwable, array $options = []): CancellablePromiseInterface |
||
138 | |||
139 | /** |
||
140 | * @param string $prefix |
||
141 | * @param array $headers |
||
142 | * @param array $ignoreHeaders |
||
143 | */ |
||
144 | protected function iterateHeaders(string $prefix, array $headers, array $ignoreHeaders) |
||
154 | |||
155 | private function addResponseToContext(ResponseInterface $response, array $options) |
||
163 | } |
||
164 |