10000 [Serializer] Add xml_format_output context option. Close #12517. by dunglas · Pull Request #13031 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Add xml_format_output context option. Close #12517. #13031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @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
{
Expand Down Expand Up @@ -514,6 +515,8 @@ private function createDomDocument(array $context)

// 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
Expand Down
20 changes: 20 additions & 0 deletions src/Symfony/Component/Serializer/Tests/Encoder/XmlEncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ public function testEncodeXmlAttributes()
$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(
Expand Down
0