| 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\Api\StructureShape; |
| 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 |
/** @var string */ |
| 16 |
private $contentType; |
| 17 |
/** |
| 18 |
* @param Service $api Service API description |
| 19 |
* @param string $endpoint Endpoint to connect to |
| 20 |
* @param JsonBody $jsonFormatter Optional JSON formatter to use |
| 21 |
*/ |
| 22 |
public function __construct(Service $api, $endpoint, JsonBody $jsonFormatter = null) |
| 23 |
{ |
| 24 |
parent::__construct($api, $endpoint); |
| 25 |
$this->contentType = JsonBody::getContentType($api); |
| 26 |
$this->jsonFormatter = $jsonFormatter ?: new JsonBody($api); |
| 27 |
} |
| 28 |
protected function payload(StructureShape $member, array $value, array &$opts) |
| 29 |
{ |
| 30 |
$body = isset($value) ? (string) $this->jsonFormatter->build($member, $value) : "{}"; |
| 31 |
$opts['headers']['Content-Type'] = $this->contentType; |
| 32 |
$opts['body'] = $body; |
| 33 |
} |
| 34 |
} |
| 35 |
|