Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44fe3b2

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Notifier] Update FreeMobile DSN [Serializer] Allow to provide (de)normalization context in mapping
2 parents 4d24ada + 7dcd023 commit 44fe3b2

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
@@ -67,7 +67,7 @@ AmazonSns ``symfony/amazon-sns-notifier`` ``sns://ACCESS_KEY:SECRET_
6767
Clickatell ``symfony/clickatell-notifier`` ``clickatell://ACCESS_TOKEN@default?from=FROM``
6868
Esendex ``symfony/esendex-notifier`` ``esendex://USER_NAME:PASSWORD@default?accountreference=ACCOUNT_REFERENCE&from=FROM``
6969
FakeSms ``symfony/fake-sms-notifier`` ``fakesms+email://MAILER_SERVICE_ID?to=TO&from=FROM`` or ``fakesms+logger://default``
70-
FreeMobile ``symfony/free-mobile-notifier`` ``freemobile://LOGIN:PASSWORD@default?phone=PHONE``
70+
FreeMobile ``symfony/free-mobile-notifier`` ``freemobile://LOGIN:API_KEY@default?phone=PHONE``
7171
GatewayApi ``symfony/gateway-api-notifier`` ``gatewayapi://TOKEN@default?from=FROM``
7272
Infobip ``symfony/infobip-notifier`` ``infobip://AUTH_TOKEN@HOST?from=FROM``
7373
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
@@ -157,6 +157,109 @@ configuration:
157157
;
158158
};
159159
160+
You can also specify the context on a per-property basis::
161+
162+
.. configuration-block::
163+
164+
.. code-block:: php-annotations
165+
166+
namespace App\Model;
167+
168+
use Symfony\Component\Serializer\Annotation\Context;
169+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
170+
171+
class Person
172+
{
173+
/**
174+
* @Context({ DateTimeNormalizer::FORMAT_KEY = 'Y-m-d' })
175+
*/
176+
public $createdAt;
177+
178+
// ...
179+
}
180+
181+
.. code-block:: php-attributes
182+
183+
namespace App\Model;
184+
185+
use Symfony\Component\Serializer\Annotation\Context;
186+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
187+
188+
class Person
189+
{
190+
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
191+
public $createdAt;
192+
193+
// ...
194+
}
195+
196+
.. code-block:: yaml
197+
198+
App\Model\Person:
199+
attributes:
200+
createdAt:
201+
context:
202+
datetime_format: 'Y-m-d'
203+
204+
.. code-block:: xml
205+
206+
<?xml version="1.0" encoding="UTF-8" ?>
207+
<serializer xmlns="http://symfony.com/schema/dic/serializer-mapping"
208+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
209+
xsi:schemaLocation="http://symfony.com/schema/dic/serializer-mapping
210+
https://symfony.com/schema/dic/serializer-mapping/serializer-mapping-1.0.xsd"
211+
>
212+
<class name="App\Model\Person">
213+
<attribute name="createdAt">
214+
<context>
215+
<entry name="datetime_format">Y-m-d</entry>
216+
</context>
217+
</attribute>
218+
</class>
219+
</serializer>
220+
221+
Use the options to specify context specific to normalization or denormalization::
222+
223+
namespace App\Model;
224+
225+
use Symfony\Component\Serializer\Annotation\Context;
226+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
227+
228+
class Person
229+
{
230+
#[Context(
231+
normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'],
232+
denormalizationContext: [DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339],
233+
)]
234+
public $createdAt;
235+
236+
// ...
237+
}
238+
239+
You can also restrict the usage of a context to some groups::
240+
241+
namespace App\Model;
242+
243+
use Symfony\Component\Serializer\Annotation\Context;
244+
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
245+
246+
class Person
247+
{
248+
#[Serializer\Groups(['extended'])]
249+
#[Serializer\Context([DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339])]
250+
#[Serializer\Context(
251+
context: [DateTimeNormalizer::FORMAT_KEY => \DateTime::RFC3339_EXTENDED],
252+
groups: ['extended'],
253+
)]
254+
public $createdAt;
255+
256+
// ...
257+
}
258+
259+
The attribute/annotation can be repeated as much as needed on a single property.
260+
Context without group is always applied first. Then context for the matching
261+
groups are merged in the provided order.
262+
160263
.. _serializer-using-serialization-groups-annotations:
161264
.. _serializer-using-serialization-groups-attributes:
162265

0 commit comments

Comments
 (0)