Skip to content

Commit 159da02

Browse files
committed
Add missing options context
1 parent 0958209 commit 159da02

File tree

1 file changed

+74
-13
lines changed

1 file changed

+74
-13
lines changed

components/serializer.rst

Lines changed: 74 additions & 13 deletions
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

@@ -923,25 +953,55 @@ which defines the configuration options for the XmlEncoder an associative array:
923953

924954
These are the options available:
925955

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

939980
The ``YamlEncoder``
940981
~~~~~~~~~~~~~~~~~~~
941982

942983
This encoder requires the :doc:`Yaml Component </components/yaml>` and
943984
transforms from and to Yaml.
944985

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

@@ -1508,6 +1568,7 @@ Learn more
15081568
.. _`PSR-1 standard`: https://www.php-fig.org/psr/psr-1/
15091569
.. _`JMS serializer`: https://github.com/schmittjoh/serializer
15101570
.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8
1571+
.. _`options with libxml`: https://www.php.net/manual/en/libxml.constants.php
15111572
.. _JSON: http://www.json.org/
15121573
.. _XML: https://www.w3.org/XML/
15131574
.. _YAML: https://yaml.org/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy