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