mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-14 02:27:23 -07:00
spaces.php
This commit is contained in:
parent
7755490b81
commit
eefa32741e
845 changed files with 50409 additions and 0 deletions
26
aws/Aws/Api/ErrorParser/JsonParserTrait.php
Normal file
26
aws/Aws/Api/ErrorParser/JsonParserTrait.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Aws\Api\Parser\PayloadParserTrait;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Provides basic JSON error parsing functionality.
|
||||
*/
|
||||
trait JsonParserTrait
|
||||
{
|
||||
use PayloadParserTrait;
|
||||
|
||||
private function genericHandler(ResponseInterface $response)
|
||||
{
|
||||
$code = (string) $response->getStatusCode();
|
||||
|
||||
return [
|
||||
'request_id' => (string) $response->getHeaderLine('x-amzn-requestid'),
|
||||
'code' => null,
|
||||
'message' => null,
|
||||
'type' => $code[0] == '4' ? 'client' : 'server',
|
||||
'parsed' => $this->parseJson($response->getBody())
|
||||
];
|
||||
}
|
||||
}
|
31
aws/Aws/Api/ErrorParser/JsonRpcErrorParser.php
Normal file
31
aws/Aws/Api/ErrorParser/JsonRpcErrorParser.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Parsers JSON-RPC errors.
|
||||
*/
|
||||
class JsonRpcErrorParser
|
||||
{
|
||||
use JsonParserTrait;
|
||||
|
||||
public function __invoke(ResponseInterface $response)
|
||||
{
|
||||
$data = $this->genericHandler($response);
|
||||
// Make the casing consistent across services.
|
||||
if ($data['parsed']) {
|
||||
$data['parsed'] = array_change_key_case($data['parsed']);
|
||||
}
|
||||
|
||||
if (isset($data['parsed']['__type'])) {
|
||||
$parts = explode('#', $data['parsed']['__type']);
|
||||
$data['code'] = isset($parts[1]) ? $parts[1] : $parts[0];
|
||||
$data['message'] = isset($data['parsed']['message'])
|
||||
? $data['parsed']['message']
|
||||
: null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
35
aws/Aws/Api/ErrorParser/RestJsonErrorParser.php
Normal file
35
aws/Aws/Api/ErrorParser/RestJsonErrorParser.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Parses JSON-REST errors.
|
||||
*/
|
||||
class RestJsonErrorParser
|
||||
{
|
||||
use JsonParserTrait;
|
||||
|
||||
public function __invoke(ResponseInterface $response)
|
||||
{
|
||||
$data = $this->genericHandler($response);
|
||||
|
||||
// Merge in error data from the JSON body
|
||||
if ($json = $data['parsed']) {
|
||||
$data = array_replace($data, $json);
|
||||
}
|
||||
|
||||
// Correct error type from services like Amazon Glacier
|
||||
if (!empty($data['type'])) {
|
||||
$data['type'] = strtolower($data['type']);
|
||||
}
|
||||
|
||||
// Retrieve the error code from services like Amazon Elastic Transcoder
|
||||
if ($code = $response->getHeaderLine('x-amzn-errortype')) {
|
||||
$colon = strpos($code, ':');
|
||||
$data['code'] = $colon ? substr($code, 0, $colon) : $code;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
82
aws/Aws/Api/ErrorParser/XmlErrorParser.php
Normal file
82
aws/Aws/Api/ErrorParser/XmlErrorParser.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
namespace Aws\Api\ErrorParser;
|
||||
|
||||
use Aws\Api\Parser\PayloadParserTrait;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Parses XML errors.
|
||||
*/
|
||||
class XmlErrorParser
|
||||
{
|
||||
use PayloadParserTrait;
|
||||
|
||||
public function __invoke(ResponseInterface $response)
|
||||
{
|
||||
$code = (string) $response->getStatusCode();
|
||||
|
||||
$data = [
|
||||
'type' => $code[0] == '4' ? 'client' : 'server',
|
||||
'request_id' => null,
|
||||
'code' => null,
|
||||
'message' => null,
|
||||
'parsed' => null
|
||||
];
|
||||
|
||||
$body = $response->getBody();
|
||||
if ($body->getSize() > 0) {
|
||||
$this->parseBody($this->parseXml($body), $data);
|
||||
} else {
|
||||
$this->parseHeaders($response, $data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function parseHeaders(ResponseInterface $response, array &$data)
|
||||
{
|
||||
if ($response->getStatusCode() == '404') {
|
||||
$data['code'] = 'NotFound';
|
||||
}
|
||||
|
||||
$data['message'] = $response->getStatusCode() . ' '
|
||||
. $response->getReasonPhrase();
|
||||
|
||||
if ($requestId = $response->getHeaderLine('x-amz-request-id')) {
|
||||
$data['request_id'] = $requestId;
|
||||
$data['message'] .= " (Request-ID: $requestId)";
|
||||
}
|
||||
}
|
||||
|
||||
private function parseBody(\SimpleXMLElement $body, array &$data)
|
||||
{
|
||||
$data['parsed'] = $body;
|
||||
|
||||
$namespaces = $body->getDocNamespaces();
|
||||
if (!isset($namespaces[''])) {
|
||||
$prefix = '';
|
||||
} else {
|
||||
// Account for the default namespace being defined and PHP not
|
||||
// being able to handle it :(.
|
||||
$body->registerXPathNamespace('ns', $namespaces['']);
|
||||
$prefix = 'ns:';
|
||||
}
|
||||
|
||||
if ($tempXml = $body->xpath("//{$prefix}Code[1]")) {
|
||||
$data['code'] = (string) $tempXml[0];
|
||||
}
|
||||
|
||||
if ($tempXml = $body->xpath("//{$prefix}Message[1]")) {
|
||||
$data['message'] = (string) $tempXml[0];
|
||||
}
|
||||
|
||||
$tempXml = $body->xpath("//{$prefix}RequestId[1]");
|
||||
if (empty($tempXml)) {
|
||||
$tempXml = $body->xpath("//{$prefix}RequestID[1]");
|
||||
}
|
||||
|
||||
if (isset($tempXml[0])) {
|
||||
$data['request_id'] = (string) $tempXml[0];
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue