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
 * Serializes a query protocol request.
13
 * @internal
14
 */
15
class QuerySerializer
16
{
17
    use EndpointV2SerializerTrait;
18
 
19
    private $endpoint;
20
    private $api;
21
    private $paramBuilder;
22
 
23
    public function __construct(
24
        Service $api,
25
        $endpoint,
26
        callable $paramBuilder = null
27
    ) {
28
        $this->api = $api;
29
        $this->endpoint = $endpoint;
30
        $this->paramBuilder = $paramBuilder ?: new QueryParamBuilder();
31
    }
32
 
33
    /**
34
     * When invoked with an AWS command, returns a serialization array
35
     * containing "method", "uri", "headers", and "body" key value pairs.
36
     *
37
     * @param CommandInterface $command Command to serialize into a request.
38
     * @param $endpointProvider Provider used for dynamic endpoint resolution.
39
     * @param $clientArgs Client arguments used for dynamic endpoint resolution.
40
     *
41
     * @return RequestInterface
42
     */
43
    public function __invoke(
44
        CommandInterface $command,
45
        $endpointProvider = null,
46
        $clientArgs = null
47
    )
48
    {
49
        $operation = $this->api->getOperation($command->getName());
50
        $body = [
51
            'Action'  => $command->getName(),
52
            'Version' => $this->api->getMetadata('apiVersion')
53
        ];
54
        $commandArgs = $command->toArray();
55
 
56
        // Only build up the parameters when there are parameters to build
57
        if ($commandArgs) {
58
            $body += call_user_func(
59
                $this->paramBuilder,
60
                $operation->getInput(),
61
                $commandArgs
62
            );
63
        }
64
        $body = http_build_query($body, '', '&', PHP_QUERY_RFC3986);
65
        $headers = [
66
            'Content-Length' => strlen($body),
67
            'Content-Type'   => 'application/x-www-form-urlencoded'
68
        ];
69
 
70
        if ($endpointProvider instanceof EndpointProviderV2) {
71
            $this->setRequestOptions(
72
                $endpointProvider,
73
                $command,
74
                $operation,
75
                $commandArgs,
76
                $clientArgs,
77
                $headers
78
            );
79
        }
80
 
81
        return new Request(
82
            'POST',
83
            $this->endpoint,
84
            $headers,
85
            $body
86
        );
87
    }
88
}