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
← All changes | includes/sdk/s3/Aws/Api/Parser/JsonRpcParser.php +26 -3 1.2.4 → 1.4.2 View file →
@@ -1,8 +1,9 @@
1 1 <?php
2 2
3 3 namespace Dudlewebs\WPMCS\s3\Aws\Api\Parser;
4 4
5 +use Dudlewebs\WPMCS\s3\Aws\Api\Operation;
5 6 use Dudlewebs\WPMCS\s3\Aws\Api\StructureShape;
6 7 use Dudlewebs\WPMCS\s3\Aws\Api\Service;
7 8 use Dudlewebs\WPMCS\s3\Aws\Result;
8 9 use Dudlewebs\WPMCS\s3\Aws\CommandInterface;
@@ -17,9 +18,9 @@
17 18 /**
18 19 * @param Service $api Service description
19 20 * @param JsonParser $parser JSON body builder
20 21 */
21 - public function __construct(Service $api, JsonParser $parser = null)
22 + public function __construct(Service $api, ?JsonParser $parser = null)
22 23 {
23 24 parent::__construct($api);
24 25 $this->parser = $parser ?: new JsonParser();
25 26 }
@@ -25,10 +26,32 @@
25 26 }
26 27 public function __invoke(CommandInterface $command, ResponseInterface $response)
27 28 {
28 29 $operation = $this->api->getOperation($command->getName());
29 - $result = null === $operation['output'] ? null : $this->parseMemberFromStream($response->getBody(), $operation->getOutput(), $response);
30 - return new Result($result ?: []);
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);
31 54 }
32 55 public function parseMemberFromStream(StreamInterface $stream, StructureShape $member, $response)
33 56 {
34 57 return $this->parser->parse($member, $this->parseJson($stream, $response));