public static function convert(ResponseInterface $response, $requestFormat, $dataType)
{
if ($requestFormat === 'json' && $dataType === 'simple_xml' || $requestFormat === 'xml' && $dataType === 'array') {
throw new InvalidArgumentException('Can not use reponse data format "%s" with the request format "%s".', $dataType, $requestFormat);
}
switch ($dataType) {
case 'array':
return self::convertToArray($response);
case 'string':
return $response->getBody()->__toString();
case 'simple_xml':
return self::convertToSimpleXml($response);
case 'stream':
return $response->getBody();
case 'psr7':
return $response;
default:
throw new InvalidArgumentException('Format "%s" is not supported', $dataType);
}
}