Skip to content

Commit f010fd4

Browse files
fix(serializer): deprecate SerializerAwareProviderInterface and SerializableProvider (#7348)
1 parent 570beca commit f010fd4

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

src/State/SerializerAwareProviderInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* Injects serializer in providers.
2020
*
2121
* @author Vincent Chalamon <[email protected]>
22+
*
23+
* @deprecated in 4.2, to be removed in 5.0 because it violates the dependency injection principle.
2224
*/
2325
interface SerializerAwareProviderInterface
2426
{

src/State/SerializerAwareProviderTrait.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ trait SerializerAwareProviderTrait
3030

3131
public function setSerializerLocator(ContainerInterface $serializerLocator): void
3232
{
33+
trigger_deprecation(
34+
'api-platform/core',
35+
'4.2',
36+
'The "%s" interface is deprecated and will be removed in 5.0. It violates the dependency injection principle.',
37+
SerializerAwareProviderInterface::class
38+
);
39+
3340
$this->serializerLocator = $serializerLocator;
3441
}
3542

src/Symfony/Bundle/ApiPlatformBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function build(ContainerBuilder $container): void
4444
{
4545
parent::build($container);
4646

47+
// TODO: remove in 5.x
4748
$container->addCompilerPass(new DataProviderPass());
4849
// Run the compiler pass before the {@see ResolveInstanceofConditionalsPass} to allow autoconfiguration of generated filter definitions.
4950
$container->addCompilerPass(new AttributeFilterPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 101);

src/Symfony/Bundle/DependencyInjection/Compiler/DataProviderPass.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
/**
2222
* Registers data providers.
2323
*
24-
* @internal
24+
* @internal since 4.2
2525
*
2626
* @author Kévin Dunglas <[email protected]>
2727
* @author Vincent Chalamon <[email protected]>
28+
*
29+
* TODO: remove in 5.x
2830
*/
2931
final class DataProviderPass implements CompilerPassInterface
3032
{

tests/Fixtures/TestBundle/State/SerializableProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
/**
2222
* @author Vincent Chalamon <[email protected]>
23+
*
24+
* @deprecated in 4.2, to be removed in 5.0 because it violates the dependency injection principle.
2325
*/
2426
class SerializableProvider implements ProviderInterface, SerializerAwareProviderInterface
2527
{

tests/Symfony/Bundle/ApiPlatformBundleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class ApiPlatformBundleTest extends TestCase
4343
public function testBuild(): void
4444
{
4545
$containerProphecy = $this->prophesize(ContainerBuilder::class);
46+
// TODO: remove in 5.x
4647
$containerProphecy->addCompilerPass(Argument::type(DataProviderPass::class))->willReturn($containerProphecy->reveal())->shouldBeCalled();
4748
$containerProphecy->addCompilerPass(Argument::type(AttributeFilterPass::class), PassConfig::TYPE_BEFORE_OPTIMIZATION, 101)->willReturn($containerProphecy->reveal())->shouldBeCalled();
4849
$containerProphecy->addCompilerPass(Argument::type(AttributeResourcePass::class))->shouldBeCalled()->willReturn($containerProphecy->reveal())->shouldBeCalled();

0 commit comments

Comments
 (0)