Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5ec6a82

Browse filesBrowse files
committed
Merge branch '5.3' into 5.4
* 5.3: [Serializer] XmlEncoder context Shortening code sample
2 parents 77c5dc3 + 0047a35 commit 5ec6a82
Copy full SHA for 5ec6a82

File tree

Expand file treeCollapse file tree

2 files changed

+43
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+43
-8
lines changed

‎components/serializer.rst

Copy file name to clipboardExpand all lines: components/serializer.rst
+43-6Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,23 +1080,59 @@ These are the options available:
10801080
============================== ================================================= ==========================
10811081
Option Description Default
10821082
============================== ================================================= ==========================
1083-
``xml_format_output`` If set to true, formats the generated XML with
1084-
line breaks and indentation.
1083+
``xml_format_output`` If set to true, formats the generated XML with ``false``
1084+
line breaks and indentation
10851085
``xml_version`` Sets the XML version attribute ``1.1``
10861086
``xml_encoding`` Sets the XML encoding attribute ``utf-8``
10871087
``xml_standalone`` Adds standalone attribute in the generated XML ``true``
10881088
``xml_type_cast_attributes`` This provides the ability to forgot the attribute ``true``
10891089
type casting
1090-
``xml_root_node_name`` Sets the root node name (default: ``response``).
1091-
``as_collection`` Always returns results as a collection, even if
1090+
``xml_root_node_name`` Sets the root node name ``response``
1091+
``as_collection`` Always returns results as a collection, even if ``false``
10921092
only one line is decoded
1093-
``decoder_ignored_node_types`` Sets nodes to be ignored in the decode ``[\XML_PI_NODE, \XML_COMMENT_NODE]``
1094-
``encoder_ignored_node_types`` Sets nodes to be ignored in the encode ``[]``
1093+
``decoder_ignored_node_types`` Array of node types (`DOM XML_* constants`_) ``[\XML_PI_NODE, \XML_COMMENT_NODE]``
1094+
to be ignored while decoding
1095+
``encoder_ignored_node_types`` Array of node types (`DOM XML_* constants`_) ``[]``
1096+
to be ignored while encoding
10951097
``load_options`` XML loading `options with libxml`_ ``\LIBXML_NONET | \LIBXML_NOBLANKS``
10961098
``remove_empty_tags`` If set to true, removes all empty tags in the ``false``
10971099
generated XML
10981100
============================== ================================================= ==========================
10991101

1102+
Example with custom ``context``::
1103+
1104+
use Symfony\Component\Serializer\Encoder\XmlEncoder;
1105+
1106+
// create encoder with specified options as new default settings
1107+
$xmlEncoder = new XmlEncoder(['xml_format_output' => true]);
1108+
1109+
$data = [
1110+
'id' => 'IDHNQIItNyQ',
1111+
'date' => '2019-10-24',
1112+
];
1113+
1114+
// encode with default context
1115+
$xmlEncoder->encode($data, 'xml');
1116+
// outputs:
1117+
// <?xml version="1.0"?>
1118+
// <response>
1119+
// <id>IDHNQIItNyQ</id>
1120+
// <date>2019-10-24</date>
1121+
// </response>
1122+
1123+
// encode with modified context
1124+
$xmlEncoder->encode($data, 'xml', [
1125+
'xml_root_node_name' => 'track',
1126+
'encoder_ignored_node_types' => [
1127+
\XML_PI_NODE, // removes XML declaration (the leading xml tag)
1128+
],
1129+
]);
1130+
// outputs:
1131+
// <track>
1132+
// <id>IDHNQIItNyQ</id>
1133+
// <date>2019-10-24</date>
1134+
// </track>
1135+
11001136
The ``YamlEncoder``
11011137
~~~~~~~~~~~~~~~~~~~
11021138

@@ -1682,6 +1718,7 @@ Learn more
16821718
.. _`JMS serializer`: https://github.com/schmittjoh/serializer
16831719
.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8
16841720
.. _`options with libxml`: https://www.php.net/manual/en/libxml.constants.php
1721+
.. _`DOM XML_* constants`: https://www.php.net/manual/en/dom.constants.php
16851722
.. _JSON: http://www.json.org/
16861723
.. _XML: https://www.w3.org/XML/
16871724
.. _YAML: https://yaml.org/

‎logging/monolog_console.rst

Copy file name to clipboardExpand all lines: logging/monolog_console.rst
-2Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.