Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
namespace Aws\Api\Parser;
3
 
4
use Aws\Api\StructureShape;
5
use Aws\Api\Service;
6
use Aws\Result;
7
use Aws\CommandInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\StreamInterface;
10
 
11
/**
12
 * @internal Implements JSON-RPC parsing (e.g., DynamoDB)
13
 */
14
class JsonRpcParser extends AbstractParser
15
{
16
    use PayloadParserTrait;
17
 
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
 
28
    public function __invoke(
29
        CommandInterface $command,
30
        ResponseInterface $response
31
    ) {
32
        $operation = $this->api->getOperation($command->getName());
33
        $result = null === $operation['output']
34
            ? null
35
            : $this->parseMemberFromStream(
36
                $response->getBody(),
37
                $operation->getOutput(),
38
                $response
39
            );
40
 
41
        return new Result($result ?: []);
42
    }
43
 
44
    public function parseMemberFromStream(
45
        StreamInterface $stream,
46
        StructureShape $member,
47
        $response
48
    ) {
49
        return $this->parser->parse($member, $this->parseJson($stream, $response));
50
    }
51
}