Convert from simplified response

Converts a simplified response into the response structure you need for
your current framework.

@param SimplifiedResponse $response
@return mixed
439315
public function convertFromResponse(SimplifiedResponse $response)
    {
        return Response::create(
            $response->content,
            $response->status,
            $response->headers
        );
    }
320679
private function convertToZfResponse(ResponseInterface $response)
    {
        $zfResponse = new HttpResponse();

        $zfResponse->setStatusCode($response->getStatusCode());
        $zfResponse->setReasonPhrase($response->getReasonPhrase());
        $zfResponse->setContent((string) $response->getBody());

        foreach ($response->getHeaders() as $name => $values) {
            $zfResponse->getHeaders()->addHeaderLine($name, implode(", ", $values));
        }

        return $zfResponse;
    }
554752
protected function decodeResponse($response)
	{
		$response = json_decode($response, true);
		if (is_null($response))
		{
			throw new RuntimeException('Closure Compiler service returned invalid JSON: ' . json_last_error_msg());
		}

		if (isset($response['serverErrors'][0]))
		{
			$error = $response['serverErrors'][0];

			throw new RuntimeException('Server error ' . $error['code'] . ': ' . $error['error']);
		}

		if (isset($response['errors'][0]))
		{
			$error = $response['errors'][0];

			throw new RuntimeException('Compilation error: ' . $error['error']);
		}

		return $response['compiledCode'];
	}
505614
public function unwrapResponse(ResponseInterface $response)
    {
        $contentType = $response->getHeaderLine('Content-Type');
        $contents = $response->getBody()->getContents();

        if (false !== stripos($contentType, 'json') || stripos($contentType, 'javascript')) {
            return json_decode($contents, true);
        } elseif (false !== stripos($contentType, 'xml')) {
            return json_decode(json_encode(simplexml_load_string($contents, 'SimpleXMLElement', LIBXML_NOCDATA), JSON_UNESCAPED_UNICODE), true);
        }

        return $contents;
    }
912337
protected function _withCustomHeaders($response)
    {
        foreach ((array)$this->getConfig('headers') as $key => $value) {
            $response = $response->withHeader($key, $value);
        }

        return $response;
    }
1256160
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode'] && !empty($jsonData['result'])) {
            $messages = [];
            foreach ($jsonData['result'] as $messageData) {
                $messages[] = static::makeResponseMessage($messageData['poll_type'], $messageData);
            }

            return $messages;
        } elseif (103 == $jsonData['retcode']) {
            throw new Code103ResponseException($response);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
875518
private function wrapResponse(Response $response, $result = null, string $output = ''): Response
    {
        if ($result instanceof Response) {
            if (!empty($output) && $result->getBody()->isWritable()) {
                $result->getBody()->write($output);
            }

            return $result;
        }

        if (is_array($result) || $result instanceof \JsonSerializable) {
            $response = $this->writeJson($response, $result);
        } else {
            $response->getBody()->write($result);
        }

        //Always glue buffered output
        $response->getBody()->write($output);

        return $response;
    }
660653
protected function formatResponse($response)
    {
        if (static::FORMAT_ARRAY === $this->output) {
            $response = static::xmlToArray($response);
        } else if (static::FORMAT_JSON === $this->output) {
            $response = static::xmlToArray($response);
            $response = json_encode($response, JSON_UNESCAPED_SLASHES);
        }

        return $response;
    }
685123
public function filterResponse(SimplifiedResponse $response)
    {
        $response->headers = array_diff_key(
            $response->headers,
            array_flip($this->blacklist)
        );

        return $response;
    }
853050
public function convert(Response $response)
    {
        if ($response->type == null) {
            return;
        }

        if ($response->type == 'counter') {
            return $this->convertCounter($response);
        }

        if ($response->type == 'set') {
            return $this->convertSet($response);
        }

        if ($response->type == 'map') {
            return $this->convertMap($response);
        }

        throw new InvalidArgumentException("Unknown crdt type : {$response->type}");
    }
1332647
public function filterResponse(SimplifiedResponse $response)
    {
        if (preg_match($this->regularExpression, $response->path)) {
            $this->aggregate->filterResponse($response);
        }

        return $response;
    }
900934
public function format($response)
    {
        $this->isNew = false;
        $responseObject = new Response();
        $responseObject->setRawResponse($response);

        if ($responseObject->containsResults()) {
            $this->extractResults($response);
            $this->prepareResultSet();
            $this->prepareNodesByLabels();
            $this->prepareRelationshipsByType();
            $this->processIdentification($response);
        }

        if ($responseObject->containsRows()) {
            $rows = $this->formatRows($response);
            $responseObject->setRows($rows);

            if ($responseObject->containsResults()) {
                foreach ($responseObject->geRows() as $k => $v) {
                    if (!$this->result->hasIdentifier($k)) {
                        $this->result->addIdentifierValue($k, $v);
                    }
                }
            }
        }

        if (is_array($responseObject->geRows())) {
            $this->processTableFormat($responseObject->geRows());
        }
        $responseObject->setResult($this->result);

        $this->reset();

        return $responseObject;
    }
521741
public static function convertToSimpleXml(ResponseInterface $response)
    {
        $body = $response->getBody();
        try {
            return new \SimpleXMLElement((string) $body ?: '<root />');
        } catch (\Exception $e) {
            throw new LinkedInTransferException('Unable to parse response body into XML.');
        }
    }
190232
protected function parseResponse(Response $response)
    {
        if ($response->getStatusCode() > 199 && $response->getStatusCode() < 299) {
            if ($body = json_decode($response->getBody()->getContents(), 1)) {
                return new Collection($body);
            }
        }

        return new Collection;
    }
51419
private function parseYubicoResponse($response)
    {
        $lines = array_filter(explode("\r\n", $response));
        $responseArray = array();

        foreach ($lines as $line) {
            list($key, $value) = explode('=', $line, 2);

            $responseArray[$key] = $value;
        }

        return $responseArray;
    }
1222121
protected function parseCurlResponse($response)
    {
        $pattern = '|HTTP/\d\.\d.*?$.*?\r\n\r\n|ims';
        preg_match_all($pattern, $response, $matches);
        $header = array_pop($matches[0]);
        # Remove headers from the response body
        $body = str_replace($header, '', $response);

        return array(
            'header' => $header,
            'body' => $body,
        );
    }
549955
protected function responseWithHeaders($response)
    {
        foreach ($this->getHeaders() as $key => $value) {
            $response->headers->set($key, $value);
        }

        return $response;
    }