Skip to content

Commit

Permalink
Merge branch '4.4' into 5.2
Browse files Browse the repository at this point in the history
* 4.4:
  [Serializer] XmlEncoder context
  Shortening code sample
  • Loading branch information
javiereguiluz committed Jun 16, 2021
2 parents 6c09717 + 785af1f commit 7cc8d2a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
49 changes: 43 additions & 6 deletions components/serializer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1070,23 +1070,59 @@ These are the options available:
============================== ================================================= ==========================
Option Description Default
============================== ================================================= ==========================
``xml_format_output`` If set to true, formats the generated XML with
line breaks and indentation.
``xml_format_output`` If set to true, formats the generated XML with ``false``
line breaks and indentation
``xml_version`` Sets the XML version attribute ``1.1``
``xml_encoding`` Sets the XML encoding attribute ``utf-8``
``xml_standalone`` Adds standalone attribute in the generated XML ``true``
``xml_type_cast_attributes`` This provides the ability to forgot the attribute ``true``
type casting
``xml_root_node_name`` Sets the root node name (default: ``response``).
``as_collection`` Always returns results as a collection, even if
``xml_root_node_name`` Sets the root node name ``response``
``as_collection`` Always returns results as a collection, even if ``false``
only one line is decoded
``decoder_ignored_node_types`` Sets nodes to be ignored in the decode ``[\XML_PI_NODE, \XML_COMMENT_NODE]``
``encoder_ignored_node_types`` Sets nodes to be ignored in the encode ``[]``
``decoder_ignored_node_types`` Array of node types (`DOM XML_* constants`_) ``[\XML_PI_NODE, \XML_COMMENT_NODE]``
to be ignored while decoding
``encoder_ignored_node_types`` Array of node types (`DOM XML_* constants`_) ``[]``
to be ignored while encoding
``load_options`` XML loading `options with libxml`_ ``\LIBXML_NONET | \LIBXML_NOBLANKS``
``remove_empty_tags`` If set to true, removes all empty tags in the ``false``
generated XML
============================== ================================================= ==========================

Example with custom ``context``::

use Symfony\Component\Serializer\Encoder\XmlEncoder;

// create encoder with specified options as new default settings
$xmlEncoder = new XmlEncoder(['xml_format_output' => true]);

$data = [
'id' => 'IDHNQIItNyQ',
'date' => '2019-10-24',
];

// encode with default context
$xmlEncoder->encode($data, 'xml');
// outputs:
// <?xml version="1.0"?>
// <response>
// <id>IDHNQIItNyQ</id>
// <date>2019-10-24</date>
// </response>

// encode with modified context
$xmlEncoder->encode($data, 'xml', [
'xml_root_node_name' => 'track',
'encoder_ignored_node_types' => [
\XML_PI_NODE, // removes XML declaration (the leading xml tag)
],
]);
// outputs:
// <track>
// <id>IDHNQIItNyQ</id>
// <date>2019-10-24</date>
// </track>

The ``YamlEncoder``
~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -1672,6 +1708,7 @@ Learn more
.. _`JMS serializer`: https://github.com/schmittjoh/serializer
.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8
.. _`options with libxml`: https://www.php.net/manual/en/libxml.constants.php
.. _`DOM XML_* constants`: https://www.php.net/manual/en/dom.constants.php
.. _JSON: http://www.json.org/
.. _XML: https://www.w3.org/XML/
.. _YAML: https://yaml.org/
Expand Down
2 changes: 0 additions & 2 deletions logging/monolog_console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ The example above could then be rewritten as::
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
// ...

class YourCommand extends Command
{
Expand All @@ -56,7 +55,6 @@ The example above could then be rewritten as::
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->logger->debug('Some info');
// ...
$this->logger->notice('Some more info');
}
}
Expand Down

0 comments on commit 7cc8d2a

Please sign in to comment.