Skip to content

Commit c5bad2c

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: [Notifier] Update FreeMobile DSN [Serializer] Allow to provide (de)normalization context in mapping
2 parents 73aa358 + 44fe3b2 commit c5bad2c

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

components/serializer.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ normalized data, instead of the denormalizer re-creating them. Note that
229229
arrays of objects. Those will still be replaced when present in the normalized
230230
data.
231231

232+
Context
233+
-------
234+
235+
Many Serializer features can be configured :doc:`using a context </serializer#serializer-context>`.
236+
232237
.. _component-serializer-attributes-groups:
233238

234239
Attributes Groups

notifier.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ AmazonSns ``symfony/amazon-sns-notifier`` ``sns://ACCESS_KEY:SECRET_
6868
Clickatell ``symfony/clickatell-notifier`` ``clickatell://ACCESS_TOKEN@default?from=FROM``
6969
Esendex ``symfony/esendex-notifier`` ``esendex://USER_NAME:PASSWORD@default?accountreference=ACCOUNT_REFERENCE&from=FROM``
7070
FakeSms ``symfony/fake-sms-notifier`` ``fakesms+email://MAILER_SERVICE_ID?to=TO&from=FROM`` or ``fakesms+logger://default``
71-
FreeMobile ``symfony/free-mobile-notifier`` ``freemobile://LOGIN:PASSWORD@default?phone=PHONE``
71+
FreeMobile ``symfony/free-mobile-notifier`` ``freemobile://LOGIN:API_KEY@default?phone=PHONE``
7272
GatewayApi ``symfony/gateway-api-notifier`` ``gatewayapi://TOKEN@default?from=FROM``
7373
Infobip ``symfony/infobip-notifier`` ``infobip://AUTH_TOKEN@HOST?from=FROM``
7474
Iqsms ``symfony/iqsms-notifier`` ``iqsms://LOGIN:PASSWORD@default?from=FROM``

serializer.rst

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,109 @@ configuration:
155155
;
156156
};
157157
158+
You can also specify the context on a per-property basis::
159+
160+
.. configuration-block::
161+
162+
.. code-block:: php-annotations
163+
164+
namespace App\Model;
165+
166+
use Symfony\Component\Serializer\Annotation\Context;
167+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
168+
169+
class Person
170+
{
171+
/**
172+
* @Context({ DateTimeNormalizer::FORMAT_KEY = 'Y-m-d' })
173+
*/
174+
public $createdAt;
175+
176+
// ...
177+
}
178+
179+
.. code-block:: php-attributes
180+
181+
namespace App\Model;
182+
183+
use Symfony\Component\Serializer\Annotation\Context;
184+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
185+
186+
class Person
187+
{
188+
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
189+
public $createdAt;
190+
191+
// ...
192+
}
193+
194+
.. code-block:: yaml
195+
196+
App\Model\Person:
197+
attributes:
198+
createdAt:
199+
context:
200+
datetime_format: 'Y-m-d'
201+
202+
.. code-block:: xml
203+
204+
<?xml version="1.0" encoding="UTF-8" ?>
205+
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
206+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
207+
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping
208+
https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
209+
>
210+
<class name="App\Model\Person">
211+
<attribute name="createdAt">
212+
<context>
213+
<entry name="datetime_format">Y-m-d</entry>
214+
</context>
215+
</attribute>
216+
</class>
217+
</serializer>
218+
219+
Use the options to specify context specific to normalization or denormalization::
220+
221+
namespace App\Model;
222+
223+
use Symfony\Component\Serializer\Annotation\Context;
224+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
225+
226+
class Person
227+
{
228+
#[Context(
229+
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
230+
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339],
231+
)]
232+
public $createdAt;
233+
234+
// ...
235+
}
236+
237+
You can also restrict the usage of a context to some groups::
238+
239+
namespace App\Model;
240+
241+
use Symfony\Component\Serializer\Annotation\Context;
242+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
243+
244+
class Person
245+
{
246+
#[Serializer\Groups(['extended'])]
247+
#[Serializer\Context([DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339])]
248+
#[Serializer\Context(
249+
context: [DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339_EXTENDED],
250+
groups: ['extended'],
251+
)]
252+
public $createdAt;
253+
254+
// ...
255+
}
256+
257+
The attribute/annotation can be repeated as much as needed on a single property.
258+
Context without group is always applied first. Then context for the matching
259+
groups are merged in the provided order.
260+
158261
.. _serializer-using-context-builders:
159262

160263
Using Context Builders

0 commit comments

Comments
 (0)