8000 Merge branch '4.4' into 5.2 · symfony/symfony-docs@7cc8d2a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7cc8d2a

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: [Serializer] XmlEncoder context Shortening code sample
2 parents 6c09717 + 785af1f commit 7cc8d2a

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

components/serializer.rst

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,23 +1070,59 @@ These are the options available:
10701070
============================== ================================================= ==========================
10711071
Option Description Default
10721072
============================== ================================================= ==========================
1073-
``xml_format_output`` If set to true, formats the generated XML with
1074-
line breaks and indentation.
1073+
``xml_format_output`` If set to true, formats the generated XML with ``false``
1074+
line breaks and indentation
10751075
``xml_version`` Sets the XML version attribute ``1.1``
10761076
``xml_encoding`` Sets the XML encoding attribute ``utf-8``
10771077
``xml_standalone`` Adds standalone attribute in the generated XML ``true``
10781078
``xml_type_cast_attributes`` This provides the ability to forgot the attribute ``true``
10791079
type casting
1080-
``xml_root_node_name`` Sets the root node name (default: ``response``).
1081-
``as_collection`` Always returns results as a collection, even if
1080+
``xml_root_node_name`` Sets the root node name ``response``
1081+
``as_collection`` Always returns results as a collection, even if ``false``
10821082
only one line is decoded
1083-
``decoder_ignored_node_types`` Sets nodes to be ignored in the decode ``[\XML_PI_NODE, \XML_COMMENT_NODE]``
1084-
``encoder_ignored_node_types`` Sets nodes to be ignored in the encode ``[]``
1083+
``decoder_ignored_node_types`` Array of node types (`DOM XML_* constants`_) ``[\XML_PI_NODE, \XML_COMMENT_NODE]``
1084+
to be ignored while decoding
1085+
``encoder_ignored_node_types`` Array of node types (`DOM XML_* constants`_) ``[]``
1086+
to be ignored while encoding
10851087
``load_options`` XML loading `options with libxml`_ ``\LIBXML_NONET | \LIBXML_NOBLANKS``
10861088
``remove_empty_tags`` If set to true, removes all empty tags in the ``false``
10871089
generated XML
10881090
============================== ================================================= ==========================
10891091

1092+
Example with custom ``context``::
1093+
1094+
use Symfony\Component\Serializer\Encoder\XmlEncoder;
1095+
1096+
// create encoder with specified options as new default settings
1097+
$xmlEncoder = new XmlEncoder(['xml_format_output' => true]);
1098+
1099+
$data = [
1100+
'id' => 'IDHNQIItNyQ',
1101+
'date' => '2019-10-24',
1102+
];
1103+
1104+
// encode with default context
1105+
$xmlEncoder->encode($data, 'xml');
1106+
// outputs:
1107+
// <?xml version="1.0"?>
1108+
// <response>
1109+
// <id>IDHNQIItNyQ</id>
1110+
// <date>2019-10-24</date>
1111+
// </response>
1112+
1113+
// encode with modified context
1114+
$xmlEncoder->encode($data, 'xml', [
1115+
'xml_root_node_name' => 'track',
1116+
'encoder_ignored_node_types' => [
1117+
\XML_PI_NODE, // removes XML declaration (the leading xml tag)
1118+
],
1119+
]);
1120+
// outputs:
1121+
// <track>
1122+
// <id>IDHNQIItNyQ</id>
8000
1123+
// <date>2019-10-24</date>
1124+
// </track>
1125+
10901126
The ``YamlEncoder``
10911127
~~~~~~~~~~~~~~~~~~~
10921128

@@ -1672,6 +1708,7 @@ Learn more
16721708
.. _`JMS serializer`: https://github.com/schmittjoh/serializer
16731709
.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8
16741710
.. _`options with libxml`: https://www.php.net/manual/en/libxml.constants.php
1711+
.. _`DOM XML_* constants`: https://www.php.net/manual/en/dom.constants.php
16751712
.. _JSON: http://www.json.org/
16761713
.. _XML: https://www.w3.org/XML/
16771714
.. _YAML: https://yaml.org/

logging/monolog_console.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ The example above could then be rewritten as::
4242
use Symfony\Component\Console\Command\Command;
4343
use Symfony\Component\Console\Input\InputInterface;
4444
use Symfony\Component\Console\Output\OutputInterface;
45-
// ...
4645

4746
class YourCommand extends Command
4847
{
@@ -56,7 +55,6 @@ The example above could then be rewritten as::
5655
protected function execute(InputInterface $input, OutputInterface $output)
5756
{
5857
$this->logger->debug('Some info');
59-
// ...
6058
$this->logger->notice('Some more info');
6159
}
6260
}

0 commit comments

Comments
 (0)
0