PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / Parser / PayloadParserTrait.php

PayloadParserTrait.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/Api/Parser/PayloadParserTrait.php

48 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Api\Parser;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\Parser\Exception\ParserException;
6 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
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 if (\JSON_ERROR_NONE !== \json_last_error()) {
20 throw new ParserException('Error parsing JSON: ' . \json_last_error_msg(), 0, null, ['response' => $response]);
21 }
22 return $jsonPayload;
23 }
24 /**
25 * @param string $xml
26 *
27 * @throws ParserException
28 *
29 * @return \SimpleXMLElement
30 */
31 protected function parseXml($xml, $response)
32 {
33 $priorSetting = \libxml_use_internal_errors(\true);
34 try {
35 \libxml_clear_errors();
36 $xmlPayload = new \SimpleXMLElement($xml);
37 if ($error = \libxml_get_last_error()) {
38 throw new \RuntimeException($error->message);
39 }
40 } catch (\Exception $e) {
41 throw new ParserException("Error parsing XML: {$e->getMessage()}", 0, $e, ['response' => $response]);
42 } finally {
43 \libxml_use_internal_errors($priorSetting);
44 }
45 return $xmlPayload;
46 }
47 }
48