From 86aba2d72c699fb8a7fa8b787522ee3c870f7b00 Mon Sep 17 00:00:00 2001 From: Vincent Amstoutz Date: Fri, 22 Aug 2025 14:39:22 +0200 Subject: [PATCH] fix(serializer): deprecate SerializerAwareProviderInterface and SerializableProvider A PR for the removal was already made: https://github.com/api-platform/core/pull/7314. --- src/State/SerializerAwareProviderInterface.php | 2 ++ src/State/SerializerAwareProviderTrait.php | 7 +++++++ src/Symfony/Bundle/ApiPlatformBundle.php | 1 + .../DependencyInjection/Compiler/DataProviderPass.php | 4 +++- tests/Fixtures/TestBundle/State/SerializableProvider.php | 2 ++ tests/Symfony/Bundle/ApiPlatformBundleTest.php | 1 + 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/State/SerializerAwareProviderInterface.php b/src/State/SerializerAwareProviderInterface.php index e213176dc4a..f8962331dcf 100644 --- a/src/State/SerializerAwareProviderInterface.php +++ b/src/State/SerializerAwareProviderInterface.php @@ -19,6 +19,8 @@ * Injects serializer in providers. * * @author Vincent Chalamon + * + * @deprecated in 4.2, to be removed in 5.0 because it violates the dependency injection principle. */ interface SerializerAwareProviderInterface { diff --git a/src/State/SerializerAwareProviderTrait.php b/src/State/SerializerAwareProviderTrait.php index dfe28b55606..bba3665f467 100644 --- a/src/State/SerializerAwareProviderTrait.php +++ b/src/State/SerializerAwareProviderTrait.php @@ -30,6 +30,13 @@ trait SerializerAwareProviderTrait public function setSerializerLocator(ContainerInterface $serializerLocator): void { + trigger_deprecation( + 'api-platform/core', + '4.2', + 'The "%s" interface is deprecated and will be removed in 5.0. It violates the dependency injection principle.', + SerializerAwareProviderInterface::class + ); + $this->serializerLocator = $serializerLocator; } diff --git a/src/Symfony/Bundle/ApiPlatformBundle.php b/src/Symfony/Bundle/ApiPlatformBundle.php index 3996c7e911d..b2c04aa4134 100644 --- a/src/Symfony/Bundle/ApiPlatformBundle.php +++ b/src/Symfony/Bundle/ApiPlatformBundle.php @@ -44,6 +44,7 @@ public function build(ContainerBuilder $container): void { parent::build($container); + // TODO: remove in 5.x $container->addCompilerPass(new DataProviderPass()); // Run the compiler pass before the {@see ResolveInstanceofConditionalsPass} to allow autoconfiguration of generated filter definitions. $container->addCompilerPass(new AttributeFilterPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 101); diff --git a/src/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php b/src/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php index 3d9567a1696..78e3c47afb5 100644 --- a/src/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php +++ b/src/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php @@ -21,10 +21,12 @@ /** * Registers data providers. * - * @internal + * @internal since 4.2 * * @author Kévin Dunglas * @author Vincent Chalamon + * + * TODO: remove in 5.x */ final class DataProviderPass implements CompilerPassInterface { diff --git a/tests/Fixtures/TestBundle/State/SerializableProvider.php b/tests/Fixtures/TestBundle/State/SerializableProvider.php index 45cc5e07181..3eca79faf54 100644 --- a/tests/Fixtures/TestBundle/State/SerializableProvider.php +++ b/tests/Fixtures/TestBundle/State/SerializableProvider.php @@ -20,6 +20,8 @@ /** * @author Vincent Chalamon + * + * @deprecated in 4.2, to be removed in 5.0 because it violates the dependency injection principle. */ class SerializableProvider implements ProviderInterface, SerializerAwareProviderInterface { diff --git a/tests/Symfony/Bundle/ApiPlatformBundleTest.php b/tests/Symfony/Bundle/ApiPlatformBundleTest.php index a189f93675c..213e140e6cc 100644 --- a/tests/Symfony/Bundle/ApiPlatformBundleTest.php +++ b/tests/Symfony/Bundle/ApiPlatformBundleTest.php @@ -43,6 +43,7 @@ class ApiPlatformBundleTest extends TestCase public function testBuild(): void { $containerProphecy = $this->prophesize(ContainerBuilder::class); + // TODO: remove in 5.x $containerProphecy->addCompilerPass(Argument::type(DataProviderPass::class))->willReturn($containerProphecy->reveal())->shouldBeCalled(); $containerProphecy->addCompilerPass(Argument::type(AttributeFilterPass::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, 101)->willReturn($containerProphecy->reveal())->shouldBeCalled(); $containerProphecy->addCompilerPass(Argument::type(AttributeResourcePass::class))->shouldBeCalled()->willReturn($containerProphecy->reveal())->shouldBeCalled();