Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
11 / 11 |
ParseBody | |
100.00% |
1 / 1 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
11 / 11 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
process | |
100.00% |
1 / 1 |
2 | |
100.00% |
9 / 9 |
<?php | |
namespace PHPixie\HTTPProcessors\Processor; | |
class ParseBody implements \PHPixie\Processors\Processor | |
{ | |
protected $parsers; | |
public function __construct($parsers) | |
{ | |
$this->parsers = $parsers; | |
} | |
public function process($serverRequest) | |
{ | |
$contentType = $serverRequest->getHeaderLine('Content-Type'); | |
$contentType = strtolower($contentType); | |
$parser = $this->parsers->getForContentType($contentType); | |
if($parser !== null) { | |
$body = (string) $serverRequest->getBody(); | |
$parsed = $parser->parse($body); | |
$serverRequest = $serverRequest->withParsedBody($parsed); | |
} | |
return $serverRequest; | |
} | |
} |