| Total Complexity | 8 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 7 | ||
| Bugs | 1 | Features | 2 |
| 1 | <?php |
||
| 13 | final class JsonBodyParser implements MiddlewareInterface |
||
| 14 | { |
||
| 15 | private bool $assoc; |
||
| 16 | private int $depth; |
||
| 17 | private int $options; |
||
| 18 | |||
| 19 | public function __construct( |
||
| 27 | } |
||
| 28 | |||
| 29 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
| 30 | { |
||
| 31 | if ($this->isJsonRequest($request)) { |
||
| 32 | $request = $request->withParsedBody( |
||
| 33 | $this->parse($request->getBody()->getContents()) |
||
| 34 | ); |
||
| 35 | } |
||
| 36 | |||
| 37 | return $handler->handle($request); |
||
| 38 | } |
||
| 39 | |||
| 40 | private function isJsonRequest(ServerRequestInterface $request): bool |
||
| 41 | { |
||
| 42 | $contentType = $request->getHeaderLine(Header::CONTENT_TYPE); |
||
| 43 | |||
| 44 | return $contentType && stripos($contentType, 'application/json') !== false; |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return array|object|null |
||
| 49 | */ |
||
| 50 | private function parse(string $rawBody) |
||
| 57 | } |
||
| 58 | } |
||
| 59 |