File: application/modules/extensions/aws/Aws/Api/Parser/PayloadParserTrait.php

Recommend this page to a friend!
  Classes of Tran Tuan  >  Pretty PHP S3 Files Manager  >  application/modules/extensions/aws/Aws/Api/Parser/PayloadParserTrait.php  >  Download  
File: application/modules/extensions/aws/Aws/Api/Parser/PayloadParserTrait.php
Role: Application script
Content type: text/plain
Description: Application script
Class: Pretty PHP S3 Files Manager
Web based interface to manage files in Amazon S3
Author: By
Last change:
Date: 4 years ago
Size: 1,208 bytes
 

Contents

Class file image Download
<?php
namespace Aws\Api\Parser;

use
Aws\Api\Parser\Exception\ParserException;

trait
PayloadParserTrait
{
   
/**
     * @param string $json
     *
     * @throws ParserException
     *
     * @return array
     */
   
private function parseJson($json)
    {
       
$jsonPayload = json_decode($json, true);

        if (
JSON_ERROR_NONE !== json_last_error()) {
            throw new
ParserException('Error parsing JSON: '
               
. json_last_error_msg());
        }

        return
$jsonPayload;
    }

   
/**
     * @param string $xml
     *
     * @throws ParserException
     *
     * @return \SimpleXMLElement
     */
   
private function parseXml($xml)
    {
       
$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);
        } finally {
           
libxml_use_internal_errors($priorSetting);
        }

        return
$xmlPayload;
    }
}


For more information send a message to info at phpclasses dot org.