Skip to content

Commit 592dede

Browse files
committed
Handle deprecations from Symfony 5.1.
1 parent d84282f commit 592dede

File tree

6 files changed

+48
-16
lines changed

6 files changed

+48
-16
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
use Symfony\Component\Config\Resource\DirectoryResource;
4242
use Symfony\Component\DependencyInjection\ChildDefinition;
4343
use Symfony\Component\DependencyInjection\ContainerBuilder;
44+
use Symfony\Component\DependencyInjection\Definition;
4445
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
4546
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
4647
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -145,6 +146,19 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
145146
$loader->load('data_provider.xml');
146147
$loader->load('filter.xml');
147148

149+
$container->getDefinition('api_platform.operation_method_resolver')
150+
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%service_id%" service is deprecated since API Platform 2.5.'));
151+
$container->getDefinition('api_platform.formats_provider')
152+
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%service_id%" service is deprecated since API Platform 2.5.'));
153+
$container->getAlias('ApiPlatform\Core\Api\OperationAwareFormatsProviderInterface')
154+
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%alias_id%" alias is deprecated since API Platform 2.5.'));
155+
$container->getDefinition('api_platform.operation_path_resolver.underscore')
156+
->setDeprecated(...$this->buildDeprecationArgs('2.1', 'The "%service_id%" service is deprecated since API Platform 2.1 and will be removed in 3.0. Use "api_platform.path_segment_name_generator.underscore" instead.'));
157+
$container->getDefinition('api_platform.operation_path_resolver.dash')
158+
->setDeprecated(...$this->buildDeprecationArgs('2.1', 'The "%service_id%" service is deprecated since API Platform 2.1 and will be removed in 3.0. Use "api_platform.path_segment_name_generator.dash" instead.'));
159+
$container->getDefinition('api_platform.filters')
160+
->setDeprecated(...$this->buildDeprecationArgs('2.1', 'The "%service_id%" service is deprecated since 2.1 and will be removed in 3.0. Use the "api_platform.filter_locator" service instead.'));
161+
148162
if (class_exists(Uuid::class)) {
149163
$loader->load('ramsey_uuid.xml');
150164
}
@@ -416,6 +430,11 @@ private function registerLegacyBundlesConfiguration(ContainerBuilder $container,
416430

417431
if (isset($bundles['NelmioApiDocBundle']) && $config['enable_nelmio_api_doc']) {
418432
$loader->load('nelmio_api_doc.xml');
433+
434+
$container->getDefinition('api_platform.nelmio_api_doc.annotations_provider')
435+
->setDeprecated(...$this->buildDeprecationArgs('2.2', 'The "%service_id%" service is deprecated since API Platform 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.'));
436+
$container->getDefinition('api_platform.nelmio_api_doc.parser')
437+
->setDeprecated(...$this->buildDeprecationArgs('2.2', 'The "%service_id%" service is deprecated since API Platform 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.'));
419438
}
420439
}
421440

@@ -609,4 +628,11 @@ private function registerSecurityConfiguration(ContainerBuilder $container, XmlF
609628
$loader->load('security.xml');
610629
}
611630
}
631+
632+
private function buildDeprecationArgs(string $version, string $message): array
633+
{
634+
return method_exists(Definition::class, 'getDeprecation')
635+
? ['api-platform/core', $version, $message]
636+
: [true, $message];
637+
}
612638
}

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Symfony\Bundle\FullStack;
2727
use Symfony\Bundle\MercureBundle\MercureBundle;
2828
use Symfony\Bundle\TwigBundle\TwigBundle;
29+
use Symfony\Component\Config\Definition\BaseNode;
2930
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
3031
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
3132
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -85,7 +86,7 @@ public function getConfigTreeBuilder()
8586
->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
8687
->scalarNode('default_operation_path_resolver')
8788
->defaultValue('api_platform.operation_path_resolver.underscore')
88-
->setDeprecated('The use of the `default_operation_path_resolver` has been deprecated in 2.1 and will be removed in 3.0. Use `path_segment_name_generator` instead.')
89+
->setDeprecated(...$this->buildDeprecationArgs('2.1', 'The use of the `default_operation_path_resolver` has been deprecated in 2.1 and will be removed in 3.0. Use `path_segment_name_generator` instead.'))
8990
->info('Specify the default operation path resolver to use for generating resources operations path.')
9091
->end()
9192
->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
@@ -109,7 +110,7 @@ public function getConfigTreeBuilder()
109110
->booleanNode('enable_fos_user')->defaultValue(class_exists(FOSUserBundle::class))->info('Enable the FOSUserBundle integration.')->end()
110111
->booleanNode('enable_nelmio_api_doc')
111112
->defaultFalse()
112-
->setDeprecated('Enabling the NelmioApiDocBundle integration has been deprecated in 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.')
113+
->setDeprecated(...$this->buildDeprecationArgs('2.2', 'Enabling the NelmioApiDocBundle integration has been deprecated in 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.'))
113114
->info('Enable the NelmioApiDocBundle integration.')
114115
->end()
115116
->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end()
@@ -494,4 +495,11 @@ private function addFormatSection(ArrayNodeDefinition $rootNode, string $key, ar
494495
->end()
495496
->end();
496497
}
498+
499+
private function buildDeprecationArgs(string $version, string $message): array
500+
{
501+
return method_exists(BaseNode::class, 'getDeprecation')
502+
? ['api-platform/core', $version, $message]
503+
: [$message];
504+
}
497505
}

src/Bridge/Symfony/Bundle/Resources/config/api.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<service id="api_platform.operation_method_resolver" class="ApiPlatform\Core\Bridge\Symfony\Routing\OperationMethodResolver" public="false">
1919
<argument type="service" id="api_platform.router" />
2020
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
21-
<deprecated>The "%service_id%" service is deprecated since API Platform 2.5.</deprecated>
2221
</service>
2322

2423
<service id="api_platform.route_name_resolver" class="ApiPlatform\Core\Bridge\Symfony\Routing\RouteNameResolver" public="false">
@@ -71,11 +70,9 @@
7170
<service id="api_platform.formats_provider" class="ApiPlatform\Core\Api\FormatsProvider">
7271
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
7372
<argument>%api_platform.formats%</argument>
74-
<deprecated>The "%service_id%" service is deprecated since API Platform 2.5.</deprecated>
7573
</service>
7674

7775
<service id="ApiPlatform\Core\Api\OperationAwareFormatsProviderInterface" alias="api_platform.formats_provider">
78-
<deprecated>The "%alias_id%" alias is deprecated since API Platform 2.5.</deprecated>
7976
</service>
8077

8178
<!-- Serializer -->
@@ -139,13 +136,9 @@
139136
<argument type="service" id="api_platform.path_segment_name_generator" />
140137
</service>
141138

142-
<service id="api_platform.operation_path_resolver.underscore" class="ApiPlatform\Core\PathResolver\UnderscoreOperationPathResolver" public="false">
143-
<deprecated>The "%service_id%" service is deprecated since API Platform 2.1 and will be removed in 3.0. Use "api_platform.path_segment_name_generator.underscore" instead.</deprecated>
144-
</service>
139+
<service id="api_platform.operation_path_resolver.underscore" class="ApiPlatform\Core\PathResolver\UnderscoreOperationPathResolver" public="false" />
145140

146-
<service id="api_platform.operation_path_resolver.dash" class="ApiPlatform\Core\PathResolver\DashOperationPathResolver" public="false">
147-
<deprecated>The "%service_id%" service is deprecated since API Platform 2.1 and will be removed in 3.0. Use "api_platform.path_segment_name_generator.dash" instead.</deprecated>
148-
</service>
141+
<service id="api_platform.operation_path_resolver.dash" class="ApiPlatform\Core\PathResolver\DashOperationPathResolver" public="false" />
149142

150143
<!-- Path name generator -->
151144

src/Bridge/Symfony/Bundle/Resources/config/filter.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<service id="api_platform.filter_collection_factory" class="ApiPlatform\Core\Api\FilterCollectionFactory" />
1515

1616
<service id="api_platform.filters" class="ApiPlatform\Core\Api\FilterCollection">
17-
<deprecated>The "%service_id%" service is deprecated since 2.1 and will be removed in 3.0. Use the "api_platform.filter_locator" service instead.</deprecated>
1817
<factory service="api_platform.filter_collection_factory" method="createFilterCollectionFromLocator" />
1918
<argument type="service" id="api_platform.filter_locator" />
2019
</service>

src/Bridge/Symfony/Bundle/Resources/config/nelmio_api_doc.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
<services>
88
<service id="api_platform.nelmio_api_doc.annotations_provider" class="ApiPlatform\Core\Bridge\NelmioApiDoc\Extractor\AnnotationsProvider\ApiPlatformProvider">
9-
<deprecated>The "%service_id%" service is deprecated since API Platform 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.</deprecated>
10-
119
<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />
1210
<argument type="service" id="api_platform.hydra.normalizer.documentation" />
1311
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
@@ -18,8 +16,6 @@
1816
</service>
1917

2018
<service id="api_platform.nelmio_api_doc.parser" class="ApiPlatform\Core\Bridge\NelmioApiDoc\Parser\ApiPlatformParser">
21-
<deprecated>The "%service_id%" service is deprecated since API Platform 2.2 and will be removed in 3.0. NelmioApiDocBundle 3 has native support for API Platform.</deprecated>
22-
2319
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
2420
<argument type="service" id="api_platform.metadata.property.name_collection_factory" />
2521
<argument type="service" id="api_platform.metadata.property.metadata_factory" />

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,11 @@ private function getPartialContainerBuilderProphecy($configuration = null)
10121012
$containerBuilderProphecy->removeBindings(Argument::type('string'))->will(function () {});
10131013
}
10141014

1015+
$containerBuilderProphecy->getDefinition(Argument::type('string'))
1016+
->willReturn($this->prophesize(Definition::class)->reveal());
1017+
$containerBuilderProphecy->getAlias(Argument::type('string'))
1018+
->willReturn($this->prophesize(Alias::class)->reveal());
1019+
10151020
return $containerBuilderProphecy;
10161021
}
10171022

@@ -1348,6 +1353,11 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo
13481353
$containerBuilderProphecy->getDefinition('api_platform.mercure.listener.response.add_link_header')->willReturn($definitionDummy);
13491354
$containerBuilderProphecy->getDefinition('api_platform.doctrine.listener.mercure.publish')->willReturn($definitionDummy);
13501355

1356+
$containerBuilderProphecy->getDefinition(Argument::type('string'))
1357+
->willReturn($this->prophesize(Definition::class)->reveal());
1358+
$containerBuilderProphecy->getAlias(Argument::type('string'))
1359+
->willReturn($this->prophesize(Alias::class)->reveal());
1360+
13511361
return $containerBuilderProphecy;
13521362
}
13531363

0 commit comments

Comments
 (0)