Skip to content

Commit 6b9fafb

Browse files
committed
feature #43982 [Messenger][Serializer] Deprecate "context aware" interfaces (mtarld)
This PR was merged into the 6.1 branch. Discussion ---------- [Messenger][Serializer] Deprecate "context aware" interfaces | Q | A | ------------- | --- | Branch? | 6.1 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | | License | MIT | Doc PR | TODO In `supports*` methods, we are really often relying on serialization context. Previously (~2017), in order to have the context in these methods (and be BC compatible), new interfaces were introduced: - `ContextAwareNormalizerInterface` - `ContextAwareDenormalizerInterface` - `ContextAwareEncoderInterface` - `ContextAwareDecoderInterface` But right now, thanks to the `DebugClassLoader`, we're able to have an upgrade path where the regular interfaces: - `NormalizerInterface` - `DenormalizerInterface` - `EncoderInterface` - `DecoderInterface` can be updated to rely on the serialization context. Therefore, the "context aware" interfaces could be deprecated in favor of "regular" ones (and then save 4 interfaces in 7.0). Commits ------- ab72f80 Merge context aware interfaces into regular ones
2 parents 098ff62 + ab72f80 commit 6b9fafb

36 files changed

+146
-58
lines changed

UPGRADE-6.1.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
UPGRADE FROM 6.0 to 6.1
2+
=======================
3+
4+
Serializer
5+
----------
6+
7+
* Deprecate `ContextAwareNormalizerInterface`, use `NormalizerInterface` instead
8+
* Deprecate `ContextAwareDenormalizerInterface`, use `DenormalizerInterface` instead
9+
* Deprecate `ContextAwareEncoderInterface`, use `EncoderInterface` instead
10+
* Deprecate `ContextAwareDecoderInterface`, use `DecoderInterface` instead

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Deprecate `ContextAwareNormalizerInterface`, use `NormalizerInterface` instead
8+
* Deprecate `ContextAwareDenormalizerInterface`, use `DenormalizerInterface` instead
9+
* Deprecate `ContextAwareEncoderInterface`, use `EncoderInterface` instead
10+
* Deprecate `ContextAwareDecoderInterface`, use `DecoderInterface` instead
11+
412
6.0
513
---
614

src/Symfony/Component/Serializer/Encoder/ContextAwareDecoderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* Adds the support of an extra $context parameter for the supportsDecoding method.
1616
*
1717
* @author Kévin Dunglas <dunglas@gmail.com>
18+
*
19+
* @deprecated since symfony/serializer 6.1, use DecoderInterface instead
1820
*/
1921
interface ContextAwareDecoderInterface extends DecoderInterface
2022
{

src/Symfony/Component/Serializer/Encoder/ContextAwareEncoderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* Adds the support of an extra $context parameter for the supportsEncoding method.
1616
*
1717
* @author Kévin Dunglas <dunglas@gmail.com>
18+
*
19+
* @deprecated since symfony/serializer 6.1, use EncoderInterface instead
1820
*/
1921
interface ContextAwareEncoderInterface extends EncoderInterface
2022
{

src/Symfony/Component/Serializer/Encoder/CsvEncoder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ public function encode(mixed $data, string $format, array $context = []): string
123123

124124
/**
125125
* {@inheritdoc}
126+
*
127+
* @param array $context
126128
*/
127-
public function supportsEncoding(string $format): bool
129+
public function supportsEncoding(string $format /*, array $context = [] */): bool
128130
{
129131
return self::FORMAT === $format;
130132
}
@@ -209,8 +211,10 @@ public function decode(string $data, string $format, array $context = []): mixed
209211

210212
/**
211213
* {@inheritdoc}
214+
*
215+
* @param array $context
212216
*/
213-
public function supportsDecoding(string $format): bool
217+
public function supportsDecoding(string $format /*, array $context = [] */): bool
214218
{
215219
return self::FORMAT === $format;
216220
}

src/Symfony/Component/Serializer/Encoder/DecoderInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ public function decode(string $data, string $format, array $context = []);
4040
* Checks whether the deserializer can decode from given format.
4141
*
4242
* @param string $format Format name
43+
* @param array $context Options that decoders have access to
4344
*
4445
* @return bool
4546
*/
46-
public function supportsDecoding(string $format);
47+
public function supportsDecoding(string $format /*, array $context = [] */);
4748
}

src/Symfony/Component/Serializer/Encoder/EncoderInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public function encode(mixed $data, string $format, array $context = []): string
3232
/**
3333
* Checks whether the serializer can encode to given format.
3434
*
35-
* @param string $format Format name
35+
* @param string $format Format name
36+
* @param array $context Options that normalizers/encoders have access to
3637
*/
37-
public function supportsEncoding(string $format): bool;
38+
public function supportsEncoding(string $format /*, array $context = [] */): bool;
3839
}

src/Symfony/Component/Serializer/Encoder/JsonDecode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ public function decode(string $data, string $format, array $context = []): mixed
9595

9696
/**
9797
* {@inheritdoc}
98+
*
99+
* @param array $context
98100
*/
99-
public function supportsDecoding(string $format): bool
101+
public function supportsDecoding(string $format /*, array $context = [] */): bool
100102
{
101103
return JsonEncoder::FORMAT === $format;
102104
}

src/Symfony/Component/Serializer/Encoder/JsonEncode.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ public function encode(mixed $data, string $format, array $context = []): string
5757

5858
/**
5959
* {@inheritdoc}
60+
*
61+
* @param array $context
6062
*/
61-
public function supportsEncoding(string $format): bool
63+
public function supportsEncoding(string $format /*, array $context = [] */): bool
6264
{
6365
return JsonEncoder::FORMAT === $format;
6466
}

src/Symfony/Component/Serializer/Encoder/JsonEncoder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,20 @@ public function decode(string $data, string $format, array $context = []): mixed
4747

4848
/**
4949
* {@inheritdoc}
50+
*
51+
* @param array $context
5052
*/
51-
public function supportsEncoding(string $format): bool
53+
public function supportsEncoding(string $format /*, array $context = [] */): bool
5254
{
5355
return self::FORMAT === $format;
5456
}
5557

5658
/**
5759
* {@inheritdoc}
60+
*
61+
* @param array $context
5862
*/
59-
public function supportsDecoding(string $format): bool
63+
public function supportsDecoding(string $format /*, array $context = [] */): bool
6064
{
6165
return self::FORMAT === $format;
6266
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy