[Serializer] Add xml_format_output context option. Close #12517.
This commit is contained in:
parent
176b175043
commit
37d3f84f1c
@ -19,6 +19,7 @@ use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
* @author John Wards <jwards@whiteoctober.co.uk>
|
||||
* @author Fabian Vogler <fabian@equivalence.ch>
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, DecoderInterface, NormalizationAwareInterface
|
||||
{
|
||||
@ -514,6 +515,8 @@ class XmlEncoder extends SerializerAwareEncoder implements EncoderInterface, Dec
|
||||
|
||||
// Set an attribute on the DOM document specifying, as part of the XML declaration,
|
||||
$xmlOptions = array(
|
||||
// nicely formats output with indentation and extra space
|
||||
'xml_format_output' => 'formatOutput',
|
||||
// the version number of the document
|
||||
'xml_version' => 'xmlVersion',
|
||||
// the encoding of the document
|
||||
|
@ -137,6 +137,26 @@ class XmlEncoderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($expected, $this->encoder->encode($array, 'xml', $context));
|
||||
}
|
||||
|
||||
public function testContext()
|
||||
{
|
||||
$array = array('person' => array('name' => 'George Abitbol'));
|
||||
$expected = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<response>
|
||||
<person>
|
||||
<name>George Abitbol</name>
|
||||
</person>
|
||||
</response>
|
||||
|
||||
XML;
|
||||
|
||||
$context = array(
|
||||
'xml_format_output' => true,
|
||||
);
|
||||
|
||||
$this->assertSame($expected, $this->encoder->encode($array, 'xml', $context));
|
||||
}
|
||||
|
||||
public function testEncodeScalarRootAttributes()
|
||||
{
|
||||
$array = array(
|
||||
|
Reference in New Issue
Block a user