← All changes
|
includes/sdk/s3/Aws/Api/Serializer/QuerySerializer.php
+18
-8
1.2.9
→
1.4.1
View file →
| @@ -3,8 +3,11 @@ | ||
| 3 | 3 | namespace Dudlewebs\WPMCS\s3\Aws\Api\Serializer; |
| 4 | 4 | |
| 5 | 5 | use Dudlewebs\WPMCS\s3\Aws\Api\Service; |
| 6 | 6 | use Dudlewebs\WPMCS\s3\Aws\CommandInterface; |
| 7 | +use Dudlewebs\WPMCS\s3\Aws\EndpointV2\EndpointProviderV2; | |
| 8 | +use Dudlewebs\WPMCS\s3\Aws\EndpointV2\EndpointV2SerializerTrait; | |
| 9 | +use Dudlewebs\WPMCS\s3\Aws\EndpointV2\Ruleset\RulesetEndpoint; | |
| 7 | 10 | use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\Request; |
| 8 | 11 | use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface; |
| 9 | 12 | /** |
| 10 | 13 | * Serializes a query protocol request. |
| @@ -11,12 +14,13 @@ | ||
| 11 | 14 | * @internal |
| 12 | 15 | */ |
| 13 | 16 | class QuerySerializer |
| 14 | 17 | { |
| 18 | + use EndpointV2SerializerTrait; | |
| 15 | 19 | private $endpoint; |
| 16 | 20 | private $api; |
| 17 | 21 | private $paramBuilder; |
| 18 | - public function __construct(Service $api, $endpoint, callable $paramBuilder = null) | |
| 22 | + public function __construct(Service $api, $endpoint, ?callable $paramBuilder = null) | |
| 19 | 23 | { |
| 20 | 24 | $this->api = $api; |
| 21 | 25 | $this->endpoint = $endpoint; |
| 22 | 26 | $this->paramBuilder = $paramBuilder ?: new QueryParamBuilder(); |
| @@ -24,21 +28,27 @@ | ||
| 24 | 28 | /** |
| 25 | 29 | * When invoked with an AWS command, returns a serialization array |
| 26 | 30 | * containing "method", "uri", "headers", and "body" key value pairs. |
| 27 | 31 | * |
| 28 | - * @param CommandInterface $command | |
| 29 | - * | |
| 32 | + * @param CommandInterface $command Command to serialize into a request. | |
| 33 | + * @param null $endpoint Endpoint resolved using EndpointProviderV2 | |
| 30 | 34 | * @return RequestInterface |
| 31 | 35 | */ |
| 32 | - public function __invoke(CommandInterface $command) | |
| 36 | + public function __invoke(CommandInterface $command, $endpoint = null) | |
| 33 | 37 | { |
| 34 | 38 | $operation = $this->api->getOperation($command->getName()); |
| 35 | 39 | $body = ['Action' => $command->getName(), 'Version' => $this->api->getMetadata('apiVersion')]; |
| 36 | - $params = $command->toArray(); | |
| 40 | + $commandArgs = $command->toArray(); | |
| 37 | 41 | // Only build up the parameters when there are parameters to build |
| 38 | - if ($params) { | |
| 39 | - $body += \call_user_func($this->paramBuilder, $operation->getInput(), $params); | |
| 42 | + if ($commandArgs) { | |
| 43 | + $body += \call_user_func($this->paramBuilder, $operation->getInput(), $commandArgs); | |
| 40 | 44 | } |
| 41 | 45 | $body = \http_build_query($body, '', '&', \PHP_QUERY_RFC3986); |
| 42 | - return new Request('POST', $this->endpoint, ['Content-Length' => \strlen($body), 'Content-Type' => 'application/x-www-form-urlencoded'], $body); | |
| 46 | + $headers = ['Content-Length' => \strlen($body), 'Content-Type' => 'application/x-www-form-urlencoded']; | |
| 47 | + $requestUri = $operation['http']['requestUri'] ?? null; | |
| 48 | + if ($endpoint instanceof RulesetEndpoint) { | |
| 49 | + $this->setEndpointV2RequestOptions($endpoint, $headers); | |
| 50 | + } | |
| 51 | + $absoluteUri = \str_ends_with($this->endpoint, '/') ? $this->endpoint : $this->endpoint . $requestUri; | |
| 52 | + return new Request('POST', $absoluteUri, $headers, $body); | |
| 43 | 53 | } |
| 44 | 54 | } |