| 1 |
<?php |
| 2 |
namespace Aws\Api\Serializer; |
| 3 |
|
| 4 |
use Aws\Api\Service; |
| 5 |
use Aws\Api\StructureShape; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class RestJsonSerializer extends RestSerializer |
| 12 |
{ |
| 13 |
|
| 14 |
private $jsonFormatter; |
| 15 |
|
| 16 |
|
| 17 |
private $contentType; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 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|string $value, array &$opts) |
| 35 |
{ |
| 36 |
$opts['headers']['Content-Type'] = $this->contentType; |
| 37 |
$body = $this->jsonFormatter->build($member, $value); |
| 38 |
$opts['headers']['Content-Length'] = (string) strlen($body); |
| 39 |
$opts['body'] = $body; |
| 40 |
} |
| 41 |
} |