Debian Codegraph @

lib/3rdParty/composer/aws/aws-sdk-php/src/Api/Serializer/RestXmlSerializer.php

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