PluginProbe
Media Cloud Sync / 1.2.2
Media Cloud Sync v1.2.2
1.4.2 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 All 36 releases
media-cloud-sync / includes / sdk / s3 / Aws / Api / Serializer / JsonRpcSerializer.php

JsonRpcSerializer.php in Media Cloud Sync 1.2.2, at includes/sdk/s3/Aws/Api/Serializer/JsonRpcSerializer.php

50 lines 1.7 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\GuzzleHttp\Psr7\Request;
8 use Dudlewebs\WPMCS\s3\Psr\Http\Message\RequestInterface;
9 /**
10 * Prepares a JSON-RPC request for transfer.
11 * @internal
12 */
13 class JsonRpcSerializer
14 {
15 /** @var JsonBody */
16 private $jsonFormatter;
17 /** @var string */
18 private $endpoint;
19 /** @var Service */
20 private $api;
21 /** @var string */
22 private $contentType;
23 /**
24 * @param Service $api Service description
25 * @param string $endpoint Endpoint to connect to
26 * @param JsonBody $jsonFormatter Optional JSON formatter to use
27 */
28 public function __construct(Service $api, $endpoint, JsonBody $jsonFormatter = null)
29 {
30 $this->endpoint = $endpoint;
31 $this->api = $api;
32 $this->jsonFormatter = $jsonFormatter ?: new JsonBody($this->api);
33 $this->contentType = JsonBody::getContentType($api);
34 }
35 /**
36 * When invoked with an AWS command, returns a serialization array
37 * containing "method", "uri", "headers", and "body" key value pairs.
38 *
39 * @param CommandInterface $command
40 *
41 * @return RequestInterface
42 */
43 public function __invoke(CommandInterface $command)
44 {
45 $name = $command->getName();
46 $operation = $this->api->getOperation($name);
47 return new Request($operation['http']['method'], $this->endpoint, ['X-Amz-Target' => $this->api->getMetadata('targetPrefix') . '.' . $name, 'Content-Type' => $this->contentType], $this->jsonFormatter->build($operation->getInput(), $command->toArray()));
48 }
49 }
50