Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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\EndpointV2SerializerTrait;
1441 ariadna 7
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
1 efrain 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,
1441 ariadna 39
        ?JsonBody $jsonFormatter = null
1 efrain 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,
1441 ariadna 59
        $endpoint = null
1 efrain 60
    )
61
    {
62
        $operationName = $command->getName();
63
        $operation = $this->api->getOperation($operationName);
64
        $commandArgs = $command->toArray();
65
        $headers = [
66
                'X-Amz-Target' => $this->api->getMetadata('targetPrefix') . '.' . $operationName,
67
                'Content-Type' => $this->contentType
68
            ];
69
 
1441 ariadna 70
        if ($endpoint instanceof RulesetEndpoint) {
71
            $this->setEndpointV2RequestOptions($endpoint, $headers);
1 efrain 72
        }
73
 
74
        return new Request(
75
            $operation['http']['method'],
76
            $this->endpoint,
77
            $headers,
78
            $this->jsonFormatter->build(
79
                $operation->getInput(),
80
                $commandArgs
81
            )
82
        );
83
    }
84
}