From 4aa2652bbc179d00fb104460c93b158962a7e13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Tue, 23 Oct 2018 15:56:27 +0200 Subject: [PATCH] [Serializer] update doc for 3.4 about normalizer --- serializer/custom_normalizer.rst | 50 +++++++------------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/serializer/custom_normalizer.rst b/serializer/custom_normalizer.rst index 33389b5c4d4..5c2ba5a385e 100644 --- a/serializer/custom_normalizer.rst +++ b/serializer/custom_normalizer.rst @@ -17,9 +17,9 @@ process. For that you'll have to create your own normalizer. But it's usually preferable to let Symfony normalize the object, then hook into the normalization to customize the normalized data. To do that, leverage the ``ObjectNormalizer``:: - namespace AppBundle\Serializer; + namespace App\Serializer; - use AppBundle\Entity\Topic; + use App\Entity\Topic; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; @@ -53,45 +53,15 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``: } } -Registering it in Your Application ----------------------------------- - -In order to enable the normalizer in an application based on the entire Symfony -framework, you must register it as a service and :doc:`tag it ` -with ``serializer.normalizer``. - -.. configuration-block:: - - .. code-block:: yaml - # app/config/services.yml - services: - app.yaml_encoder: - class: AppBundle\Serializer\TopicNormalizer - tags: - - { name: serializer.normalizer } - - .. code-block:: xml - - - - - - - - - - - +Registering it in your Application +---------------------------------- - .. code-block:: php +If you use the Symfony Framework. then you probably want to register this normalizer +as a service in your app. If you're using the :ref:`default services.yml configuration `, +that's done automatically! - // app/config/services.php - use AppBundle\Serializer\TopicNormalizer; +.. tip:: - $container - ->register('app.yaml_encoder', TopicNormalizer::class) - ->addTag('serializer.normalizer') - ; + If you're not using autoconfigure, make sure to register your class as a service + and tag it with ``serializer.normalizer``.