mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-20 13:23:47 -07:00
spaces.php
This commit is contained in:
parent
7755490b81
commit
eefa32741e
845 changed files with 50409 additions and 0 deletions
51
aws/Aws/Api/Parser/PayloadParserTrait.php
Normal file
51
aws/Aws/Api/Parser/PayloadParserTrait.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue