diff --git a/src/Elasticsearch/Serializer/ItemNormalizer.php b/src/Elasticsearch/Serializer/ItemNormalizer.php index 582e9069044..74e9f5f7e97 100644 --- a/src/Elasticsearch/Serializer/ItemNormalizer.php +++ b/src/Elasticsearch/Serializer/ItemNormalizer.php @@ -90,6 +90,19 @@ public function supportsNormalization(mixed $data, string $format = null, array return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsNormalization($data, $format); } + public function getSupportedTypes($format): array + { + // @deprecated remove condition when support for symfony versions under 6.3 is dropped + if (!method_exists($this->decorated, 'getSupportedTypes')) { + return [ + DocumentNormalizer::FORMAT => null, + '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + ]; + } + + return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : []; + } + /** * {@inheritdoc} * diff --git a/src/GraphQl/Serializer/Exception/ErrorNormalizer.php b/src/GraphQl/Serializer/Exception/ErrorNormalizer.php index ca3323dcd6b..215b3cee685 100644 --- a/src/GraphQl/Serializer/Exception/ErrorNormalizer.php +++ b/src/GraphQl/Serializer/Exception/ErrorNormalizer.php @@ -39,4 +39,11 @@ public function supportsNormalization(mixed $data, string $format = null, array { return $data instanceof Error; } + + public function getSupportedTypes($format): array + { + return [ + Error::class => true, + ]; + } } diff --git a/src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php b/src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php index f64160d47d3..48c44035bd2 100644 --- a/src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php +++ b/src/GraphQl/Serializer/Exception/HttpExceptionNormalizer.php @@ -50,4 +50,11 @@ public function supportsNormalization(mixed $data, string $format = null, array { return $data instanceof Error && $data->getPrevious() instanceof HttpExceptionInterface; } + + public function getSupportedTypes($format): array + { + return [ + Error::class => false, + ]; + } } diff --git a/src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php b/src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php index 3cf0c26808d..01cc7a1afaf 100644 --- a/src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php +++ b/src/GraphQl/Serializer/Exception/RuntimeExceptionNormalizer.php @@ -44,4 +44,11 @@ public function supportsNormalization(mixed $data, string $format = null, array { return $data instanceof Error && $data->getPrevious() instanceof \RuntimeException; } + + public function getSupportedTypes($format): array + { + return [ + Error::class => false, + ]; + } } diff --git a/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php b/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php index 1fb6526ed47..95843d0aa50 100644 --- a/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php +++ b/src/GraphQl/Serializer/Exception/ValidationExceptionNormalizer.php @@ -77,4 +77,11 @@ public function supportsNormalization(mixed $data, string $format = null, array { return $data instanceof Error && $data->getPrevious() instanceof ValidationException; } + + public function getSupportedTypes($format): array + { + return [ + Error::class => false, + ]; + } } diff --git a/src/GraphQl/Serializer/ItemNormalizer.php b/src/GraphQl/Serializer/ItemNormalizer.php index f6bf6642ea2..d2d8da58aa1 100644 --- a/src/GraphQl/Serializer/ItemNormalizer.php +++ b/src/GraphQl/Serializer/ItemNormalizer.php @@ -56,6 +56,11 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? parent::getSupportedTypes($format) : []; + } + /** * {@inheritdoc} * diff --git a/src/GraphQl/Serializer/ObjectNormalizer.php b/src/GraphQl/Serializer/ObjectNormalizer.php index d49b9a7ca03..1fe29b9311a 100644 --- a/src/GraphQl/Serializer/ObjectNormalizer.php +++ b/src/GraphQl/Serializer/ObjectNormalizer.php @@ -44,11 +44,25 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + // @deprecated remove condition when support for symfony versions under 6.3 is dropped + if (!method_exists($this->decorated, 'getSupportedTypes')) { + return [ + '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + ]; + } + + return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; + } + /** * {@inheritdoc} */ public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } diff --git a/src/Hal/Serializer/EntrypointNormalizer.php b/src/Hal/Serializer/EntrypointNormalizer.php index 94ecddcde73..93ab6ca21c5 100644 --- a/src/Hal/Serializer/EntrypointNormalizer.php +++ b/src/Hal/Serializer/EntrypointNormalizer.php @@ -74,8 +74,15 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $data instanceof Entrypoint; } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? [Entrypoint::class => true] : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } } diff --git a/src/Hal/Serializer/ItemNormalizer.php b/src/Hal/Serializer/ItemNormalizer.php index 4c9bb677c70..2ce87b95fc0 100644 --- a/src/Hal/Serializer/ItemNormalizer.php +++ b/src/Hal/Serializer/ItemNormalizer.php @@ -46,6 +46,11 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? parent::getSupportedTypes($format) : []; + } + /** * {@inheritdoc} */ diff --git a/src/Hal/Serializer/ObjectNormalizer.php b/src/Hal/Serializer/ObjectNormalizer.php index 0a0e852cd4c..7ef480aa8a8 100644 --- a/src/Hal/Serializer/ObjectNormalizer.php +++ b/src/Hal/Serializer/ObjectNormalizer.php @@ -39,11 +39,25 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + // @deprecated remove condition when support for symfony versions under 6.3 is dropped + if (!method_exists($this->decorated, 'getSupportedTypes')) { + return [ + '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + ]; + } + + return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; + } + /** * {@inheritdoc} */ public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } diff --git a/src/Hydra/Serializer/CollectionFiltersNormalizer.php b/src/Hydra/Serializer/CollectionFiltersNormalizer.php index 2dc4793cfa0..11909f083b9 100644 --- a/src/Hydra/Serializer/CollectionFiltersNormalizer.php +++ b/src/Hydra/Serializer/CollectionFiltersNormalizer.php @@ -50,8 +50,20 @@ public function supportsNormalization(mixed $data, string $format = null, array return $this->collectionNormalizer->supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + // @deprecated remove condition when support for symfony versions under 6.3 is dropped + if (!method_exists($this->collectionNormalizer, 'getSupportedTypes')) { + return ['*' => $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod()]; + } + + return $this->collectionNormalizer->getSupportedTypes($format); + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); } diff --git a/src/Hydra/Serializer/DocumentationNormalizer.php b/src/Hydra/Serializer/DocumentationNormalizer.php index e6e5e3fe122..f09e8d157a6 100644 --- a/src/Hydra/Serializer/DocumentationNormalizer.php +++ b/src/Hydra/Serializer/DocumentationNormalizer.php @@ -544,8 +544,15 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $data instanceof Documentation; } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? [Documentation::class => true] : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } } diff --git a/src/Hydra/Serializer/EntrypointNormalizer.php b/src/Hydra/Serializer/EntrypointNormalizer.php index 9018fad0a15..0f0f2ce4afb 100644 --- a/src/Hydra/Serializer/EntrypointNormalizer.php +++ b/src/Hydra/Serializer/EntrypointNormalizer.php @@ -83,8 +83,15 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $data instanceof Entrypoint; } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? [Entrypoint::class => true] : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } } diff --git a/src/Hydra/Serializer/ErrorNormalizer.php b/src/Hydra/Serializer/ErrorNormalizer.php index 753bd0bc554..1b76b5c3953 100644 --- a/src/Hydra/Serializer/ErrorNormalizer.php +++ b/src/Hydra/Serializer/ErrorNormalizer.php @@ -65,8 +65,22 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException); } + public function getSupportedTypes($format): array + { + if (self::FORMAT === $format) { + return [ + \Exception::class => true, + FlattenException::class => true, + ]; + } + + return []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } } diff --git a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php index 4eafee6157e..efd96212700 100644 --- a/src/Hydra/Serializer/PartialCollectionViewNormalizer.php +++ b/src/Hydra/Serializer/PartialCollectionViewNormalizer.php @@ -106,8 +106,22 @@ public function supportsNormalization(mixed $data, string $format = null, array return $this->collectionNormalizer->supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + // @deprecated remove condition when support for symfony versions under 6.3 is dropped + if (!method_exists($this->collectionNormalizer, 'getSupportedTypes')) { + return [ + '*' => $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(), + ]; + } + + return $this->collectionNormalizer->getSupportedTypes($format); + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod(); } diff --git a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php index 3319e036c61..60802039475 100644 --- a/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php +++ b/src/JsonApi/Serializer/ConstraintViolationListNormalizer.php @@ -59,8 +59,15 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $data instanceof ConstraintViolationListInterface; } + public function getSupportedTypes($format): array + { + return (self::FORMAT === $format) ? [ConstraintViolationListInterface::class => true] : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } diff --git a/src/JsonApi/Serializer/EntrypointNormalizer.php b/src/JsonApi/Serializer/EntrypointNormalizer.php index 047a418dfe8..9feb1b6dc5f 100644 --- a/src/JsonApi/Serializer/EntrypointNormalizer.php +++ b/src/JsonApi/Serializer/EntrypointNormalizer.php @@ -74,8 +74,15 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $data instanceof Entrypoint; } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? [Entrypoint::class => true] : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } } diff --git a/src/JsonApi/Serializer/ErrorNormalizer.php b/src/JsonApi/Serializer/ErrorNormalizer.php index 758c8db593b..52fddd5c167 100644 --- a/src/JsonApi/Serializer/ErrorNormalizer.php +++ b/src/JsonApi/Serializer/ErrorNormalizer.php @@ -67,8 +67,22 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException); } + public function getSupportedTypes($format): array + { + if (self::FORMAT === $format) { + return [ + \Exception::class => true, + FlattenException::class => true, + ]; + } + + return []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } } diff --git a/src/JsonApi/Serializer/ItemNormalizer.php b/src/JsonApi/Serializer/ItemNormalizer.php index f54f2aa15f0..f3e4dbd0141 100644 --- a/src/JsonApi/Serializer/ItemNormalizer.php +++ b/src/JsonApi/Serializer/ItemNormalizer.php @@ -65,6 +65,11 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? parent::getSupportedTypes($format) : []; + } + /** * {@inheritdoc} */ diff --git a/src/JsonApi/Serializer/ObjectNormalizer.php b/src/JsonApi/Serializer/ObjectNormalizer.php index 326928ca496..da115f45db2 100644 --- a/src/JsonApi/Serializer/ObjectNormalizer.php +++ b/src/JsonApi/Serializer/ObjectNormalizer.php @@ -42,8 +42,22 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + // @deprecated remove condition when support for symfony versions under 6.3 is dropped + if (!method_exists($this->decorated, 'getSupportedTypes')) { + return [ + '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + ]; + } + + return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } diff --git a/src/JsonLd/Serializer/ItemNormalizer.php b/src/JsonLd/Serializer/ItemNormalizer.php index ed2470f0906..e0cc8a171ed 100644 --- a/src/JsonLd/Serializer/ItemNormalizer.php +++ b/src/JsonLd/Serializer/ItemNormalizer.php @@ -58,6 +58,11 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && parent::supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? parent::getSupportedTypes($format) : []; + } + /** * {@inheritdoc} * diff --git a/src/JsonLd/Serializer/ObjectNormalizer.php b/src/JsonLd/Serializer/ObjectNormalizer.php index 526aa85589c..e21b8dbacfa 100644 --- a/src/JsonLd/Serializer/ObjectNormalizer.php +++ b/src/JsonLd/Serializer/ObjectNormalizer.php @@ -41,8 +41,22 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context); } + public function getSupportedTypes($format): array + { + // @deprecated remove condition when support for symfony versions under 6.3 is dropped + if (!method_exists($this->decorated, 'getSupportedTypes')) { + return [ + '*' => $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(), + ]; + } + + return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return $this->decorated instanceof CacheableSupportsMethodInterface && $this->decorated->hasCacheableSupportsMethod(); } diff --git a/src/OpenApi/Serializer/ApiGatewayNormalizer.php b/src/OpenApi/Serializer/ApiGatewayNormalizer.php index fa90c4b0898..2ffea4727f2 100644 --- a/src/OpenApi/Serializer/ApiGatewayNormalizer.php +++ b/src/OpenApi/Serializer/ApiGatewayNormalizer.php @@ -120,11 +120,23 @@ public function supportsNormalization(mixed $data, string $format = null, array return $this->documentationNormalizer->supportsNormalization($data, $format); } + public function getSupportedTypes($format): array + { + // @deprecated remove condition when support for symfony versions under 6.3 is dropped + if (!method_exists($this->documentationNormalizer, 'getSupportedTypes')) { + return ['*' => $this->documentationNormalizer instanceof CacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod()]; + } + + return $this->documentationNormalizer->getSupportedTypes($format); + } + /** * {@inheritdoc} */ public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return $this->documentationNormalizer instanceof CacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod(); } diff --git a/src/OpenApi/Serializer/OpenApiNormalizer.php b/src/OpenApi/Serializer/OpenApiNormalizer.php index e3486863894..1c0ed7cacff 100644 --- a/src/OpenApi/Serializer/OpenApiNormalizer.php +++ b/src/OpenApi/Serializer/OpenApiNormalizer.php @@ -75,8 +75,15 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && $data instanceof OpenApi; } + public function getSupportedTypes($format): array + { + return self::FORMAT === $format ? [OpenApi::class => true] : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } } diff --git a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php index 32891c46f4f..1e07ea49e88 100644 --- a/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php +++ b/src/OpenApi/Tests/Serializer/ApiGatewayNormalizerTest.php @@ -28,6 +28,9 @@ final class ApiGatewayNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportsNormalization(): void { $normalizerProphecy = $this->prophesize(NormalizerInterface::class); diff --git a/src/Problem/Serializer/ErrorNormalizer.php b/src/Problem/Serializer/ErrorNormalizer.php index fe584794456..da86321e69e 100644 --- a/src/Problem/Serializer/ErrorNormalizer.php +++ b/src/Problem/Serializer/ErrorNormalizer.php @@ -66,8 +66,22 @@ public function supportsNormalization(mixed $data, string $format = null, array return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException); } + public function getSupportedTypes($format): array + { + if (self::FORMAT === $format) { + return [ + \Exception::class => true, + FlattenException::class => true, + ]; + } + + return []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } } diff --git a/src/RamseyUuid/Serializer/UuidDenormalizer.php b/src/RamseyUuid/Serializer/UuidDenormalizer.php index 78695c05237..5f9f5d7c3b9 100644 --- a/src/RamseyUuid/Serializer/UuidDenormalizer.php +++ b/src/RamseyUuid/Serializer/UuidDenormalizer.php @@ -37,4 +37,11 @@ public function supportsDenormalization(mixed $data, string $type, string $forma { return \is_string($data) && is_a($type, UuidInterface::class, true); } + + public function getSupportedTypes(?string $format): array + { + return [ + UuidInterface::class => true, + ]; + } } diff --git a/src/Serializer/AbstractCollectionNormalizer.php b/src/Serializer/AbstractCollectionNormalizer.php index e8935f3136d..47b6ff76bba 100644 --- a/src/Serializer/AbstractCollectionNormalizer.php +++ b/src/Serializer/AbstractCollectionNormalizer.php @@ -56,9 +56,28 @@ public function supportsNormalization(mixed $data, string $format = null, array public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } + public function getSupportedTypes(?string $format): array + { + /* + * At this point, support anything that is_iterable(), i.e. array|Traversable + * for non-objects, symfony uses 'native-'.\gettype($data) : + * https://github.com/tucksaun/symfony/blob/400685a68b00b0932f8ef41096578872b643099c/src/Symfony/Component/Serializer/Serializer.php#L254 + */ + if (static::FORMAT === $format) { + return [ + 'native-array' => true, + '\Traversable' => true, + ]; + } + + return []; + } + /** * {@inheritdoc} * diff --git a/src/Serializer/AbstractConstraintViolationListNormalizer.php b/src/Serializer/AbstractConstraintViolationListNormalizer.php index 6665268fb50..8f920c723a0 100644 --- a/src/Serializer/AbstractConstraintViolationListNormalizer.php +++ b/src/Serializer/AbstractConstraintViolationListNormalizer.php @@ -46,8 +46,15 @@ public function supportsNormalization(mixed $data, string $format = null, array return static::FORMAT === $format && $data instanceof ConstraintViolationListInterface; } + public function getSupportedTypes($format): array + { + return $format === static::FORMAT ? [ConstraintViolationListInterface::class => true] : []; + } + public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } diff --git a/src/Serializer/AbstractItemNormalizer.php b/src/Serializer/AbstractItemNormalizer.php index 7b27018ef55..9905110ce7c 100644 --- a/src/Serializer/AbstractItemNormalizer.php +++ b/src/Serializer/AbstractItemNormalizer.php @@ -87,11 +87,20 @@ public function supportsNormalization(mixed $data, string $format = null, array return $this->resourceClassResolver->isResourceClass($class); } + public function getSupportedTypes(?string $format): array + { + return [ + '*' => true, + ]; + } + /** * {@inheritdoc} */ public function hasCacheableSupportsMethod(): bool { + trigger_deprecation('api-platform/core', '3.1', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__); + return true; } diff --git a/tests/Fixtures/TestBundle/Serializer/Denormalizer/DummyPlainIdentifierDenormalizer.php b/tests/Fixtures/TestBundle/Serializer/Denormalizer/DummyPlainIdentifierDenormalizer.php index 6c49fa900e1..8e07a55ec2c 100644 --- a/tests/Fixtures/TestBundle/Serializer/Denormalizer/DummyPlainIdentifierDenormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Denormalizer/DummyPlainIdentifierDenormalizer.php @@ -71,4 +71,9 @@ public function supportsDenormalization($data, $type, $format = null, array $con && ('1' === ($data['relatedDummy'] ?? null) || ['1'] === ($data['relatedDummies'] ?? null)) && !isset($context[self::class]); } + + public function getSupportedTypes($format): array + { + return 'json' === $format ? ['*' => false] : []; + } } diff --git a/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php b/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php index fd143363fb2..b3bf54792c4 100644 --- a/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Denormalizer/RelatedDummyPlainIdentifierDenormalizer.php @@ -65,4 +65,9 @@ public function supportsDenormalization($data, $type, $format = null, array $con && '1' === ($data['thirdLevel'] ?? null) && !isset($context[self::class]); } + + public function getSupportedTypes($format): array + { + return 'json' === $format ? ['*' => false] : []; + } } diff --git a/tests/Fixtures/TestBundle/Serializer/Denormalizer/SerializableResourceDenormalizer.php b/tests/Fixtures/TestBundle/Serializer/Denormalizer/SerializableResourceDenormalizer.php index 51c64ebf078..9322483e15b 100644 --- a/tests/Fixtures/TestBundle/Serializer/Denormalizer/SerializableResourceDenormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Denormalizer/SerializableResourceDenormalizer.php @@ -41,4 +41,9 @@ public function supportsDenormalization($data, $type, $format = null, array $con { return 'json' === $format && SerializableResource::class === $type && \is_array($data); } + + public function getSupportedTypes($format): array + { + return 'json' === $format ? ['*' => true] : []; + } } diff --git a/tests/Fixtures/TestBundle/Serializer/Normalizer/AddGroupNormalizer.php b/tests/Fixtures/TestBundle/Serializer/Normalizer/AddGroupNormalizer.php index e9439b7d03c..9c0f610412e 100644 --- a/tests/Fixtures/TestBundle/Serializer/Normalizer/AddGroupNormalizer.php +++ b/tests/Fixtures/TestBundle/Serializer/Normalizer/AddGroupNormalizer.php @@ -48,4 +48,11 @@ public function supportsNormalization($data, $format = null, array $context = [] return $data instanceof RelationGroupImpactOnCollection; } + + public function getSupportedTypes($format): array + { + return [ + RelationGroupImpactOnCollection::class => false, + ]; + } } diff --git a/tests/Hal/Serializer/CollectionNormalizerTest.php b/tests/Hal/Serializer/CollectionNormalizerTest.php index d9c2cd70303..2b919476278 100644 --- a/tests/Hal/Serializer/CollectionNormalizerTest.php +++ b/tests/Hal/Serializer/CollectionNormalizerTest.php @@ -33,6 +33,9 @@ class CollectionNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportsNormalize(): void { $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); diff --git a/tests/Hal/Serializer/EntrypointNormalizerTest.php b/tests/Hal/Serializer/EntrypointNormalizerTest.php index 30c0602fecb..68a91bf4270 100644 --- a/tests/Hal/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hal/Serializer/EntrypointNormalizerTest.php @@ -34,6 +34,9 @@ class EntrypointNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportNormalization(): void { $collection = new ResourceNameCollection(); diff --git a/tests/Hal/Serializer/ItemNormalizerTest.php b/tests/Hal/Serializer/ItemNormalizerTest.php index ea40dab3092..e58718705b6 100644 --- a/tests/Hal/Serializer/ItemNormalizerTest.php +++ b/tests/Hal/Serializer/ItemNormalizerTest.php @@ -67,6 +67,9 @@ public function testDoesNotSupportDenormalization(): void $normalizer->denormalize(['foo'], 'Foo'); } + /** + * @group legacy + */ public function testSupportsNormalization(): void { $std = new \stdClass(); diff --git a/tests/Hal/Serializer/ObjectNormalizerTest.php b/tests/Hal/Serializer/ObjectNormalizerTest.php index ec4fc4174f8..c503e3ead2b 100644 --- a/tests/Hal/Serializer/ObjectNormalizerTest.php +++ b/tests/Hal/Serializer/ObjectNormalizerTest.php @@ -45,6 +45,9 @@ public function testDoesNotSupportDenormalization(): void $normalizer->denormalize(['foo'], 'Foo'); } + /** + * @group legacy + */ public function testSupportsNormalization(): void { $std = new \stdClass(); diff --git a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php index d151da88114..e8d9b2b87c3 100644 --- a/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php @@ -40,6 +40,9 @@ class CollectionFiltersNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportsNormalization(): void { $decoratedProphecy = $this->prophesize(NormalizerInterface::class); diff --git a/tests/Hydra/Serializer/CollectionNormalizerTest.php b/tests/Hydra/Serializer/CollectionNormalizerTest.php index c880ab4bb38..df477860b2d 100644 --- a/tests/Hydra/Serializer/CollectionNormalizerTest.php +++ b/tests/Hydra/Serializer/CollectionNormalizerTest.php @@ -36,6 +36,9 @@ class CollectionNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportsNormalize(): void { $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); diff --git a/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php b/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php index b2ee6a82983..f5b690a9a3c 100644 --- a/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php @@ -31,6 +31,9 @@ class ConstraintViolationNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportNormalization(): void { $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); diff --git a/tests/Hydra/Serializer/DocumentationNormalizerTest.php b/tests/Hydra/Serializer/DocumentationNormalizerTest.php index f1d1ebf5eb6..5bd6ccdbccd 100644 --- a/tests/Hydra/Serializer/DocumentationNormalizerTest.php +++ b/tests/Hydra/Serializer/DocumentationNormalizerTest.php @@ -43,6 +43,9 @@ class DocumentationNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testNormalize(): void { $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataCollectionFactoryInterface::class); diff --git a/tests/Hydra/Serializer/EntrypointNormalizerTest.php b/tests/Hydra/Serializer/EntrypointNormalizerTest.php index 6165b1b0023..4ac1d65b305 100644 --- a/tests/Hydra/Serializer/EntrypointNormalizerTest.php +++ b/tests/Hydra/Serializer/EntrypointNormalizerTest.php @@ -36,6 +36,9 @@ class EntrypointNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportNormalization(): void { $collection = new ResourceNameCollection(); diff --git a/tests/Hydra/Serializer/ErrorNormalizerTest.php b/tests/Hydra/Serializer/ErrorNormalizerTest.php index 4cfb50ac21b..9f1ad08014c 100644 --- a/tests/Hydra/Serializer/ErrorNormalizerTest.php +++ b/tests/Hydra/Serializer/ErrorNormalizerTest.php @@ -27,6 +27,9 @@ class ErrorNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportsNormalization(): void { $urlGeneratorProphecy = $this->prophesize(UrlGeneratorInterface::class); diff --git a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php index 57015c8d2ed..10da718f583 100644 --- a/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php +++ b/tests/Hydra/Serializer/PartialCollectionViewNormalizerTest.php @@ -158,6 +158,9 @@ private function normalizePaginator(bool $partial = false, bool $cursor = false) return $normalizer->normalize($paginatorProphecy->reveal(), null, ['resource_class' => SoMany::class, 'operation_name' => 'get']); } + /** + * @group legacy + */ public function testSupportsNormalization(): void { $decoratedNormalizerProphecy = $this->prophesize(NormalizerInterface::class); diff --git a/tests/JsonApi/Serializer/CollectionNormalizerTest.php b/tests/JsonApi/Serializer/CollectionNormalizerTest.php index f7d55aa3f8b..87ac5b7352f 100644 --- a/tests/JsonApi/Serializer/CollectionNormalizerTest.php +++ b/tests/JsonApi/Serializer/CollectionNormalizerTest.php @@ -34,6 +34,9 @@ class CollectionNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportsNormalize(): void { $resourceClassResolverProphecy = $this->prophesize(ResourceClassResolverInterface::class); diff --git a/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php b/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php index 46e9ff325dd..7c14b5d57be 100644 --- a/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/JsonApi/Serializer/ConstraintViolationNormalizerTest.php @@ -32,6 +32,9 @@ class ConstraintViolationNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportNormalization(): void { $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); diff --git a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php index aabe337deb3..848adf8f6ea 100644 --- a/tests/JsonApi/Serializer/EntrypointNormalizerTest.php +++ b/tests/JsonApi/Serializer/EntrypointNormalizerTest.php @@ -40,6 +40,9 @@ class EntrypointNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportNormalization(): void { $collection = new ResourceNameCollection(); diff --git a/tests/JsonApi/Serializer/ErrorNormalizerTest.php b/tests/JsonApi/Serializer/ErrorNormalizerTest.php index b245b1e6476..5bc67633e62 100644 --- a/tests/JsonApi/Serializer/ErrorNormalizerTest.php +++ b/tests/JsonApi/Serializer/ErrorNormalizerTest.php @@ -24,6 +24,9 @@ */ class ErrorNormalizerTest extends TestCase { + /** + * @group legacy + */ public function testSupportsNormalization(): void { $normalizer = new ErrorNormalizer(); diff --git a/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php b/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php index 34f5ca61f68..2b2a6ea90c6 100644 --- a/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php +++ b/tests/Problem/Serializer/ConstraintViolationNormalizerTest.php @@ -30,6 +30,9 @@ class ConstraintViolationNormalizerTest extends TestCase { use ProphecyTrait; + /** + * @group legacy + */ public function testSupportNormalization(): void { $nameConverterProphecy = $this->prophesize(NameConverterInterface::class); diff --git a/tests/Problem/Serializer/ErrorNormalizerTest.php b/tests/Problem/Serializer/ErrorNormalizerTest.php index 50bbea4a348..5c38af7aaa8 100644 --- a/tests/Problem/Serializer/ErrorNormalizerTest.php +++ b/tests/Problem/Serializer/ErrorNormalizerTest.php @@ -23,6 +23,9 @@ */ class ErrorNormalizerTest extends TestCase { + /** + * @group legacy + */ public function testSupportNormalization(): void { $normalizer = new ErrorNormalizer(); diff --git a/tests/Serializer/AbstractItemNormalizerTest.php b/tests/Serializer/AbstractItemNormalizerTest.php index 1b04021cce4..d4ac401a2b4 100644 --- a/tests/Serializer/AbstractItemNormalizerTest.php +++ b/tests/Serializer/AbstractItemNormalizerTest.php @@ -51,6 +51,9 @@ class AbstractItemNormalizerTest extends TestCase use ExpectDeprecationTrait; use ProphecyTrait; + /** + * @group legacy + */ public function testSupportNormalizationAndSupportDenormalization(): void { $std = new \stdClass(); diff --git a/tests/Serializer/ItemNormalizerTest.php b/tests/Serializer/ItemNormalizerTest.php index 26409b818fe..99c22a5b9fb 100644 --- a/tests/Serializer/ItemNormalizerTest.php +++ b/tests/Serializer/ItemNormalizerTest.php @@ -46,6 +46,9 @@ class ItemNormalizerTest extends TestCase use ExpectDeprecationTrait; use ProphecyTrait; + /** + * @group legacy + */ public function testSupportNormalization(): void { $std = new \stdClass();