# media-cloud-sync/1.1.1/includes/sdk/s3/Aws/Api/Parser/PayloadParserTrait.php

Media Cloud Sync, version 1.1.1. 48 lines.

- Page: https://pluginprobe.com/plugins/media-cloud-sync/1.1.1/code/includes/sdk/s3/Aws/Api/Parser/PayloadParserTrait.php
- Raw: https://pluginprobe.com/plugins/media-cloud-sync/1.1.1/raw/includes/sdk/s3/Aws/Api/Parser/PayloadParserTrait.php
- Modified: 2024-10-27T10:40:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/media-cloud-sync/1.1.1/code/includes/sdk/s3/Aws/Api/Parser/PayloadParserTrait.php#L10-L20`.

```php
<?php

namespace Dudlewebs\WPMCS\s3\Aws\Api\Parser;

use Dudlewebs\WPMCS\s3\Aws\Api\Parser\Exception\ParserException;
use Dudlewebs\WPMCS\s3\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;
    }
}

```
