Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
        $opts['body'] = $this->getXmlBody($member, $value);
33
    }
34
 
35
    /**
36
     * @param StructureShape $member
37
     * @param array $value
38
     * @return string
39
     */
40
    private function getXmlBody(StructureShape $member, array $value)
41
    {
42
        $xmlBody = (string)$this->xmlBody->build($member, $value);
43
        $xmlBody = str_replace("'", "&apos;", $xmlBody);
44
        $xmlBody = str_replace('\r', "&#13;", $xmlBody);
45
        $xmlBody = str_replace('\n', "&#10;", $xmlBody);
46
        return $xmlBody;
47
    }
48
}