PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / Api / Parser / PayloadParserTrait.php
transferito / vendor / aws / aws-sdk-php / src / Api / Parser Last commit date
Exception 11 months ago AbstractParser.php 11 months ago AbstractRestParser.php 11 months ago Crc32ValidatingParser.php 11 months ago DecodingEventStreamIterator.php 11 months ago EventParsingIterator.php 11 months ago JsonParser.php 11 months ago JsonRpcParser.php 11 months ago MetadataParserTrait.php 11 months ago PayloadParserTrait.php 11 months ago QueryParser.php 11 months ago RestJsonParser.php 11 months ago RestXmlParser.php 11 months ago XmlParser.php 11 months ago
PayloadParserTrait.php
62 lines
1 <?php
2 namespace Aws\Api\Parser;
3
4 use Aws\Api\Parser\Exception\ParserException;
5 use Psr\Http\Message\ResponseInterface;
6
7 trait PayloadParserTrait
8 {
9 /**
10 * @param string $json
11 *
12 * @throws ParserException
13 *
14 * @return array
15 */
16 private function parseJson($json, $response)
17 {
18 $jsonPayload = json_decode($json, true);
19
20 if (JSON_ERROR_NONE !== json_last_error()) {
21 throw new ParserException(
22 'Error parsing JSON: ' . json_last_error_msg(),
23 0,
24 null,
25 ['response' => $response]
26 );
27 }
28
29 return $jsonPayload;
30 }
31
32 /**
33 * @param string $xml
34 *
35 * @throws ParserException
36 *
37 * @return \SimpleXMLElement
38 */
39 protected function parseXml($xml, $response)
40 {
41 $priorSetting = libxml_use_internal_errors(true);
42 try {
43 libxml_clear_errors();
44 $xmlPayload = new \SimpleXMLElement($xml);
45 if ($error = libxml_get_last_error()) {
46 throw new \RuntimeException($error->message);
47 }
48 } catch (\Exception $e) {
49 throw new ParserException(
50 "Error parsing XML: {$e->getMessage()}",
51 0,
52 $e,
53 ['response' => $response]
54 );
55 } finally {
56 libxml_use_internal_errors($priorSetting);
57 }
58
59 return $xmlPayload;
60 }
61 }
62