123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace Aws\Api\Serializer;
- use Aws\Api\Service;
- use Aws\CommandInterface;
- use Aws\EndpointV2\EndpointV2SerializerTrait;
- use Aws\EndpointV2\Ruleset\RulesetEndpoint;
- use GuzzleHttp\Psr7\Request;
- use Psr\Http\Message\RequestInterface;
- class JsonRpcSerializer
- {
- use EndpointV2SerializerTrait;
-
- private $jsonFormatter;
-
- private $endpoint;
-
- private $api;
-
- private $contentType;
-
- public function __construct(
- Service $api,
- $endpoint,
- JsonBody $jsonFormatter = null
- ) {
- $this->endpoint = $endpoint;
- $this->api = $api;
- $this->jsonFormatter = $jsonFormatter ?: new JsonBody($this->api);
- $this->contentType = JsonBody::getContentType($api);
- }
-
- public function __invoke(
- CommandInterface $command,
- $endpoint = null
- )
- {
- $operationName = $command->getName();
- $operation = $this->api->getOperation($operationName);
- $commandArgs = $command->toArray();
- $headers = [
- 'X-Amz-Target' => $this->api->getMetadata('targetPrefix') . '.' . $operationName,
- 'Content-Type' => $this->contentType
- ];
- if ($endpoint instanceof RulesetEndpoint) {
- $this->setEndpointV2RequestOptions($endpoint, $headers);
- }
- return new Request(
- $operation['http']['method'],
- $this->endpoint,
- $headers,
- $this->jsonFormatter->build(
- $operation->getInput(),
- $commandArgs
- )
- );
- }
- }
|