Ec2ParamBuilder.php
11 months ago
JsonBody.php
11 months ago
JsonRpcSerializer.php
11 months ago
QueryParamBuilder.php
11 months ago
QuerySerializer.php
11 months ago
RestJsonSerializer.php
11 months ago
RestSerializer.php
11 months ago
RestXmlSerializer.php
11 months ago
XmlBody.php
11 months ago
RestJsonSerializer.php
43 lines
| 1 | <?php |
| 2 | namespace Aws\Api\Serializer; |
| 3 | |
| 4 | use Aws\Api\Service; |
| 5 | use Aws\Api\StructureShape; |
| 6 | |
| 7 | /** |
| 8 | * Serializes requests for the REST-JSON protocol. |
| 9 | * @internal |
| 10 | */ |
| 11 | class RestJsonSerializer extends RestSerializer |
| 12 | { |
| 13 | /** @var JsonBody */ |
| 14 | private $jsonFormatter; |
| 15 | |
| 16 | /** @var string */ |
| 17 | private $contentType; |
| 18 | |
| 19 | /** |
| 20 | * @param Service $api Service API description |
| 21 | * @param string $endpoint Endpoint to connect to |
| 22 | * @param JsonBody $jsonFormatter Optional JSON formatter to use |
| 23 | */ |
| 24 | public function __construct( |
| 25 | Service $api, |
| 26 | $endpoint, |
| 27 | JsonBody $jsonFormatter = null |
| 28 | ) { |
| 29 | parent::__construct($api, $endpoint); |
| 30 | $this->contentType = JsonBody::getContentType($api); |
| 31 | $this->jsonFormatter = $jsonFormatter ?: new JsonBody($api); |
| 32 | } |
| 33 | |
| 34 | protected function payload(StructureShape $member, array $value, array &$opts) |
| 35 | { |
| 36 | $body = isset($value) ? |
| 37 | ((string) $this->jsonFormatter->build($member, $value)) |
| 38 | : "{}"; |
| 39 | $opts['headers']['Content-Type'] = $this->contentType; |
| 40 | $opts['body'] = $body; |
| 41 | } |
| 42 | } |
| 43 |