Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/Serializer/QuerySerializer.php

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