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

Commit9cd5b2b

Browse files
committed
Reword and minor fixes
1 parentbaadee0 commit9cd5b2b

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

‎serializer/custom_normalizer.rst‎

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@
44
How to Create your Custom Normalizer
55
====================================
66

7-
The:doc:`Serializer Component</components/serializer>` uses Normalizers
8-
to transform any data to an array.
7+
The:doc:`Serializer component</components/serializer>` uses
8+
normalizers to transform any data into an array. The component provides several
9+
:doc:`built-in normalizers</serializer/normalizers>` but you may need to create
10+
your own normalizer to transform an unsupported data structure.
911

10-
The Component provides several built-in normalizer that are described
11-
:doc:`in their own section</serializer/normalizers>` but you may want
12-
to use another structure that's not supported.
13-
14-
Creating a new normalizer
12+
Creating a New Normalizer
1513
-------------------------
1614

1715
Imagine you want add, modify, or remove some properties during the serialization
1816
process. For that you'll have to create your own normalizer. But it's usually
1917
preferable to let Symfony normalize the object, then hook into the normalization
20-
to customize the normalized data. To do that,weleverage the ObjectNormalizer::
18+
to customize the normalized data. To do that, leverage the``ObjectNormalizer``::
2119

2220
namespace AppBundle\Serializer;
2321

@@ -42,14 +40,9 @@ to customize the normalized data. To do that, we leverage the ObjectNormalizer::
4240
$data = $this->normalizer->normalize($topic, $format, $context);
4341

4442
// Here, add, edit, or delete some data:
45-
$data['href']['self'] = $this
46-
->router
47-
->generate(
48-
'topic_show',
49-
['id' => $topic->getId()],
50-
UrlGeneratorInterface::ABSOLUTE_URL
51-
)
52-
;
43+
$data['href']['self'] = $this->router->generate('topic_show', array(
44+
'id' => $topic->getId(),
45+
), UrlGeneratorInterface::ABSOLUTE_URL);
5346

5447
return $data;
5548
}
@@ -60,12 +53,12 @@ to customize the normalized data. To do that, we leverage the ObjectNormalizer::
6053
}
6154
}
6255

63-
Registering it inyour app
64-
--------------------------
56+
Registering it inYour Application
57+
----------------------------------
6558

66-
If you usetheSymfony Framework. then you probably want to register this
67-
normalizer as a service in your app. Then, you only need totag itwith
68-
``serializer.normalizer`` to inject your custom normalizer into the Serializer.
59+
In order to enablethenormalizer in an application based on the entire Symfony
60+
framework, you must register it as a service and:doc:`tag it</service_container/tags>`
61+
with``serializer.normalizer``.
6962

7063
..configuration-block::
7164

@@ -102,5 +95,3 @@ normalizer as a service in your app. Then, you only need to tag it with
10295
->register('app.yaml_encoder', TopicNormalizer::class)
10396
->addTag('serializer.normalizer')
10497
;
105-
106-
.. _tracker:https://github.com/symfony/symfony/issues

‎serializer/normalizers.rst‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
Normalizers
55
===========
66

7-
Normalizer basically turn **objects** into **array** and vice versa.
8-
They implement
7+
Normalizers turn **objects** into **arrays** and vice versa. They implement
98
:class:`Symfony\\Component\\Serializer\\Normalizers\\NormalizerInterface` for
109
normalizing (object to array) and
1110
:class:`Symfony\\Component\\Serializer\\Normalizers\\DenormalizerInterface` for
12-
denormalizing (object toarray).
11+
denormalizing (array toobject).
1312

14-
You can add new normalizers to a Serializer instance by usingits first constructor argument::
13+
Normalizers are enabled in the serializer passing them asits first argument::
1514

1615
use Symfony\Component\Serializer\Serializer;
1716
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
@@ -22,7 +21,17 @@ You can add new normalizers to a Serializer instance by using its first construc
2221
Built-in Normalizers
2322
--------------------
2423

25-
*:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer` to normalizer PHP object using the PropertyAccessor component;
26-
*:class:`Symfony\\Component\\Serializer\\Normalizer\\CustomNormalizer` to normalizer PHP object using object that implements ``:class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizableInterface``;
27-
*:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer` to normalizer PHP object using getter and setter of the object;
28-
*:class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer` to normalizer PHP object using PHP reflection.
24+
Symfony includes the following normalizers but you can also
25+
:doc:`create your own normalizer</serializer/custom_normalizer>`:
26+
27+
*:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer` to
28+
normalize PHP object using the:doc:`PropertyAccessor component</components/property_access>`;
29+
*:class:`Symfony\\Component\\Serializer\\Normalizer\\CustomNormalizer` to
30+
normalize PHP object using an object that implements
31+
``:class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizableInterface``;
32+
*:class:`Symfony\\Component\\Serializer\\Normalizer\\GetSetMethodNormalizer` to
33+
normalize PHP object using the getter and setter methods of the object;
34+
*:class:`Symfony\\Component\\Serializer\\Normalizer\\PropertyNormalizer` to
35+
normalize PHP object using `PHP reflection`_.
36+
37+
.. _`PHP reflection`:https://php.net/manual/en/book.reflection.php

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp