Skip to content

Commit 7d5a546

Browse files
committed
Merge branch '4.4'
* 4.4: [#12600] Added versionadded for invokable listeners Revert "bug #12600 [Doctrine] Don't mention invokable listeners in 4.3 (javiereguiluz)" [#12584] Small tweaks Add WeekType Documentation [Doctrine] Don't mention invokable listeners in 4.3 [Messenger] update events for 4.4 Use normalizer context constants everywhere
2 parents b24ba25 + 9bfa4ce commit 7d5a546

File tree

7 files changed

+217
-14
lines changed

7 files changed

+217
-14
lines changed

components/serializer.rst

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ needs three parameters:
168168

169169
By default, additional attributes that are not mapped to the denormalized object
170170
will be ignored by the Serializer component. If you prefer to throw an exception
171-
when this happens, set the ``allow_extra_attributes`` context option to
171+
when this happens, set the ``AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES`` context option to
172172
``false`` and provide an object that implements ``ClassMetadataFactoryInterface``
173173
when constructing the normalizer::
174174

@@ -188,7 +188,7 @@ when constructing the normalizer::
188188
// this will throw a Symfony\Component\Serializer\Exception\ExtraAttributesException
189189
// because "city" is not an attribute of the Person class
190190
$person = $serializer->deserialize($data, 'App\Model\Person', 'xml', [
191-
'allow_extra_attributes' => false,
191+
AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES => false,
192192
]);
193193

194194
Deserializing in an Existing Object
@@ -209,12 +209,12 @@ The serializer can also be used to update an existing object::
209209
</person>
210210
EOF;
211211

212-
$serializer->deserialize($data, Person::class, 'xml', ['object_to_populate' => $person]);
212+
$serializer->deserialize($data, Person::class, 'xml', [AbstractNormalizer::OBJECT_TO_POPULATE => $person]);
213213
// $person = App\Model\Person(name: 'foo', age: '69', sportsperson: true)
214214

215215
This is a common need when working with an ORM.
216216

217-
The ``OBJECT_TO_POPULATE`` is only used for the top level object. If that object
217+
The ``AbstractNormalizer::OBJECT_TO_POPULATE`` is only used for the top level object. If that object
218218
is the root of a tree structure, all child elements that exist in the
219219
normalized data will be re-created with new instances.
220220

@@ -372,6 +372,7 @@ Selecting Specific Attributes
372372

373373
It is also possible to serialize only a set of specific attributes::
374374

375+
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
375376
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
376377
use Symfony\Component\Serializer\Serializer;
377378

@@ -399,7 +400,7 @@ It is also possible to serialize only a set of specific attributes::
399400

400401
$serializer = new Serializer([new ObjectNormalizer()]);
401402

402-
$data = $serializer->normalize($user, null, ['attributes' => ['familyName', 'company' => ['name']]]);
403+
$data = $serializer->normalize($user, null, [AbstractNormalizer::ATTRIBUTES => ['familyName', 'company' => ['name']]]);
403404
// $data = ['familyName' => 'Dunglas', 'company' => ['name' => 'Les-Tilleuls.coop']];
404405

405406
Only attributes that are not ignored (see below) are available.
@@ -411,11 +412,12 @@ Ignoring Attributes
411412
-------------------
412413

413414
As an option, there's a way to ignore attributes from the origin object.
414-
To remove those attributes provide an array via the ``ignored_attributes``
415+
To remove those attributes provide an array via the ``AbstractNormalizer::IGNORED_ATTRIBUTES``
415416
key in the ``context`` parameter of the desired serializer method::
416417

417418
use Acme\Person;
418419
use Symfony\Component\Serializer\Encoder\JsonEncoder;
420+
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
419421
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
420422
use Symfony\Component\Serializer\Serializer;
421423

@@ -427,7 +429,7 @@ key in the ``context`` parameter of the desired serializer method::
427429
$encoder = new JsonEncoder();
428430

429431
$serializer = new Serializer([$normalizer], [$encoder]);
430-
$serializer->serialize($person, 'json', ['ignored_attributes' => ['age']]); // Output: {"name":"foo"}
432+
$serializer->serialize($person, 'json', [AbstractNormalizer::IGNORED_ATTRIBUTES => ['age']]); // Output: {"name":"foo"}
431433

432434
.. _component-serializer-converting-property-names-when-serializing-and-deserializing:
433435

@@ -843,7 +845,7 @@ Skipping ``null`` Values
843845
------------------------
844846

845847
By default, the Serializer will preserve properties containing a ``null`` value.
846-
You can change this behavior by setting the ``skip_null_values`` context option
848+
You can change this behavior by setting the ``AbstractObjectNormalizer::SKIP_NULL_VALUES`` context option
847849
to ``true``::
848850

849851
$dummy = new class {
@@ -852,7 +854,7 @@ to ``true``::
852854
};
853855

854856
$normalizer = new ObjectNormalizer();
855-
$result = $normalizer->normalize($dummy, 'json', ['skip_null_values' => true]);
857+
$result = $normalizer->normalize($dummy, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]);
856858
// ['bar' => 'notNull']
857859

858860
.. _component-serializer-handling-circular-references:
@@ -1027,11 +1029,11 @@ in a Symfony application. When using the standalone component, refer to
10271029
:ref:`the groups documentation <component-serializer-attributes-groups>` to
10281030
learn how to do that.
10291031

1030-
The check is only done if the ``enable_max_depth`` key of the serializer context
1032+
The check is only done if the ``AbstractObjectNormalizer::ENABLE_MAX_DEPTH`` key of the serializer context
10311033
is set to ``true``. In the following example, the third level is not serialized
10321034
because it is deeper than the configured maximum depth of 2::
10331035

1034-
$result = $serializer->normalize($level1, null, ['enable_max_depth' => true]);
1036+
$result = $serializer->normalize($level1, null, [AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true]);
10351037
/*
10361038
$result = [
10371039
'foo' => 'level1',
@@ -1052,6 +1054,7 @@ having unique identifiers::
10521054
use Symfony\Component\Serializer\Annotation\MaxDepth;
10531055
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
10541056
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
1057+
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
10551058
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
10561059
use Symfony\Component\Serializer\Serializer;
10571060

@@ -1090,7 +1093,7 @@ having unique identifiers::
10901093

10911094
$serializer = new Serializer([$normalizer]);
10921095

1093-
$result = $serializer->normalize($level1, null, [ObjectNormalizer::ENABLE_MAX_DEPTH => true]);
1096+
$result = $serializer->normalize($level1, null, [AbstractObjectNormalizer::ENABLE_MAX_DEPTH => true]);
10941097
/*
10951098
$result = [
10961099
'id' => 1,
@@ -1220,6 +1223,7 @@ If the class constructor defines arguments, as usually happens with
12201223
arguments are missing. In those cases, use the ``default_constructor_arguments``
12211224
context option::
12221225

1226+
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
12231227
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
12241228
use Symfony\Component\Serializer\Serializer;
12251229

@@ -1241,7 +1245,7 @@ context option::
12411245
$data = $serializer->denormalize(
12421246
['foo' => 'Hello'],
12431247
'MyObj',
1244-
['default_constructor_arguments' => [
1248+
[AbstractNormalizer::DEFAULT_CONSTRUCTOR_ARGUMENTS => [
12451249
'MyObj' => ['foo' => '', 'bar' => ''],
12461250
]]
12471251
);

doctrine/events.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ with the ``doctrine.orm.entity_listener`` tag:
330330
])
331331
;
332332
333+
.. versionadded:: 4.4
334+
335+
Support for invokable listeners (using the ``__invoke()`` method) was introduced in Symfony 4.4.
336+
333337
Doctrine Lifecycle Subscribers
334338
------------------------------
335339

messenger.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,10 +1448,12 @@ In addition to middleware, Messenger also dispatches several events. You can
14481448
:doc:`create an event listener </event_dispatcher>` to hook into various parts
14491449
of the process. For each, the event class is the event name:
14501450

1451+
* :class:`Symfony\\Component\\Messenger\\Event\\WorkerStartedEvent`
1452+
* :class:`Symfony\\Component\\Messenger\\Event\\WorkerMessageReceivedEvent`
14511453
* :class:`Symfony\\Component\\Messenger\\Event\\SendMessageToTransportsEvent`
14521454
* :class:`Symfony\\Component\\Messenger\\Event\\WorkerMessageFailedEvent`
14531455
* :class:`Symfony\\Component\\Messenger\\Event\\WorkerMessageHandledEvent`
1454-
* :class:`Symfony\\Component\\Messenger\\Event\\WorkerMessageReceivedEvent`
1456+
* :class:`Symfony\\Component\\Messenger\\Event\\WorkerRunningEvent`
14551457
* :class:`Symfony\\Component\\Messenger\\Event\\WorkerStoppedEvent`
14561458

14571459
Multiple Buses, Command & Event Buses

reference/forms/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Form Types Reference
3535
types/datetime
3636
types/time
3737
types/birthday
38+
types/week
3839

3940
types/checkbox
4041
types/file

reference/forms/types/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Date and Time Fields
3434
* :doc:`DateTimeType </reference/forms/types/datetime>`
3535
* :doc:`TimeType </reference/forms/types/time>`
3636
* :doc:`BirthdayType </reference/forms/types/birthday>`
37+
* :doc:`WeekType </reference/forms/types/week>`
3738

3839
Other Fields
3940
~~~~~~~~~~~~
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
weeks
2+
~~~~~
3+
4+
**type**: ``array`` **default**: 1 to 53
5+
6+
List of weeks available to the week field type. This option is only relevant
7+
when the ``widget`` option is set to ``choice``.

reference/forms/types/week.rst

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
.. index::
2+
single: Forms; Fields; WeekType
3+
4+
WeekType Field
5+
==============
6+
7+
.. versionadded:: 4.4
8+
9+
The ``WeekType`` type was introduced in Symfony 4.4.
10+
11+
This field type allows the user to modify data that represents a specific
12+
`ISO 8601`_ week number (e.g. ``1984-W05``).
13+
14+
Can be rendered as a text input or select tags. The underlying format of
15+
the data can be a string or an array.
16+
17+
+----------------------+-----------------------------------------------------------------------------+
18+
| Underlying Data Type | can be a string, or array (see the ``input`` option) |
19+
+----------------------+-----------------------------------------------------------------------------+
20+
| Rendered as | single text box, two text boxes or two select fields |
21+
+----------------------+-----------------------------------------------------------------------------+
22+
| Options | - `choice_translation_domain`_ |
23+
| | - `placeholder`_ |
24+
| | - `html5`_ |
25+
| | - `input`_ |
26+
| | - `widget`_ |
27+
| | - `weeks`_ |
28+
| | - `years`_ |
29+
+----------------------+-----------------------------------------------------------------------------+
30+
| Overridden options | - `compound`_ |
31+
| | - `empty_data`_ |
32+
| | - `error_bubbling`_ |
33+
+----------------------+-----------------------------------------------------------------------------+
34+
| Inherited | - `attr`_ |
35+
| options | - `data`_ |
36+
| | - `disabled`_ |
37+
| | - `help`_ |
38+
| | - `help_attr`_ |
39+
| | - `help_html`_ |
40+
| | - `inherit_data`_ |
41+
| | - `invalid_message`_ |
42+
| | - `invalid_message_parameters`_ |
43+
| | - `mapped`_ |
44+
| | - `row_attr`_ |
45+
+----------------------+-----------------------------------------------------------------------------+
46+
| Parent type | :doc:`FormType </reference/forms/types/form>` |
47+
+----------------------+-----------------------------------------------------------------------------+
48+
| Class | :class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\WeekType` |
49+
+----------------------+-----------------------------------------------------------------------------+
50+
51+
.. include:: /reference/forms/types/options/_debug_form.rst.inc
52+
53+
Field Options
54+
-------------
55+
56+
.. include:: /reference/forms/types/options/choice_translation_domain.rst.inc
57+
58+
placeholder
59+
~~~~~~~~~~~
60+
61+
**type**: ``string`` | ``array``
62+
63+
If your widget option is set to ``choice``, then this field will be represented
64+
as a series of ``select`` boxes. When the placeholder value is a string,
65+
it will be used as the **blank value** of all select boxes::
66+
67+
use Symfony\Component\Form\Extension\Core\Type\WeekType;
68+
69+
$builder->add('startWeek', WeekType::class, [
70+
'placeholder' => 'Select a value',
71+
]);
72+
73+
Alternatively, you can use an array that configures different placeholder
74+
values for the year and week fields::
75+
76+
use Symfony\Component\Form\Extension\Core\Type\WeekType;
77+
78+
$builder->add('startDateTime', WeekType::class, [
79+
'placeholder' => [
80+
'year' => 'Year',
81+
'week' => 'Week',
82+
]
83+
]);
84+
85+
.. include:: /reference/forms/types/options/html5.rst.inc
86+
87+
input
88+
~~~~~
89+
90+
**type**: ``string`` **default**: ``array``
91+
92+
The format of the *input* data - i.e. the format that the date is stored
93+
on your underlying object. Valid values are:
94+
95+
* ``string`` (e.g. ``"2011-W17"``)
96+
* ``array`` (e.g. ``[2011, 17]``)
97+
98+
The value that comes back from the form will also be normalized back into
99+
this format.
100+
101+
widget
102+
~~~~~~
103+
104+
**type**: ``string`` **default**: ``choice``
105+
106+
The basic way in which this field should be rendered. Can be one of the
107+
following:
108+
109+
* ``choice``: renders two select inputs;
110+
* ``text``: renders a two field input of type ``text`` (year and week);
111+
* ``single_text``: renders a single input of type ``week``.
112+
113+
years
114+
~~~~~
115+
116+
**type**: ``array`` **default**: ten years before to ten years after the
117+
current year
118+
119+
List of years available to the year field type. This option is only relevant
120+
when the ``widget`` option is set to ``choice``.
121+
122+
.. include:: /reference/forms/types/options/weeks.rst.inc
123+
124+
Overridden Options
125+
------------------
126+
127+
.. include:: /reference/forms/types/options/compound_type.rst.inc
128+
129+
.. include:: /reference/forms/types/options/empty_data.rst.inc
130+
:end-before: DEFAULT_PLACEHOLDER
131+
132+
The actual default value of this option depends on other field options:
133+
134+
* If ``widget`` is ``single_text``, then ``''`` (empty string);
135+
* Otherwise ``[]`` (empty array).
136+
137+
.. include:: /reference/forms/types/options/empty_data.rst.inc
138+
:start-after: DEFAULT_PLACEHOLDER
139+
140+
error_bubbling
141+
~~~~~~~~~~~~~~
142+
143+
**default**: ``false``
144+
145+
Inherited Options
146+
-----------------
147+
148+
These options inherit from the :doc:`FormType </reference/forms/types/form>`:
149+
150+
.. include:: /reference/forms/types/options/attr.rst.inc
151+
152+
.. include:: /reference/forms/types/options/data.rst.inc
153+
154+
.. include:: /reference/forms/types/options/disabled.rst.inc
155+
156+
.. include:: /reference/forms/types/options/help.rst.inc
157+
158+
.. include:: /reference/forms/types/options/help_attr.rst.inc
159+
160+
.. include:: /reference/forms/types/options/help_html.rst.inc
161+
162+
.. include:: /reference/forms/types/options/inherit_data.rst.inc
163+
164+
.. include:: /reference/forms/types/options/invalid_message.rst.inc
165+
166+
.. include:: /reference/forms/types/options/invalid_message_parameters.rst.inc
167+
168+
.. include:: /reference/forms/types/options/mapped.rst.inc
169+
170+
.. include:: /reference/forms/types/options/row_attr.rst.inc
171+
172+
Field Variables
173+
---------------
174+
175+
+----------+------------+----------------------------------------------------------------------+
176+
| Variable | Type | Usage |
177+
+==========+============+======================================================================+
178+
| widget | ``mixed`` | The value of the `widget`_ option. |
179+
+----------+------------+----------------------------------------------------------------------+
180+
| type | ``string`` | Only present when widget is ``single_text`` and HTML5 is activated, |
181+
| | | contains the input type to use (``datetime``, ``date`` or ``time``). |
182+
+----------+------------+----------------------------------------------------------------------+
183+
184+
.. _`ISO 8601`: https://en.wikipedia.org/wiki/ISO_8601

0 commit comments

Comments
 (0)