Parses the response according to its content-type header.

@throws UnexpectedValueException
@param  ResponseInterface $response
@return array
760389
protected function parseResponse(ResponseInterface $response)
    {
        $content = (string) $response->getBody();

        if(strpos($content, "callback") !== false){
            $lpos = strpos($content, "(");
            $rpos = strrpos($content, ")");
            $content  = substr($content, $lpos + 1, $rpos - $lpos -1);

            return $this->parseJson($content);
        } else if(strpos($content, "access_token=") !== false) {
            $result = array();
            parse_str($content, $result);
            return $result;
        } else {
            return parent::parseResponse($response);
        }
    }
1014376
public static function getContent(ResponseInterface $response)
    {
        $body = $response->getBody()->__toString();
        if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
            $content = json_decode($body, true);
            if (JSON_ERROR_NONE === json_last_error()) {
                return $content;
            }
        }

        return $body;
    }
689473
protected function getResponseContent(ResponseInterface $rawResponse)
    {
        // First check that content in response exists, due too bug: https://bugs.php.net/bug.php?id=54484
        $content = (string) $rawResponse->getBody();
        if (!$content) {
            return [];
        }

        $response = json_decode($content, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            parse_str($content, $response);
        }

        return $response;
    }
1076700
protected function parseResponse( Response$response ):array
	{
		$headers= $response->headers;
		$body= $this->achieveSerializer( $this->response_content_type )->decode( $response->body );

		return $this->response_transformer->transform(
			[
				'headers'=> $headers,
				'body'=> $body,
			]
		);
	}
1331579
public static function getPagination(ResponseInterface $response): ?array
    {
        if (!$response->hasHeader('Link')) {
            return null;
        }

        $header     = self::getHeader($response, 'Link');
        $pagination = [];
        foreach (explode(',', $header) as $link) {
            preg_match('/<(.*)>; rel="(.*)"/i', trim($link, ','), $match);

            if (3 === count($match)) {
                $pagination[$match[2]] = $match[1];
            }
        }

        return $pagination;
    }
96668
protected function parse_result( $response ) {
		if ( is_wp_error( $response ) ) {
			return (object) [
				'success' => false,
				'version' => false,
				'error'   => $response->get_error_code(),
				'message' => $response->get_error_message(),
			];
		} else {
			$result = json_decode( $response );
			if ( is_null( $result ) ) {
				return (object) [
					'success' => false,
					'version' => false,
					'error'   => '500',
					'message' => 'Parser Error',
				];
			} else {
				return $result;
			}
		}
	}
879326
protected function configureResponse(ResponseInterface $Response){
        $Response->setRequest($this->Request);
        $Response->extract();
        return $Response;
    }
633357
public function getParametersFromResponse(ResponseInterface $response)
    {
        $contents = $response->getBody()->getContents();

        $parameters = [];

        parse_str($contents, $parameters);

        return $parameters;
    }
5709
protected function serveHeaders(ResponseInterface $response)
    {
        header_remove('X-Powered-By');
        foreach ($response->getHeaders() as $header => $values) {
            header($header . ': ' . array_shift($values), true);
            foreach ($values as $value) {
                header($header . ': ' . $value, false);
            }
        }
    }
345645
protected function parseResponseIntoArray($response)
    {
        if (!$response->isContentType('json')) {
            parse_str($response->getBody(true), $array);

            return $array;
        }

        return $response->json();
    }
796706
public function parseReadData($data)
	{
		$results = array();

		foreach ($data as $row) {
			if (is_array($row)) {
				$key = $row[$this->keyColumn];
				$value = $row[$this->valueColumn];
			} elseif (is_object($row)) {
				$key = $row->{$this->keyColumn};
				$value = $row->{$this->valueColumn};
			} else {
				$msg = 'Expected array or object, got '.gettype($row);
				throw new \UnexpectedValueException($msg);
			}

			ArrayUtil::set($results, $key, $value);
		}

		return $results;
	}
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;
    }
618582
public function simplifyResponse($request, $response)
    {
        if (!$request instanceof Request) {
            throw new \UnexpectedValueException("Expected a Symfony2 request object.");
        }

        if (!$response instanceof Response) {
            throw new \UnexpectedValueException("Expected a Symfony2 response object.");
        }

        return new SimplifiedResponse(
            $request->getPathInfo(),
            $response->getStatusCode(),
            array_map(
                function ($value) {
                    return reset($value);
                },
                iterator_to_array($response->headers)
            ),
            $response->getContent()
        );
    }
305821
public function transform($value): array
    {
        if (null === $value) {
            return [];
        }

        if (!$value instanceof ProductVariantInterface) {
            throw new UnexpectedTypeException($value, ProductVariantInterface::class);
        }

        return array_combine(
            array_map(function (ProductOptionValueInterface $productOptionValue) {
                return $productOptionValue->getOptionCode();
            }, $value->getOptionValues()->toArray()),
            $value->getOptionValues()->toArray()
        );
    }
177678
protected function parseResponse(Response $response)
    {
        $contentType = explode(';', $response->getHeader('content-type'))[0];

        switch ($contentType) {
            case 'application/json':
            case 'application/vnd.api+json':
                return $response->json();

            case 'application/xml':
                return $response->xml();
        }

        throw new RuntimeException("Unsupported returned content-type [$contentType]");
    }
1115719
private function parseResponse(ResponseInterface $response = null): array
    {
        $body = $response
            ? (string) $response->getBody()
            : null;

        return $body
            ? guzzle_json_decode($body, true)
            : [];
    }
871800
protected function _unserializeResponseBody(ResponseInterface $response) {

		$body = (string) $response->getBody();
		$contentType = $response->getHeaderLine('Content-type');

		try {
			if(false !== stripos($contentType, $this->dataType)
				&& isset($this->unserializers[$this->dataType])) {
				/** @var UnserializerInterface $unserializer */
				$unserializer = \Yii::createObject($this->unserializers[$this->dataType]);
				if($unserializer instanceof UnserializerInterface) {
					return $unserializer->unserialize($body, false);
				}
			}

			return $body;

		} catch(InvalidParamException $e) {

			return $body;
		}
	}