PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / Parser / JsonRpcParser.php

JsonRpcParser.php in Media Cloud Sync 1.4.2, at includes/sdk/s3/Aws/Api/Parser/JsonRpcParser.php

60 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Api\Parser;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\Operation;
6 use Dudlewebs\WPMCS\s3\Aws\Api\StructureShape;
7 use Dudlewebs\WPMCS\s3\Aws\Api\Service;
8 use Dudlewebs\WPMCS\s3\Aws\Result;
9 use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
10 use Dudlewebs\WPMCS\s3\Psr\Http\Message\ResponseInterface;
11 use Dudlewebs\WPMCS\s3\Psr\Http\Message\StreamInterface;
12 /**
13 * @internal Implements JSON-RPC parsing (e.g., DynamoDB)
14 */
15 class JsonRpcParser extends AbstractParser
16 {
17 use PayloadParserTrait;
18 /**
19 * @param Service $api Service description
20 * @param JsonParser $parser JSON body builder
21 */
22 public function __construct(Service $api, ?JsonParser $parser = null)
23 {
24 parent::__construct($api);
25 $this->parser = $parser ?: new JsonParser();
26 }
27 public function __invoke(CommandInterface $command, ResponseInterface $response)
28 {
29 $operation = $this->api->getOperation($command->getName());
30 return $this->parseResponse($response, $operation);
31 }
32 /**
33 * This method parses a response based on JSON RPC protocol.
34 *
35 * @param ResponseInterface $response the response to parse.
36 * @param Operation $operation the operation which holds information for
37 * parsing the response.
38 *
39 * @return Result
40 */
41 private function parseResponse(ResponseInterface $response, Operation $operation)
42 {
43 if (null === $operation['output']) {
44 return new Result([]);
45 }
46 $outputShape = $operation->getOutput();
47 foreach ($outputShape->getMembers() as $memberName => $memberProps) {
48 if (!empty($memberProps['eventstream'])) {
49 return new Result([$memberName => new EventParsingIterator($response->getBody(), $outputShape->getMember($memberName), $this)]);
50 }
51 }
52 $result = $this->parseMemberFromStream($response->getBody(), $operation->getOutput(), $response);
53 return new Result(\is_null($result) ? [] : $result);
54 }
55 public function parseMemberFromStream(StreamInterface $stream, StructureShape $member, $response)
56 {
57 return $this->parser->parse($member, $this->parseJson($stream, $response));
58 }
59 }
60