/** * {@inheritDoc} * @throws RuntimeException */ public function buildResponse(DomainPayloadInterface $domainPayload, ResponseInterface $response) { try { $response->getBody()->rewind(); $response->getBody()->write(json_encode($domainPayload->getValues())); $headers = array_merge($this->headers, ['Content-Type' => 'application/json']); foreach ($headers as $header => $value) { $response = $response->withHeader($header, $value); } return $response->withStatus(200); } catch (Exception $e) { throw new RuntimeException('Response object could not be instantiated! ' . $e->getMessage()); } }