@@ 13-32 (lines=20) @@ | ||
10 | * @package Thruster\Component\Http\Parser |
|
11 | * @author Aurimas Niekis <[email protected]> |
|
12 | */ |
|
13 | class JsonBodyParser implements ParserInterface |
|
14 | { |
|
15 | /** |
|
16 | * @inheritDoc |
|
17 | */ |
|
18 | public function parse(ServerRequestInterface $request) : ServerRequestInterface |
|
19 | { |
|
20 | if (false === strpos($request->getHeaderLine('Content-Type'), 'application/json')) { |
|
21 | return $request; |
|
22 | } |
|
23 | ||
24 | $body = $request->getBody()->getContents(); |
|
25 | ||
26 | $parsedBody = json_decode($body, true); |
|
27 | ||
28 | // TODO: Implement broken json handling |
|
29 | ||
30 | return $request->withParsedBody($parsedBody); |
|
31 | } |
|
32 | } |
|
33 |
@@ 13-30 (lines=18) @@ | ||
10 | * @package Thruster\Component\Http\Parser |
|
11 | * @author Aurimas Niekis <[email protected]> |
|
12 | */ |
|
13 | class URLEncodedBodyParser implements ParserInterface |
|
14 | { |
|
15 | /** |
|
16 | * @inheritDoc |
|
17 | */ |
|
18 | public function parse(ServerRequestInterface $request) : ServerRequestInterface |
|
19 | { |
|
20 | if (false === strpos($request->getHeaderLine('Content-Type'), 'application/x-www-form-urlencoded')) { |
|
21 | return $request; |
|
22 | } |
|
23 | ||
24 | $body = $request->getBody()->getContents(); |
|
25 | ||
26 | parse_str($body, $parsedBody); |
|
27 | ||
28 | return $request->withParsedBody($parsedBody); |
|
29 | } |
|
30 | } |
|
31 |