Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/Parser/PayloadParserTrait.php

raw symbols SCIP
1 <?php
2 namespace Aws\Api\Parser;
3
4 use Aws\Api\Parser\Exception\ParserException;
5
6 trait PayloadParserTrait
7 {
8 /**
9 * @param string $json
10 *
11 * @throws ParserException
12 *
13 * @return array
14 */
15 private function parseJson($json, $response)
16 {
17 $jsonPayload = json_decode($json, true);
18
19 if (JSON_ERROR_NONE !== json_last_error()) {
20 throw new ParserException(
21 'Error parsing JSON: ' . json_last_error_msg(),
22 0,
23 null,
24 ['response' => $response]
25 );
26 }
27
28 return $jsonPayload;
29 }
30
31 /**
32 * @param string $xml
33 *
34 * @throws ParserException
35 *
36 * @return \SimpleXMLElement
37 */
38 protected function parseXml($xml, $response)
39 {
40 $priorSetting = libxml_use_internal_errors(true);
41 try {
42 libxml_clear_errors();
43 $xmlPayload = new \SimpleXMLElement($xml);
44 if ($error = libxml_get_last_error()) {
45 throw new \RuntimeException($error->message);
46 }
47 } catch (\Exception $e) {
48 throw new ParserException(
49 "Error parsing XML: {$e->getMessage()}",
50 0,
51 $e,
52 ['response' => $response]
53 );
54 } finally {
55 libxml_use_internal_errors($priorSetting);
56 }
57
58 return $xmlPayload;
59 }
60 }