Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
2
namespace Aws\Api\Parser;
2
namespace Aws\Api\Parser;
Línea -... Línea 3...
-
 
3
 
3
 
4
use Aws\Api\Operation;
4
use Aws\Api\StructureShape;
5
use Aws\Api\StructureShape;
5
use Aws\Api\Service;
6
use Aws\Api\Service;
6
use Aws\Result;
7
use Aws\Result;
7
use Aws\CommandInterface;
8
use Aws\CommandInterface;
Línea 17... Línea 18...
17
 
18
 
18
    /**
19
    /**
19
     * @param Service    $api    Service description
20
     * @param Service    $api    Service description
20
     * @param JsonParser $parser JSON body builder
21
     * @param JsonParser $parser JSON body builder
21
     */
22
     */
22
    public function __construct(Service $api, JsonParser $parser = null)
23
    public function __construct(Service $api, ?JsonParser $parser = null)
23
    {
24
    {
24
        parent::__construct($api);
25
        parent::__construct($api);
25
        $this->parser = $parser ?: new JsonParser();
26
        $this->parser = $parser ?: new JsonParser();
Línea 26... Línea 27...
26
    }
27
    }
27
 
28
 
28
    public function __invoke(
29
    public function __invoke(
29
        CommandInterface $command,
30
        CommandInterface $command,
30
        ResponseInterface $response
31
        ResponseInterface $response
-
 
32
    ) {
-
 
33
        $operation = $this->api->getOperation($command->getName());
-
 
34
 
-
 
35
        return $this->parseResponse($response, $operation);
-
 
36
    }
-
 
37
 
-
 
38
    /**
-
 
39
     * This method parses a response based on JSON RPC protocol.
-
 
40
     *
-
 
41
     * @param ResponseInterface $response the response to parse.
-
 
42
     * @param Operation $operation the operation which holds information for
-
 
43
     *        parsing the response.
-
 
44
     *
-
 
45
     * @return Result
-
 
46
     */
31
    ) {
47
    private function parseResponse(ResponseInterface $response, Operation $operation)
-
 
48
    {
-
 
49
        if (null === $operation['output']) {
-
 
50
            return new Result([]);
-
 
51
        }
-
 
52
 
-
 
53
        $outputShape = $operation->getOutput();
-
 
54
        foreach ($outputShape->getMembers() as $memberName => $memberProps) {
-
 
55
            if (!empty($memberProps['eventstream'])) {
-
 
56
                return new Result([
-
 
57
                    $memberName => new EventParsingIterator(
-
 
58
                        $response->getBody(),
-
 
59
                        $outputShape->getMember($memberName),
32
        $operation = $this->api->getOperation($command->getName());
60
                        $this
-
 
61
                    )
-
 
62
                ]);
-
 
63
            }
33
        $result = null === $operation['output']
64
        }
34
            ? null
65
 
35
            : $this->parseMemberFromStream(
66
        $result = $this->parseMemberFromStream(
36
                $response->getBody(),
67
                $response->getBody(),
37
                $operation->getOutput(),
68
                $operation->getOutput(),
Línea 38... Línea 69...
38
                $response
69
                $response
39
            );
70
            );
Línea 40... Línea 71...
40
 
71
 
41
        return new Result($result ?: []);
72
        return new Result(is_null($result) ? [] : $result);
42
    }
73
    }