Total Complexity | 8 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | final class JsonBodyParser implements MiddlewareInterface |
||
13 | { |
||
14 | private bool $throwException = true; |
||
15 | |||
16 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
17 | { |
||
18 | $contentType = $request->getHeaderLine('Content-Type'); |
||
19 | |||
20 | if ($contentType && strpos(strtolower($contentType), 'application/json') !== false) { |
||
21 | $request = $request->withParsedBody( |
||
22 | $this->parse($request->getBody()->getContents()) |
||
23 | ); |
||
24 | } |
||
25 | |||
26 | return $handler->handle($request); |
||
27 | } |
||
28 | |||
29 | public function throwException(bool $value): self |
||
34 | } |
||
35 | |||
36 | private function parse(string $body): array |
||
46 | } |
||
47 | } |
||
49 |