private parseResponse ( $response_headers, $raw_response ) : mixed | ||
$response_headers | ||
$raw_response | ||
리턴 | mixed | Provided the content-type is determined to be json or xml: Returns stdClass object when the default json decoder is used and the content-type is json. Returns SimpleXMLElement object when the default xml decoder is used and the content-type is xml. |
private function parseResponse($response_headers, $raw_response)
{
$response = $raw_response;
if (isset($response_headers['Content-Type'])) {
if (preg_match($this->jsonPattern, $response_headers['Content-Type'])) {
$json_decoder = $this->jsonDecoder;
if (is_callable($json_decoder)) {
$response = $json_decoder($response);
}
} elseif (preg_match($this->xmlPattern, $response_headers['Content-Type'])) {
$xml_decoder = $this->xmlDecoder;
if (is_callable($xml_decoder)) {
$response = $xml_decoder($response);
}
} else {
$decoder = $this->defaultDecoder;
if (is_callable($decoder)) {
$response = $decoder($response);
}
}
}
return $response;
}