Total Complexity | 9 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
10 | final class JsonRequestParserMiddleware implements MiddlewareInterface |
||
11 | { |
||
12 | /** @var string[] array of regexes to check against content-types */ |
||
13 | private array $jsonContentTypes; |
||
14 | |||
15 | 6 | public function __construct(array $jsonContentTypes = null) |
|
21 | } |
||
22 | |||
23 | 5 | public function process(ServerRequestInterface $request, RequestHandlerInterface $requestHandler): ResponseInterface |
|
24 | { |
||
25 | 5 | if ($this->isJsonRequest($request->getHeaderLine('Content-Type'))) { |
|
26 | 4 | $request = $request->withParsedBody($this->parseBody($request)); |
|
27 | } |
||
28 | 4 | return $requestHandler->handle($request); |
|
29 | } |
||
30 | |||
31 | 5 | private function isJsonRequest(?string $requestContentType) : bool |
|
39 | } |
||
40 | |||
41 | 4 | private function parseBody(ServerRequestInterface $request) : array |
|
51 |