Create response from http response.

@param \GuzzleHttp\Psr7\Response $httpResponse
@return \Niddit\Google\Maps\Service\Places\PlaceDetailsResponse
490580
public static function fromResponse(Response $httpResponse)
    {
        $content = json_decode($httpResponse->getBody()->getContents(), true);

        $status = isset($content['status']) ? $content['status'] : '';

        if($status == Status::OK) {
            $htmlAttributes = isset($content['html_attributes']) ? $content['html_attributes'] : [];

            $result = isset($content['result']) ? $content['result'] : [];
            $result = PlaceDetailsResult::fromArray($result);
            $errorMessage = null;
        }

        else {
            $errorMessage = isset($content['error_message']) ? $content['error_message'] : null;
            $htmlAttributes = [];
            $result = null;
        }

        return new static($httpResponse, $status, $result, $htmlAttributes, $errorMessage);
    }
1276468
public function index(): HTTPResponse
    {
        $body = null;
        $contentType = $this->getRequest()->getHeader('Content-Type');

        if ($contentType === 'application/json') {
            $body = json_decode($this->getRequest()->getBody(), true);
        } else {
            $body = $this->getRequest()->postVars();
        }

        if (empty($body)) {
            return $this->getErrorResponse(
                'No parameters could be found in request body. Did you correctly set the Content-Type header?',
                500
            );
        }

        // request needs parsed body
        $psrRequest = (new HttpRequestAdapter())->toPsr7($this->getRequest())
            ->withParsedBody($body);
        $psrResponse = new Response();

        $authServer = $this->serverGenerator->getServer();

        try {
            return (new HttpResponseAdapter())
                ->fromPsr7($authServer->respondToAccessTokenRequest($psrRequest, $psrResponse));
        } catch (OAuthServerException $e) {
            return $this->convertResponse($e->generateHttpResponse(new Response()));
        } catch (Exception $e) {
            return $this->getErrorResponse($e->getMessage());
        }
    }
1002079
protected function createPsr7Response(Response $response)
    {
        return new PsrResponse(
            $response->getStatusCode(),
            $response->headers->all(),
            $response->getContent(),
            $response->getProtocolVersion()
        );
    }
264419
public function createResponse()
    {
        if (empty($this->headers)) {
            throw new \RuntimeException('No headers have been received');
        }

        // HTTP-version SP status-code SP reason-phrase
        $startLine = explode(' ', array_shift($this->headers), 3);
        $headers = \GuzzleHttp\headers_from_lines($this->headers);
        $normalizedKeys = \GuzzleHttp\normalize_header_keys($headers);

        if (!empty($this->options['decode_content'])
            && isset($normalizedKeys['content-encoding'])
        ) {
            $headers['x-encoded-content-encoding']
                = $headers[$normalizedKeys['content-encoding']];
            unset($headers[$normalizedKeys['content-encoding']]);
            if (isset($normalizedKeys['content-length'])) {
                $headers['x-encoded-content-length']
                    = $headers[$normalizedKeys['content-length']];

                $bodyLength = (int) $this->sink->getSize();
                if ($bodyLength) {
                    $headers[$normalizedKeys['content-length']] = $bodyLength;
                } else {
                    unset($headers[$normalizedKeys['content-length']]);
                }
            }
        }

        // Attach a response to the easy handle with the parsed headers.
        $this->response = new Response(
            $startLine[1],
            $headers,
            $this->sink,
            substr($startLine[0], 5),
            isset($startLine[2]) ? (string) $startLine[2] : null
        );
    }
1030211
protected function createResponse($rawResponse)
    {
        $response = new Response();

        $headerSize = curl_getinfo($this->handle, CURLINFO_HEADER_SIZE);
        $rawHeaders = trim(substr($rawResponse, 0, $headerSize));
        $rawHeadersArray = explode("\r\n\r\n", $rawHeaders);

        if (!empty($rawHeadersArray)) {
            $headerLines = explode("\r\n", $rawHeadersArray[0]);
            foreach ($headerLines as $headerLine) {
                if (stripos(trim($headerLine), 'http', 0) === 0) {
                    if (preg_match('/^http\/((\d*[.])?\d+)\s+(\d+)\s+([a-z]+)/i', trim($headerLine), $matches)) {
                        $response = $response->withStatus($matches[3], $matches[4])
                            ->withProtocolVersion($matches[1]);
                    }
                    continue;
                }

                $header = explode(':', $headerLine, 2);
                $name = trim($header[0]);
                $value = trim($header[1]);

                if ($response->hasHeader($name)) {
                    $response = $response->withAddedHeader($name, $value);
                } else {
                    $response = $response->withHeader($name, $value);
                }
            }
        }

        $content = substr($rawResponse, $headerSize);
        $response->getBody()->write($content);
        $response->getBody()->rewind();

        return $response;
    }
56019
private function postProcessing(JsonResponse $response) {
		$apiUrl = $this->getServiceContainer()->getPreferenceLoader()->getSystemPreferences()->getApiUrl();
		$response->setContent(str_replace('%apiurl%', $apiUrl, $response->getContent()));
		return $response;
	}
448327
public static function create(array $parsedResponse)
    {
        $result = new self();
        $result->setVersion($parsedResponse['Version']);
        $result->setEnabled(Utilities::toBoolean($parsedResponse['Enabled']));
        if ($result->getEnabled()) {
            $result->setIncludeAPIs(
                Utilities::toBoolean($parsedResponse['IncludeAPIs'])
            );
        }
        $result->setRetentionPolicy(
            RetentionPolicy::create($parsedResponse['RetentionPolicy'])
        );

        return $result;
    }
1033078
public function createResponse($statusCode, array $headers = [], array $options = [])
    {
        $body = JsonRpc\json_encode($options);

        return new Response($statusCode, $headers, $body === false ? null : $body);
    }
329272
public function applyResponse(HttpRequestInterface $request, HttpResponseInterface $response, array $options)
    {
        return $this->factory->fromResponse($response);
    }
301231
public function setFromResponseObj(HttpResponse $response)
    {
        if ($response->isSuccess()) {
            $body = json_decode($response->getBody(), true);
            $this->setStatus((bool) isset($body['success']) ? $body['success'] : false);
        } else {
            $this->setError($response->getReasonPhrase());
        }

        return $this;
    }
657555
public function setResponse(JsonResponse $response)
    {
        $this->response = $response;

        if (!$response->getRequest()) {
            $response->setRequest($this);
        }

        return $this;
    }
427977
protected function createResponse($response, Exception $e)
    {
        $response = new HttpResponse($response->getContent(), $response->getStatusCode(), $response->headers->all());

        return $response->withException($e);
    }
1315676
public function postRequest(HTTPRequest $request, HTTPResponse $response = null)
    {
        if ($response &&
            preg_match('/text\/html/', $response->getHeader('Content-Type')) &&
            !preg_match('/^(admin|dev)\//', $request->getURL())
        ) {
            $response->setBody(
                $this->obfuscateEmails($response->getBody())
            );
        }
    }
964132
public static function makeFromJson(JsonResponse $json)
    {
        $content = $json->getContent();

        // If the contents of the JsonResponse does not starts with /**/ (typical laravel jsonp response)
        // we assume that it is a valid json response that can be decoded, or we just use the raw jsonp
        // contents for building the response
        if (! Str::startsWith($json->getContent(), '/**/')) {
            $content = \json_decode($json->getContent(), true);
        }

        $new = static::create($content, $json->getStatusCode());

        $new->headers = $json->headers;

        return $new;
    }
1374391
public function response($data = [], $status = Response::HTTP_OK, $headers = [])
    {
        return new JsonResponse($data, $status, $headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    }
365877
public function createResponse()
    {
        $response = $this->format();
        $response->headers->set('content-type', $this->getContentType());
        $response->setStatusCode($this->getStatusCode());
        $response->setCharset('UTF-8');

        return $response;
    }
1020222
public static function create($curlResponse, $headerSize) { 
        $headers = substr($curlResponse, 0, $headerSize);
        
        return function_exists('http_parse_headers') ? http_parse_headers($headers) : HTTPHeadersParser::parse($headers);
    }