| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\Api\Serializer; |
| 4 |
|
| 5 |
use Dudlewebs\WPMCS\s3\Aws\Api\StructureShape; |
| 6 |
use Dudlewebs\WPMCS\s3\Aws\Api\Service; |
| 7 |
/** |
| 8 |
* @internal |
| 9 |
*/ |
| 10 |
class RestXmlSerializer extends RestSerializer |
| 11 |
{ |
| 12 |
/** @var XmlBody */ |
| 13 |
private $xmlBody; |
| 14 |
/** |
| 15 |
* @param Service $api Service API description |
| 16 |
* @param string $endpoint Endpoint to connect to |
| 17 |
* @param XmlBody $xmlBody Optional XML formatter to use |
| 18 |
*/ |
| 19 |
public function __construct(Service $api, $endpoint, ?XmlBody $xmlBody = null) |
| 20 |
{ |
| 21 |
parent::__construct($api, $endpoint); |
| 22 |
$this->xmlBody = $xmlBody ?: new XmlBody($api); |
| 23 |
} |
| 24 |
protected function payload(StructureShape $member, array $value, array &$opts) |
| 25 |
{ |
| 26 |
$opts['headers']['Content-Type'] = 'application/xml'; |
| 27 |
$body = $this->getXmlBody($member, $value); |
| 28 |
$opts['headers']['Content-Length'] = \strlen($body); |
| 29 |
$opts['body'] = $body; |
| 30 |
} |
| 31 |
/** |
| 32 |
* @param StructureShape $member |
| 33 |
* @param array $value |
| 34 |
* @return string |
| 35 |
*/ |
| 36 |
private function getXmlBody(StructureShape $member, array $value) |
| 37 |
{ |
| 38 |
$xmlBody = (string) $this->xmlBody->build($member, $value); |
| 39 |
$xmlBody = \str_replace("'", "'", $xmlBody); |
| 40 |
$xmlBody = \str_replace('\\r', " ", $xmlBody); |
| 41 |
$xmlBody = \str_replace('\\n', " ", $xmlBody); |
| 42 |
return $xmlBody; |
| 43 |
} |
| 44 |
} |
| 45 |
|