diff --git a/src/State/SerializerAwareProviderInterface.php b/src/State/SerializerAwareProviderInterface.php index e213176dc4..f8962331dc 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 dfe28b5560..bba3665f46 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 3996c7e911..b2c04aa413 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 3d9567a169..78e3c47afb 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 45cc5e0718..3eca79faf5 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 a189f93675..213e140e6c 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();