Skip to content

Commit 0850560

Browse files
committed
Add missing options context
1 parent 0958209 commit 0850560

File tree

1 file changed

+70
-13
lines changed

1 file changed

+70
-13
lines changed

components/serializer.rst

Lines changed: 70 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,51 @@ 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+
============================== ================================================= ==========================
938975

939976
The ``YamlEncoder``
940977
~~~~~~~~~~~~~~~~~~~
941978

942979
This encoder requires the :doc:`Yaml Component </components/yaml>` and
943980
transforms from and to Yaml.
944981

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

@@ -1508,6 +1564,7 @@ Learn more
15081564
.. _`PSR-1 standard`: https://www.php-fig.org/psr/psr-1/
15091565
.. _`JMS serializer`: https://github.com/schmittjoh/serializer
15101566
.. _RFC3339: https://tools.ietf.org/html/rfc3339#section-5.8
1567+
.. _`options with libxml`: https://www.php.net/manual/en/libxml.constants.php
15111568
.. _JSON: http://www.json.org/
15121569
.. _XML: https://www.w3.org/XML/
15131570
.. _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