v2: Updates

* 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!
This commit is contained in:
Devang Srivastava 2020-09-28 15:32:51 +05:30
commit e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions

View file

@ -14,6 +14,7 @@ use Psr\Http\Message\ResponseInterface;
abstract class AbstractRestParser extends AbstractParser
{
use PayloadParserTrait;
/**
* Parses a payload from a response.
*
@ -73,7 +74,13 @@ abstract class AbstractRestParser extends AbstractParser
) {
$member = $output->getMember($payload);
if ($member instanceof StructureShape) {
if (!empty($member['eventstream'])) {
$result[$payload] = new EventParsingIterator(
$response->getBody(),
$member,
$this
);
} else if ($member instanceof StructureShape) {
// Structure members parse top-level data into a specific key.
$result[$payload] = [];
$this->payload($response, $member, $result[$payload]);
@ -110,7 +117,10 @@ abstract class AbstractRestParser extends AbstractParser
break;
case 'timestamp':
try {
$value = new DateTimeResult($value);
$value = DateTimeResult::fromTimestamp(
$value,
!empty($shape['timestampFormat']) ? $shape['timestampFormat'] : null
);
break;
} catch (\Exception $e) {
// If the value cannot be parsed, then do not add it to the
@ -118,10 +128,21 @@ abstract class AbstractRestParser extends AbstractParser
return;
}
case 'string':
if ($shape['jsonvalue']) {
$value = $this->parseJson(base64_decode($value));
try {
if ($shape['jsonvalue']) {
$value = $this->parseJson(base64_decode($value), $response);
}
// If value is not set, do not add to output structure.
if (!isset($value)) {
return;
}
break;
} catch (\Exception $e) {
//If the value cannot be parsed, then do not add it to the
//output structure.
return;
}
break;
}
$result[$name] = $value;