1 | <?php |
||
7 | class ResponseBuilder |
||
8 | { |
||
9 | private $dataObjectBuilder; |
||
10 | |||
11 | 20 | public function __construct(DataObjectBuilder $dataObjectBuilder = null) |
|
15 | |||
16 | 12 | public function build(ResponseInterface $httpResponse) |
|
17 | { |
||
18 | 12 | $body = $httpResponse->getBody(); |
|
19 | |||
20 | 12 | $normalizedResponse = $this->getNormalizedResponse($body); |
|
21 | |||
22 | 6 | $dataObject = array_key_exists('dataObject', $normalizedResponse) |
|
23 | 6 | ? $normalizedResponse['dataObject'] |
|
24 | 6 | : []; |
|
25 | |||
26 | 6 | return new Response( |
|
27 | 6 | $normalizedResponse['data'], |
|
28 | 6 | $normalizedResponse['errors'], |
|
29 | $dataObject |
||
30 | ); |
||
31 | } |
||
32 | |||
33 | 12 | private function getNormalizedResponse(string $body) |
|
54 | |||
55 | 12 | private function getJsonDecodedResponse(string $body) |
|
68 | } |
||
69 |