Skip to content

Commit f1372f7

Browse files
committed
minor #14384 [Serializer] Add missing options context (maxhelias)
This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] Add missing options context The options are not really in the right place since just above the text indicates the elements for associative arrays. But we only list context options for an associative array here : https://symfony.com/doc/current/components/serializer.html#context Wouldn't we move all the options for all encoders here ? https://symfony.com/doc/current/components/serializer.html#encoders And in the first section display only the possible options for associative array with the link to their description. Solve #10277 and #10286 Commits ------- 159da02 Add missing options context
2 parents d585762 + 159da02 commit f1372f7

File tree

1 file changed

+74
-13
lines changed

1 file changed

+74
-13
lines changed

components/serializer.rst

+74-13
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,24 @@ When serializing, you can set a callback to format a specific object property::
691691
Normalizers
692692
-----------
693693

694-
There are several types of normalizers available:
694+
Normalizers turn **object** into **array** and vice versa. They implement
695+
::class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizableInterface`
696+
for normalize (object to array) and
697+
:class:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizableInterface` for denormalize
698+
(array to object).
699+
700+
You can add new normalizers to a Serializer instance by using its first constructor argument::
701+
702+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
703+
use Symfony\Component\Serializer\Serializer;
704+
705+
$normalizers = [new ObjectNormalizer()];
706+
$serializer = new Serializer($normalizers, []);
707+
708+
Built-in Normalizers
709+
~~~~~~~~~~~~~~~~~~~~
710+
711+
The Serializer component provides several built-in normalizers:
695712

696713
:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`
697714
This normalizer leverages the :doc:`PropertyAccess Component </components/property_access>`
@@ -765,6 +782,14 @@ There are several types of normalizers available:
765782
:class:`Symfony\\Component\\Serializer\\Normalizer\\ProblemNormalizer`
766783
Normalizes errors according to the API Problem spec `RFC 7807`_.
767784

785+
.. note::
786+
787+
You can also create your own Normalizer to use another structure. Read more at
788+
:doc:`/serializer/custom_normalizer`.
789+
790+
All these normalizers are enabled by default when using the Serializer component
791+
in a Symfony application.
792+
768793
.. _component-serializer-encoders:
769794

770795
Encoders
@@ -803,6 +828,11 @@ The Serializer component provides several built-in encoders:
803828
:class:`Symfony\\Component\\Serializer\\Encoder\\CsvEncoder`
804829
This encoder encodes and decodes data in `CSV`_.
805830

831+
.. note::
832+
833+
You can also create your own Encoder to use another structure. Read more at
834+
:doc:`/serializer/custom_encoders`.
835+
806836
All these encoders are enabled by default when using the Serializer component
807837
in a Symfony application.
808838

@@ -927,25 +957,55 @@ which defines the configuration options for the XmlEncoder an associative array:
927957

928958
These are the options available:
929959

930-
====================== ==================================================== ==========================
931-
Option Description Default
932-
====================== ==================================================== ==========================
933-
``xml_format_output`` If set to true, formats the generated XML with line
934-
breaks and indentation.
935-
``xml_version`` Sets the XML version attribute ``1.1``
936-
``xml_encoding`` Sets the XML encoding attribute ``utf-8``
937-
``xml_standalone`` Adds standalone attribute in the generated XML ``true``
938-
``xml_root_node_name`` Sets the root node name (default: ``response``).
939-
``remove_empty_tags`` If set to true, removes all empty tags in the ``false``
940-
generated XML
941-
====================== ==================================================== ==========================
960+
============================== ================================================= ==========================
961+
Option Description Default
962+
============================== ================================================= ==========================
963+
``xml_format_output`` If set to true, formats the generated XML with
964+
line breaks and indentation.
965+
``xml_version`` Sets the XML version attribute ``1.1``
966+
``xml_encoding`` Sets the XML encoding attribute ``utf-8``
967+
``xml_standalone`` Adds standalone attribute in the generated XML ``true``
968+
``xml_type_cast_attributes`` This provides the ability to forgot the attribute ``true``
969+
type casting
970+
``xml_root_node_name`` Sets the root node name (default: ``response``).
971+
``as_collection`` Always returns results as a collection, even if
972+
only one line is decoded
973+
``decoder_ignored_node_types`` Sets nodes to be ignored in the decode ``[\XML_PI_NODE, \XML_COMMENT_NODE]``
974+
``encoder_ignored_node_types`` Sets nodes to be ignored in the encode ``[]``
975+
``load_options`` XML loading `options with libxml`_ ``\LIBXML_NONET | \LIBXML_NOBLANKS``
976+
``remove_empty_tags`` If set to true, removes all empty tags in the ``false``
977+
generated XML
978+
============================== ================================================= ==========================
979+
980+
.. versionadded:: 4.2
981+
982+
The ``decoder_ignored_node_types`` & ``encoder_ignored_node_types`` options was introduced in Symfony 4.2.
942983

943984
The ``YamlEncoder``
944985
~~~~~~~~~~~~~~~~~~~
945986

946987
This encoder requires the :doc:`Yaml Component </components/yaml>` and
947988
transforms from and to Yaml.
948989

990+
The ``YamlEncoder`` Context Options
991+
...................................
992+
993+
The ``encode()`` method, like other encoder, uses ``context`` to set
994+
configuration options for the YamlEncoder an associative array::
995+
996+
$xmlEncoder->encode($array, 'xml', $context);
997+
998+
These are the options available:
999+
1000+
=============== ======================================================== ==========================
1001+
Option Description Default
1002+
=============== ======================================================== ==========================
1003+
``yaml_inline`` The level where you switch to inline YAML ``0``
1004+
``yaml_indent`` The level of indentation (used internally) ``0``
1005+
``yaml_flags`` A bit field of ``Yaml::DUMP_*`` / ``PARSE_*`` constants ``0``
1006+
to customize the encoding / decoding YAML string
1007+
=============== ======================================================== ==========================
1008+
9491009
Skipping ``null`` Values
9501010
------------------------
9511011

@@ -1512,6 +1572,7 @@ Learn more
15121572
.. _`PSR-1 standard`: https://www.php-fig.org/psr/psr-1/
15131573
.. _`JMS serializer`: https://github.com/schmittjoh/serializer
15141574
.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8
1575+
.. _`options with libxml`: https://www.php.net/manual/en/libxml.constants.php
15151576
.. _JSON: http://www.json.org/
15161577
.. _XML: https://www.w3.org/XML/
15171578
.. _YAML: https://yaml.org/

0 commit comments

Comments
 (0)