Skip to content

Commit 18f4575

Browse files
committed
Merge branch 'patch-1' of github.com:loalf/symfony-docs into loalf-patch-1
Also contains tweaks to #1829 Conflicts: reference/configuration/framework.rst
2 parents 35fff77 + 63fae5b commit 18f4575

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

components/serializer.rst

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ The Serializer Component
1111
In order to do so, the Serializer Component follows the following
1212
simple schema.
1313

14+
.. _component-serializer-encoders:
15+
.. _component-serializer-normalizers:
16+
1417
.. image:: /images/components/serializer/serializer_workflow.png
1518

1619
As you can see in the picture above, an array is used as a man in

reference/configuration/framework.rst

+70
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Configuration
3434
* `gc_probability`_
3535
* `gc_maxlifetime`_
3636
* `save_path`_
37+
* `serializer`_
38+
* `enabled`_
3739
* `templating`_
3840
* `assets_base_urls`_
3941
* `assets_version`_
@@ -244,6 +246,70 @@ save_path
244246
This determines the argument to be passed to the save handler. If you choose
245247
the default file handler, this is the path where the files are created.
246248

249+
.. _configuration-framework-serializer:
250+
251+
serializer
252+
~~~~~~~~~~
253+
254+
enabled
255+
.......
256+
257+
**type**: ``boolean`` **default**: ``false``
258+
259+
Whether to enable the ``serializer`` service or not in the service container.
260+
If enabled, the ``serializer`` service will be available in the container
261+
and will be loaded with two :ref:`encoders<component-serializer-encoders>`
262+
(:class:`Symfony\\Component\\Serializer\\Encoder\\JsonEncoder` and
263+
:class:`Symfony\\Component\\Serializer\\Encoder\\XmlEncoder`)
264+
but no :ref:`normalizers<component-serializer-normalizers>`, meaning you'll
265+
need to load your own.
266+
267+
You can load normalizers and/or encoders by tagging them as
268+
:ref:`serializer.normalizer<reference-dic-tags-serializer-normalizer>` and
269+
:ref:`serializer.encoder<reference-dic-tags-serializer-encoder>`. It's also
270+
possible to set the priority of the tag in order to decide the matching order.
271+
272+
Here an example on how to load the load
273+
the :class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`:
274+
275+
.. configuration-block::
276+
277+
.. code-block:: yaml
278+
279+
# app/config/config.yml
280+
services:
281+
get_set_method_normalizer:
282+
class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer
283+
tags:
284+
- { name: serializer.normalizer }
285+
286+
.. code-block:: xml
287+
288+
<!-- app/config/config.xml -->
289+
<services>
290+
<service id="get_set_method_normalizer" class="Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer">
291+
<tag name="serializer.normalizer" />
292+
</service>
293+
</services>
294+
295+
.. code-block:: php
296+
297+
// app/config/config.php
298+
use Symfony\Component\DependencyInjection\Definition;
299+
300+
$definition = new Definition(
301+
'Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer'
302+
));
303+
$definition->addTag('serializer.normalizer');
304+
$container->setDefinition('get_set_method_normalizer', $definition);
305+
306+
.. note::
307+
308+
The :class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer`
309+
is broken by design. As soon as you have a circular object graph, an
310+
infinite loop is created when calling the getters. You're encouraged
311+
to add your own normalizers that fit your use-case.
312+
247313
templating
248314
~~~~~~~~~~
249315

@@ -462,6 +528,10 @@ Full Default Configuration
462528
# DEPRECATED! Please use: cookie_httponly
463529
httponly: ~
464530
531+
# serializer configuration
532+
serializer:
533+
enabled: false
534+
465535
# templating configuration
466536
templating:
467537
assets_version: ~

reference/dic_tags.rst

+30
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ the AsseticBundle has several tags that aren't listed here.
4242
+-----------------------------------+---------------------------------------------------------------------------+
4343
| `security.listener.factory`_ | Necessary when creating a custom authentication system |
4444
+-----------------------------------+---------------------------------------------------------------------------+
45+
| `serializer.encoder`_ | Register a new encoder in the ``serializer`` service |
46+
+-----------------------------------+---------------------------------------------------------------------------+
47+
| `serializer.normalizer`_ | Register a new normalizer in the ``serializer`` service |
48+
+-----------------------------------+---------------------------------------------------------------------------+
4549
| `swiftmailer.plugin`_ | Register a custom SwiftMailer Plugin |
4650
+-----------------------------------+---------------------------------------------------------------------------+
4751
| `templating.helper`_ | Make your service available in PHP templates |
@@ -560,6 +564,32 @@ is used behind the scenes to determine if the user should have access. The
560564

561565
For more information, read the cookbook article: :doc:`/cookbook/security/voters`.
562566

567+
.. _reference-dic-tags-serializer-encoder:
568+
569+
serializer.encoder
570+
------------------
571+
572+
**Purpose**: Register a new encoder in the ``serializer`` service
573+
574+
The class that's tagged should implement the :class:`Symfony\\Component\\Serializer\\Encoder\\EncoderInterface`
575+
and :class:`Symfony\\Component\\Serializer\\Encoder\\DecoderInterface`.
576+
577+
You have to :ref:`enable the serializer service<configuration-framework-serializer>`
578+
in order to use this tag.
579+
580+
.. _reference-dic-tags-serializer-normalizer:
581+
582+
serializer.normalizer
583+
---------------------
584+
585+
**Purpose**: Register a new normalizer in the Serializer service
586+
587+
The class that's tagged should implement the :class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizerInterface`
588+
and :class:`Symfony\\Component\\Serializer\\Normalizer\\DenormalizerInterface`.
589+
590+
You have to :ref:`enable the serializer service<configuration-framework-serializer>`
591+
in order to use this tag.
592+
563593
swiftmailer.plugin
564594
------------------
565595

0 commit comments

Comments
 (0)