PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / Serializer / QuerySerializer.php

QuerySerializer.php in Media Cloud Sync 1.4.1, at includes/sdk/s3/Aws/Api/Serializer/QuerySerializer.php

55 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Dudlewebs\WPMCS\s3\Aws\Api\Serializer;
4
5 use Dudlewebs\WPMCS\s3\Aws\Api\Service;
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;
10 use Dudlewebs\WPMCS\s3\GuzzleHttp\Psr7\Request;
11 use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
12 /**
13 * Serializes a query protocol request.
14 * @internal
15 */
16 class QuerySerializer
17 {
18 use EndpointV2SerializerTrait;
19 private $endpoint;
20 private $api;
21 private $paramBuilder;
22 public function __construct(Service $api, $endpoint, ?callable $paramBuilder = null)
23 {
24 $this->api = $api;
25 $this->endpoint = $endpoint;
26 $this->paramBuilder = $paramBuilder ?: new QueryParamBuilder();
27 }
28 /**
29 * When invoked with an AWS command, returns a serialization array
30 * containing "method", "uri", "headers", and "body" key value pairs.
31 *
32 * @param CommandInterface $command Command to serialize into a request.
33 * @param null $endpoint Endpoint resolved using EndpointProviderV2
34 * @return RequestInterface
35 */
36 public function __invoke(CommandInterface $command, $endpoint = null)
37 {
38 $operation = $this->api->getOperation($command->getName());
39 $body = ['Action' => $command->getName(), 'Version' => $this->api->getMetadata('apiVersion')];
40 $commandArgs = $command->toArray();
41 // Only build up the parameters when there are parameters to build
42 if ($commandArgs) {
43 $body += \call_user_func($this->paramBuilder, $operation->getInput(), $commandArgs);
44 }
45 $body = \http_build_query($body, '', '&', \PHP_QUERY_RFC3986);
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);
53 }
54 }
55