diff options
author | Andrew Dolgov <[email protected]> | 2022-11-23 21:14:33 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2022-11-23 21:14:33 +0300 |
commit | 0c8af4992cb0f7589dcafaad65ada12753c64594 (patch) | |
tree | 18e83d068c3e7dd2499331de977782b382279396 /vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php |
initial
Diffstat (limited to 'vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php')
-rw-r--r-- | vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php b/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php new file mode 100644 index 0000000..43d3d56 --- /dev/null +++ b/vendor/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php @@ -0,0 +1,61 @@ +<?php +namespace Aws\Api\Parser; + +use Aws\Api\Parser\Exception\ParserException; +use Psr\Http\Message\ResponseInterface; + +trait PayloadParserTrait +{ + /** + * @param string $json + * + * @throws ParserException + * + * @return array + */ + private function parseJson($json, $response) + { + $jsonPayload = json_decode($json, true); + + if (JSON_ERROR_NONE !== json_last_error()) { + throw new ParserException( + 'Error parsing JSON: ' . json_last_error_msg(), + 0, + null, + ['response' => $response] + ); + } + + return $jsonPayload; + } + + /** + * @param string $xml + * + * @throws ParserException + * + * @return \SimpleXMLElement + */ + protected function parseXml($xml, $response) + { + $priorSetting = libxml_use_internal_errors(true); + try { + libxml_clear_errors(); + $xmlPayload = new \SimpleXMLElement($xml); + if ($error = libxml_get_last_error()) { + throw new \RuntimeException($error->message); + } + } catch (\Exception $e) { + throw new ParserException( + "Error parsing XML: {$e->getMessage()}", + 0, + $e, + ['response' => $response] + ); + } finally { + libxml_use_internal_errors($priorSetting); + } + + return $xmlPayload; + } +} |