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

Appearance settings

Commit 58052e9

Browse filesBrowse files
committed
feature #49291 [Serializer] Add methods getSupportedTypes to allow better performance (tucksaun, nicolas-grekas)
This PR was merged into the 6.3 branch. Discussion ---------- [Serializer] Add methods `getSupportedTypes` to allow better performance | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | yes (new method in the interfaces, one interface deprecated) | License | MIT | Doc PR | to be written The PRs allows normalizers or denormalizers to expose their supported types and the associated cacheability to the Serializer. With this info, even if the `supports*` call is not cacheable, the Serializer can skip a ton of method calls to `supports*` improving performance substaintially in some cases: ![Screenshot 2023-02-02 at 15 46 49](https://user-images.githubusercontent.com/870118/217378926-03aa77e8-d80e-4bdd-b5dc-acc3602b70b3.png) <details> <summary>I found this design while working on a customer project performance (a big app built around API Platform): we reached the point where the slowest part of main application endpoint was `Symfony\Component\Serializer\Serializer::getNormalizer`.</summary> After some digging, we found out we were experiencing the conjunction of two phenomenons: - the application is quite complex and returns deep nested and repeating structures, exposing the underlying bottleneck; - and a lot of custom non-cacheable normalizers. Because most of the normalizers are not cacheable, the Serializer has to call every normalizer over and over again leading `getNormalizer` to account for 20% of the total wall time: ![Screenshot 2023-02-07 at 16 56 02](https://user-images.githubusercontent.com/870118/217375680-e7d33db2-fd6a-4ef0-b8d0-34d0eac8cf09.png) We first tried to improve cacheability based on context without much success, then an approach similar to #45779 with some success but still feeling this could be faster. We then thought that even if the `supportsNormalization` could not be cached (because of the context), maybe we could avoid the calls at the origin by letting the `Normalizers` expose the types they support and came to this PR with pretty good results. </details> The perfornance improvement was only measured by adapting Symfony's normalizers as well as the project ones, proper third party normalizers updates should improve performance even more. This should effectively replaces the `CacheableSupportsMethodInterface` as the cacheability can now be returned by `getSupportedTypes`. Commits ------- e5af24a [Serializer] Add wildcard support to getSupportedTypes() 400685a [Serializer] Add methods `getSupportedTypes` to allow better performance
2 parents a7e0b05 + e5af24a commit 58052e9
Copy full SHA for 58052e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

41 files changed

+619
-78
lines changed

‎.github/expected-missing-return-types.diff

Copy file name to clipboardExpand all lines: .github/expected-missing-return-types.diff
+23-31Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8130,6 +8130,7 @@ index 1924b1ddb0..62c58c8e8b 100644
81308130
$annotatedClasses = [];
81318131
diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/ControllerArgumentValueResolverPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/ControllerArgumentValueResolverPass.php
81328132
index dff3e248ae..381db9aa8f 100644
8133+
index 6e00840c7e..8e69c81c23 100644
81338134
--- a/src/Symfony/Component/HttpKernel/DependencyInjection/ControllerArgumentValueResolverPass.php
81348135
+++ b/src/Symfony/Component/HttpKernel/DependencyInjection/ControllerArgumentValueResolverPass.php
81358136
@@ -34,5 +34,5 @@ class ControllerArgumentValueResolverPass implements CompilerPassInterface
@@ -11254,32 +11255,32 @@ index fc6336ebdb..e13a834930 100644
1125411255
{
1125511256
if (1 > \func_num_args()) {
1125611257
diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
11257-
index 52e985815b..e7d0493152 100644
11258+
index 7d138b0b26..03e28f9d20 100644
1125811259
--- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
1125911260
+++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
11260-
@@ -210,5 +210,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
11261+
@@ -215,5 +215,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
1126111262
* @throws LogicException if the 'allow_extra_attributes' context variable is false and no class metadata factory is provided
1126211263
*/
1126311264
- protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false)
1126411265
+ protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false): array|bool
1126511266
{
1126611267
$allowExtraAttributes = $context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES];
11267-
@@ -260,5 +260,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
11268+
@@ -265,5 +265,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
1126811269
* @return bool
1126911270
*/
1127011271
- protected function isAllowedAttribute(object|string $classOrObject, string $attribute, string $format = null, array $context = [])
1127111272
+ protected function isAllowedAttribute(object|string $classOrObject, string $attribute, string $format = null, array $context = []): bool
1127211273
{
1127311274
$ignoredAttributes = $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES];
11274-
@@ -311,5 +311,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
11275+
@@ -316,5 +316,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
1127511276
* @throws MissingConstructorArgumentException
1127611277
*/
1127711278
- protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null)
1127811279
+ protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null): object
1127911280
{
1128011281
if (null !== $object = $this->extractObjectToPopulate($class, $context, self::OBJECT_TO_POPULATE)) {
1128111282
diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
11282-
index a02a46b941..aedfd67c2e 100644
11283+
index 75fe3a5cb1..a28dd40568 100644
1128311284
--- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
1128411285
+++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
1128511286
@@ -139,10 +139,10 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
@@ -11321,46 +11322,36 @@ index a02a46b941..aedfd67c2e 100644
1132111322
- public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */)
1132211323
+ public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */): bool
1132311324
{
11324-
return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type));
11325+
return class_exists($type) || (interface_exists($type, false) && null !== $this->classDiscriminatorResolver?->getMappingForClass($type));
1132511326
}
1132611327

1132711328
- public function denormalize(mixed $data, string $type, string $format = null, array $context = [])
1132811329
+ public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
1132911330
{
1133011331
if (!isset($context['cache_key'])) {
11331-
diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizerAwareTrait.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizerAwareTrait.php
11332-
index c5cc86ecf6..c65534fafb 100644
11333-
--- a/src/Symfony/Component/Serializer/Normalizer/DenormalizerAwareTrait.php
11334-
+++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizerAwareTrait.php
11335-
@@ -25,5 +25,5 @@ trait DenormalizerAwareTrait
11336-
* @return void
11337-
*/
11338-
- public function setDenormalizer(DenormalizerInterface $denormalizer)
11339-
+ public function setDenormalizer(DenormalizerInterface $denormalizer): void
11340-
{
11341-
$this->denormalizer = $denormalizer;
1134211332
diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php
11343-
index 1786d6fff1..04a2e62ed2 100644
11333+
index 1d83b2da11..1c632f42bf 100644
1134411334
--- a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php
1134511335
+++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php
11346-
@@ -45,5 +45,5 @@ interface DenormalizerInterface
11336+
@@ -47,5 +47,5 @@ interface DenormalizerInterface
1134711337
* @throws ExceptionInterface Occurs for all the other cases of errors
1134811338
*/
1134911339
- public function denormalize(mixed $data, string $type, string $format = null, array $context = []);
1135011340
+ public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed;
1135111341

1135211342
/**
11353-
@@ -57,4 +57,4 @@ interface DenormalizerInterface
11343+
@@ -64,5 +64,5 @@ interface DenormalizerInterface
1135411344
* @return bool
1135511345
*/
1135611346
- public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */);
1135711347
+ public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */): bool;
11358-
}
11348+
11349+
/**
1135911350
diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php
11360-
index e08dd5d9ec..cc282ae4bb 100644
11351+
index 2719c8b52c..1112f7f3cc 100644
1136111352
--- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php
1136211353
+++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php
11363-
@@ -138,5 +138,5 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
11354+
@@ -148,5 +148,5 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
1136411355
* @return void
1136511356
*/
1136611357
- protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = [])
@@ -11379,38 +11370,39 @@ index 40a4fa0e8c..a1e2749aae 100644
1137911370
{
1138011371
$this->normalizer = $normalizer;
1138111372
diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php
11382-
index cb43d78cc7..d215ffe997 100644
11373+
index d6d0707ff5..9953ad3005 100644
1138311374
--- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php
1138411375
+++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php
11385-
@@ -37,5 +37,5 @@ interface NormalizerInterface
11376+
@@ -39,5 +39,5 @@ interface NormalizerInterface
1138611377
* @throws ExceptionInterface Occurs for all the other cases of errors
1138711378
*/
1138811379
- public function normalize(mixed $object, string $format = null, array $context = []);
1138911380
+ public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null;
1139011381

1139111382
/**
11392-
@@ -48,4 +48,4 @@ interface NormalizerInterface
11383+
@@ -55,5 +55,5 @@ interface NormalizerInterface
1139311384
* @return bool
1139411385
*/
1139511386
- public function supportsNormalization(mixed $data, string $format = null /* , array $context = [] */);
1139611387
+ public function supportsNormalization(mixed $data, string $format = null /* , array $context = [] */): bool;
11397-
}
11388+
11389+
/**
1139811390
diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
11399-
index 8018cb7a49..aa06b9c50b 100644
11391+
index 140e89c6a1..f77348252b 100644
1140011392
--- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
1140111393
+++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
11402-
@@ -133,5 +133,5 @@ class ObjectNormalizer extends AbstractObjectNormalizer
11394+
@@ -143,5 +143,5 @@ class ObjectNormalizer extends AbstractObjectNormalizer
1140311395
* @return void
1140411396
*/
1140511397
- protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = [])
1140611398
+ protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = []): void
1140711399
{
1140811400
try {
1140911401
diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php
11410-
index 3dd734055d..cbc0e86d27 100644
11402+
index 645ba74290..d960bf4b20 100644
1141111403
--- a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php
1141211404
+++ b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php
11413-
@@ -175,5 +175,5 @@ class PropertyNormalizer extends AbstractObjectNormalizer
11405+
@@ -185,5 +185,5 @@ class PropertyNormalizer extends AbstractObjectNormalizer
1141411406
* @return void
1141511407
*/
1141611408
- protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = [])

‎src/Symfony/Component/Messenger/Transport/Serialization/Normalizer/FlattenExceptionNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Serialization/Normalizer/FlattenExceptionNormalizer.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public function normalize(mixed $object, string $format = null, array $context =
4545
return $normalized;
4646
}
4747

48+
public function getSupportedTypes(?string $format): array
49+
{
50+
return [
51+
FlattenException::class => false,
52+
];
53+
}
54+
4855
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
4956
{
5057
return $data instanceof FlattenException && ($context[Serializer::MESSENGER_SERIALIZATION_CONTEXT] ?? false);

‎src/Symfony/Component/Serializer/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ CHANGELOG
66

77
* Add `XmlEncoder::SAVE_OPTIONS` context option
88
* Add `BackedEnumNormalizer::ALLOW_INVALID_VALUES` context option
9+
* Add method `getSupportedTypes(?string $format)` to `NormalizerInterface` and `DenormalizerInterface`
910
* Deprecate `MissingConstructorArgumentsException` in favor of `MissingConstructorArgumentException`
11+
* Deprecate `CacheableSupportsMethodInterface` in favor of the new `getSupportedTypes(?string $format)` methods
1012

1113
6.2
1214
---

‎src/Symfony/Component/Serializer/Debug/TraceableNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Debug/TraceableNormalizer.php
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ public function __construct(
3333
private NormalizerInterface|DenormalizerInterface $normalizer,
3434
private SerializerDataCollector $dataCollector,
3535
) {
36+
if (!method_exists($normalizer, 'getSupportedTypes')) {
37+
trigger_deprecation('symfony/serializer', '6.3', 'Not implementing the "NormalizerInterface::getSupportedTypes()" in "%s" is deprecated.', get_debug_type($normalizer));
38+
}
39+
}
40+
41+
public function getSupportedTypes(?string $format): array
42+
{
43+
// @deprecated remove condition in 7.0
44+
if (!method_exists($this->normalizer, 'getSupportedTypes')) {
45+
return ['*' => $this->normalizer instanceof CacheableSupportsMethodInterface && $this->normalizer->hasCacheableSupportsMethod()];
46+
}
47+
48+
return $this->normalizer->getSupportedTypes($format);
3649
}
3750

3851
public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
@@ -114,8 +127,13 @@ public function setDenormalizer(DenormalizerInterface $denormalizer): void
114127
$this->normalizer->setDenormalizer($denormalizer);
115128
}
116129

130+
/**
131+
* @deprecated since Symfony 6.3, use "getSupportedTypes()" instead
132+
*/
117133
public function hasCacheableSupportsMethod(): bool
118134
{
135+
trigger_deprecation('symfony/serializer', '6.3', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
136+
119137
return $this->normalizer instanceof CacheableSupportsMethodInterface && $this->normalizer->hasCacheableSupportsMethod();
120138
}
121139

‎src/Symfony/Component/Serializer/Debug/TraceableSerializer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Debug/TraceableSerializer.php
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Serializer\DataCollector\SerializerDataCollector;
1515
use Symfony\Component\Serializer\Encoder\DecoderInterface;
1616
use Symfony\Component\Serializer\Encoder\EncoderInterface;
17+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
1718
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
1819
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
1920
use Symfony\Component\Serializer\SerializerInterface;
@@ -29,13 +30,13 @@ class TraceableSerializer implements SerializerInterface, NormalizerInterface, D
2930
{
3031
public const DEBUG_TRACE_ID = 'debug_trace_id';
3132

32-
/**
33-
* @param SerializerInterface&NormalizerInterface&DenormalizerInterface&EncoderInterface&DecoderInterface $serializer
34-
*/
3533
public function __construct(
36-
private SerializerInterface $serializer,
34+
private SerializerInterface&NormalizerInterface&DenormalizerInterface&EncoderInterface&DecoderInterface $serializer,
3735
private SerializerDataCollector $dataCollector,
3836
) {
37+
if (!method_exists($serializer, 'getSupportedTypes')) {
38+
trigger_deprecation('symfony/serializer', '6.3', 'Not implementing the "NormalizerInterface::getSupportedTypes()" in "%s" is deprecated.', get_debug_type($serializer));
39+
}
3940
}
4041

4142
public function serialize(mixed $data, string $format, array $context = []): string
@@ -128,6 +129,16 @@ public function decode(string $data, string $format, array $context = []): mixed
128129
return $result;
129130
}
130131

132+
public function getSupportedTypes(?string $format): array
133+
{
134+
// @deprecated remove condition in 7.0
135+
if (!method_exists($this->serializer, 'getSupportedTypes')) {
136+
return ['*' => $this->serializer instanceof CacheableSupportsMethodInterface && $this->serializer->hasCacheableSupportsMethod()];
137+
}
138+
139+
return $this->serializer->getSupportedTypes($format);
140+
}
141+
131142
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
132143
{
133144
return $this->serializer->supportsNormalization($data, $format, $context);

‎src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,13 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
150150
}
151151
}
152152

153+
/**
154+
* @deprecated since Symfony 6.3, use "getSupportedTypes()" instead
155+
*/
153156
public function hasCacheableSupportsMethod(): bool
154157
{
158+
trigger_deprecation('symfony/serializer', '6.3', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
159+
155160
return false;
156161
}
157162

‎src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ abstract protected function getAttributeValue(object $object, string $attribute,
300300
*/
301301
public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */)
302302
{
303-
return class_exists($type) || (interface_exists($type, false) && $this->classDiscriminatorResolver && null !== $this->classDiscriminatorResolver->getMappingForClass($type));
303+
return class_exists($type) || (interface_exists($type, false) && null !== $this->classDiscriminatorResolver?->getMappingForClass($type));
304304
}
305305

306306
public function denormalize(mixed $data, string $type, string $format = null, array $context = [])

‎src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,25 @@ class ArrayDenormalizer implements ContextAwareDenormalizerInterface, Denormaliz
2727
{
2828
use DenormalizerAwareTrait;
2929

30+
public function setDenormalizer(DenormalizerInterface $denormalizer): void
31+
{
32+
if (!method_exists($denormalizer, 'getSupportedTypes')) {
33+
trigger_deprecation('symfony/serializer', '6.3', 'Not implementing the "DenormalizerInterface::getSupportedTypes()" in "%s" is deprecated.', get_debug_type($denormalizer));
34+
}
35+
36+
$this->denormalizer = $denormalizer;
37+
}
38+
39+
public function getSupportedTypes(?string $format): array
40+
{
41+
// @deprecated remove condition in 7.0
42+
if (!method_exists($this->denormalizer, 'getSupportedTypes')) {
43+
return ['*' => $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod()];
44+
}
45+
46+
return $this->denormalizer->getSupportedTypes($format);
47+
}
48+
3049
/**
3150
* @throws NotNormalizableValueException
3251
*/
@@ -69,8 +88,13 @@ public function supportsDenormalization(mixed $data, string $type, string $forma
6988
&& $this->denormalizer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
7089
}
7190

91+
/**
92+
* @deprecated since Symfony 6.3, use "getSupportedTypes()" instead
93+
*/
7294
public function hasCacheableSupportsMethod(): bool
7395
{
96+
trigger_deprecation('symfony/serializer', '6.3', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
97+
7498
return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod();
7599
}
76100
}

‎src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ final class BackedEnumNormalizer implements NormalizerInterface, DenormalizerInt
2727
*/
2828
public const ALLOW_INVALID_VALUES = 'allow_invalid_values';
2929

30+
public function getSupportedTypes(?string $format): array
31+
{
32+
return [
33+
\BackedEnum::class => true,
34+
];
35+
}
36+
3037
public function normalize(mixed $object, string $format = null, array $context = []): int|string
3138
{
3239
if (!$object instanceof \BackedEnum) {
@@ -78,8 +85,13 @@ public function supportsDenormalization(mixed $data, string $type, string $forma
7885
return is_subclass_of($type, \BackedEnum::class);
7986
}
8087

88+
/**
89+
* @deprecated since Symfony 6.3, use "getSupportedTypes()" instead
90+
*/
8191
public function hasCacheableSupportsMethod(): bool
8292
{
93+
trigger_deprecation('symfony/serializer', '6.3', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
94+
8395
return true;
8496
}
8597
}

‎src/Symfony/Component/Serializer/Normalizer/CacheableSupportsMethodInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/CacheableSupportsMethodInterface.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* supports*() methods will be cached by type and format.
2020
*
2121
* @author Kévin Dunglas <dunglas@gmail.com>
22+
*
23+
* @deprecated since Symfony 6.3, implement "getSupportedTypes(?string $format)" instead
2224
*/
2325
interface CacheableSupportsMethodInterface
2426
{

‎src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ConstraintViolationListNormalizer.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ public function __construct(array $defaultContext = [], NameConverterInterface $
3939
$this->nameConverter = $nameConverter;
4040
}
4141

42+
public function getSupportedTypes(?string $format): array
43+
{
44+
return [
45+
ConstraintViolationListInterface::class => __CLASS__ === static::class || $this->hasCacheableSupportsMethod(),
46+
];
47+
}
48+
4249
public function normalize(mixed $object, string $format = null, array $context = []): array
4350
{
4451
if (\array_key_exists(self::PAYLOAD_FIELDS, $context)) {
@@ -109,8 +116,13 @@ public function supportsNormalization(mixed $data, string $format = null /* , ar
109116
return $data instanceof ConstraintViolationListInterface;
110117
}
111118

119+
/**
120+
* @deprecated since Symfony 6.3, use "getSupportedTypes()" instead
121+
*/
112122
public function hasCacheableSupportsMethod(): bool
113123
{
124+
trigger_deprecation('symfony/serializer', '6.3', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);
125+
114126
return __CLASS__ === static::class;
115127
}
116128
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.