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\Serializer;
3
 
4
use Aws\Api\Service;
5
use Aws\CommandInterface;
6
use Aws\EndpointV2\EndpointProviderV2;
7
use Aws\EndpointV2\EndpointV2SerializerTrait;
8
use GuzzleHttp\Psr7\Request;
9
use Psr\Http\Message\RequestInterface;
10
 
11
/**
12
 * Prepares a JSON-RPC request for transfer.
13
 * @internal
14
 */
15
class JsonRpcSerializer
16
{
17
    use EndpointV2SerializerTrait;
18
 
19
    /** @var JsonBody */
20
    private $jsonFormatter;
21
 
22
    /** @var string */
23
    private $endpoint;
24
 
25
    /** @var Service */
26
    private $api;
27
 
28
    /** @var string */
29
    private $contentType;
30
 
31
    /**
32
     * @param Service  $api           Service description
33
     * @param string   $endpoint      Endpoint to connect to
34
     * @param JsonBody $jsonFormatter Optional JSON formatter to use
35
     */
36
    public function __construct(
37
        Service $api,
38
        $endpoint,
39
        JsonBody $jsonFormatter = null
40
    ) {
41
        $this->endpoint = $endpoint;
42
        $this->api = $api;
43
        $this->jsonFormatter = $jsonFormatter ?: new JsonBody($this->api);
44
        $this->contentType = JsonBody::getContentType($api);
45
    }
46
 
47
    /**
48
     * When invoked with an AWS command, returns a serialization array
49
     * containing "method", "uri", "headers", and "body" key value pairs.
50
     *
51
     * @param CommandInterface $command Command to serialize into a request.
52
     * @param $endpointProvider Provider used for dynamic endpoint resolution.
53
     * @param $clientArgs Client arguments used for dynamic endpoint resolution.
54
     *
55
     * @return RequestInterface
56
     */
57
    public function __invoke(
58
        CommandInterface $command,
59
        $endpointProvider = null,
60
        $clientArgs = null
61
    )
62
    {
63
        $operationName = $command->getName();
64
        $operation = $this->api->getOperation($operationName);
65
        $commandArgs = $command->toArray();
66
        $headers = [
67
                'X-Amz-Target' => $this->api->getMetadata('targetPrefix') . '.' . $operationName,
68
                'Content-Type' => $this->contentType
69
            ];
70
 
71
        if ($endpointProvider instanceof EndpointProviderV2) {
72
            $this->setRequestOptions(
73
                $endpointProvider,
74
                $command,
75
                $operation,
76
                $commandArgs,
77
                $clientArgs,
78
                $headers
79
            );
80
        }
81
 
82
        return new Request(
83
            $operation['http']['method'],
84
            $this->endpoint,
85
            $headers,
86
            $this->jsonFormatter->build(
87
                $operation->getInput(),
88
                $commandArgs
89
            )
90
        );
91
    }
92
}