Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] update doc for 3.4 about normalizer#10543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 1 commit intosymfony:3.4fromlyrixx:serializer-normalizer
Oct 24, 2018
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 10 additions & 40 deletionsserializer/custom_normalizer.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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``::

namespaceAppBundle\Serializer;
namespaceApp\Serializer;

useAppBundle\Entity\Topic;
useApp\Entity\Topic;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
Expand DownExpand Up@@ -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 </service_container/tags>`
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

<!-- app/config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="app.yaml_encoder" class="AppBundle\Serializer\TopicNormalizer">
<tag name="serializer.normalizer" />
</service>
</services>
</container>
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 <service-container-services-load-example>`,
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``.

[8]ページ先頭

©2009-2025 Movatter.jp