mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-07-06 04:51:32 -07:00
* Simplifies & beautifies everything * Introduces a new Class system. * Errors are defaulted to AWS's handler. * New function names & more efficient handling. * Should fix a majority of the errors. Please read the README for more!
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
namespace Aws\Api\Parser;
|
|
|
|
use Aws\Api\DateTimeResult;
|
|
use Aws\Api\Shape;
|
|
|
|
/**
|
|
* @internal Implements standard JSON parsing.
|
|
*/
|
|
class JsonParser
|
|
{
|
|
public function parse(Shape $shape, $value)
|
|
{
|
|
if ($value === null) {
|
|
return $value;
|
|
}
|
|
|
|
switch ($shape['type']) {
|
|
case 'structure':
|
|
$target = [];
|
|
foreach ($shape->getMembers() as $name => $member) {
|
|
$locationName = $member['locationName'] ?: $name;
|
|
if (isset($value[$locationName])) {
|
|
$target[$name] = $this->parse($member, $value[$locationName]);
|
|
}
|
|
}
|
|
return $target;
|
|
|
|
case 'list':
|
|
$member = $shape->getMember();
|
|
$target = [];
|
|
foreach ($value as $v) {
|
|
$target[] = $this->parse($member, $v);
|
|
}
|
|
return $target;
|
|
|
|
case 'map':
|
|
$values = $shape->getValue();
|
|
$target = [];
|
|
foreach ($value as $k => $v) {
|
|
$target[$k] = $this->parse($values, $v);
|
|
}
|
|
return $target;
|
|
|
|
case 'timestamp':
|
|
return DateTimeResult::fromTimestamp(
|
|
$value,
|
|
!empty($shape['timestampFormat']) ? $shape['timestampFormat'] : null
|
|
);
|
|
|
|
case 'blob':
|
|
return base64_decode($value);
|
|
|
|
default:
|
|
return $value;
|
|
}
|
|
}
|
|
}
|
|
|