Skip to content

Commit

Permalink
Merge branch 'AyrtonRicardo-add-output-format'
Browse files Browse the repository at this point in the history
  • Loading branch information
goetas committed Feb 17, 2017
2 parents edf55a5 + cf49fa9 commit cda77c5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ private function addVisitorsSection(NodeBuilder $builder)
->arrayNode('doctype_whitelist')
->prototype('scalar')->end()
->end()
->booleanNode('format_output')
->defaultTrue()
->end()
->end()
->end()
->end()
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/JMSSerializerExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function loadInternal(array $config, ContainerBuilder $container)
;

$container->setParameter('jms_serializer.xml_deserialization_visitor.doctype_whitelist', $config['visitors']['xml']['doctype_whitelist']);
$container->setParameter('jms_serializer.xml_serialization_visitor.format_output', $config['visitors']['xml']['format_output']);
$container->setParameter('jms_serializer.json_serialization_visitor.options', $config['visitors']['json']['options']);

if ( ! $config['enable_short_alias']) {
Expand Down
4 changes: 4 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<parameter key="jms_serializer.xml_serialization_visitor.class">JMS\Serializer\XmlSerializationVisitor</parameter>
<parameter key="jms_serializer.xml_deserialization_visitor.class">JMS\Serializer\XmlDeserializationVisitor</parameter>
<parameter key="jms_serializer.xml_deserialization_visitor.doctype_whitelist" type="collection"></parameter>
<parameter key="jms_serializer.xml_serialization_visitor.format_output"></parameter>
<parameter key="jms_serializer.yaml_serialization_visitor.class">JMS\Serializer\YamlSerializationVisitor</parameter>

<parameter key="jms_serializer.handler_registry.class">JMS\Serializer\Handler\LazyHandlerRegistry</parameter>
Expand Down Expand Up @@ -236,6 +237,9 @@
<service id="jms_serializer.xml_serialization_visitor" class="%jms_serializer.xml_serialization_visitor.class%">
<argument type="service" id="jms_serializer.naming_strategy" />
<tag name="jms_serializer.serialization_visitor" format="xml" />
<call method="setFormatOutput">
<argument>%jms_serializer.xml_serialization_visitor.format_output%</argument>
</call>
</service>
<service id="jms_serializer.xml_deserialization_visitor" class="%jms_serializer.xml_deserialization_visitor.class%">
<argument type="service" id="jms_serializer.naming_strategy" />
Expand Down
1 change: 1 addition & 0 deletions Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ values:
xml:
doctype_whitelist:
- '<!DOCTYPE authorized SYSTEM "http://some_url">' # an authorized document type for xml deserialization
format_output: true
.. code-block :: xml
Expand Down
20 changes: 20 additions & 0 deletions Tests/DependencyInjection/JMSSerializerExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,26 @@ public function getXmlVisitorWhitelists()
return $configs;
}

public function testXmlVisitorFormatOutput()
{
$config = array(
'visitors' => array(
'xml' => array(
'format_output' => false,
)
)
);
$container = $this->getContainerForConfig(array($config));

$this->assertFalse($container->get('jms_serializer.xml_serialization_visitor')->isFormatOutput());
}

public function testXmlVisitorDefaultValueToFormatOutput()
{
$container = $this->getContainerForConfig(array());
$this->assertTrue($container->get('jms_serializer.xml_serialization_visitor')->isFormatOutput());
}

private function getContainerForConfig(array $configs, KernelInterface $kernel = null)
{
if (null === $kernel) {
Expand Down

0 comments on commit cda77c5

Please sign in to comment.