Skip to content

Commit f56cd4a

Browse files
derrabussoyuka
authored andcommitted
Handle deprecations from Symfony 5.1 (#3589)
1 parent 6e388f8 commit f56cd4a

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
@@ -43,6 +43,7 @@
4343
use Symfony\Component\Config\Resource\DirectoryResource;
4444
use Symfony\Component\DependencyInjection\ChildDefinition;
4545
use Symfony\Component\DependencyInjection\ContainerBuilder;
46+
use Symfony\Component\DependencyInjection\Definition;
4647
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
4748
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
4849
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
@@ -147,6 +148,19 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
147148
$loader->load('data_provider.xml');
148149
$loader->load('filter.xml');
149150

151+
$container->getDefinition('api_platform.operation_method_resolver')
152+
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%service_id%" service is deprecated since API Platform 2.5.'));
153+
$container->getDefinition('api_platform.formats_provider')
154+
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%service_id%" service is deprecated since API Platform 2.5.'));
155+
$container->getAlias('ApiPlatform\Core\Api\OperationAwareFormatsProviderInterface')
156+
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%alias_id%" alias is deprecated since API Platform 2.5.'));
157+
$container->getDefinition('api_platform.operation_path_resolver.underscore')
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.underscore" instead.'));
159+
$container->getDefinition('api_platform.operation_path_resolver.dash')
160+
->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.'));
161+
$container->getDefinition('api_platform.filters')
162+
->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.'));
163+
150164
if (class_exists(Uuid::class)) {
151165
$loader->load('ramsey_uuid.xml');
152166
}
@@ -460,6 +474,11 @@ private function registerLegacyBundlesConfiguration(ContainerBuilder $container,
460474

461475
if (isset($bundles['NelmioApiDocBundle']) && $config['enable_nelmio_api_doc']) {
462476
$loader->load('nelmio_api_doc.xml');
477+
478+
$container->getDefinition('api_platform.nelmio_api_doc.annotations_provider')
479+
->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.'));
480+
$container->getDefinition('api_platform.nelmio_api_doc.parser')
481+
->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.'));
463482
}
464483
}
465484

@@ -668,4 +687,11 @@ private function registerSecurityConfiguration(ContainerBuilder $container, XmlF
668687
$loader->load('security.xml');
669688
}
670689
}
690+
691+
private function buildDeprecationArgs(string $version, string $message): array
692+
{
693+
return method_exists(Definition::class, 'getDeprecation')
694+
? ['api-platform/core', $version, $message]
695+
: [true, $message];
696+
}
671697
}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\Bundle\FullStack;
2828
use Symfony\Bundle\MercureBundle\MercureBundle;
2929
use Symfony\Bundle\TwigBundle\TwigBundle;
30+
use Symfony\Component\Config\Definition\BaseNode;
3031
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
3132
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
3233
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -87,7 +88,7 @@ public function getConfigTreeBuilder()
8788
->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
8889
->scalarNode('default_operation_path_resolver')
8990
->defaultValue('api_platform.operation_path_resolver.underscore')
90-
->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.')
91+
->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.'))
9192
->info('Specify the default operation path resolver to use for generating resources operations path.')
9293
->end()
9394
->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
@@ -111,7 +112,7 @@ public function getConfigTreeBuilder()
111112
->booleanNode('enable_fos_user')->defaultValue(class_exists(FOSUserBundle::class))->info('Enable the FOSUserBundle integration.')->end()
112113
->booleanNode('enable_nelmio_api_doc')
113114
->defaultFalse()
114-
->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.')
115+
->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.'))
115116
->info('Enable the NelmioApiDocBundle integration.')
116117
->end()
117118
->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end()
@@ -567,4 +568,11 @@ private function addDefaultsSection(ArrayNodeDefinition $rootNode): void
567568
$defaultsNode->children()->variableNode($snakeCased);
568569
}
569570
}
571+
572+
private function buildDeprecationArgs(string $version, string $message): array
573+
{
574+
return method_exists(BaseNode::class, 'getDeprecation')
575+
? ['api-platform/core', $version, $message]
576+
: [$message];
577+
}
570578
}

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
@@ -1030,6 +1030,11 @@ private function getPartialContainerBuilderProphecy($configuration = null)
10301030
$containerBuilderProphecy->removeBindings(Argument::type('string'))->will(function () {});
10311031
}
10321032

1033+
$containerBuilderProphecy->getDefinition(Argument::type('string'))
1034+
->willReturn($this->prophesize(Definition::class)->reveal());
1035+
$containerBuilderProphecy->getAlias(Argument::type('string'))
1036+
->willReturn($this->prophesize(Alias::class)->reveal());
1037+
10331038
return $containerBuilderProphecy;
10341039
}
10351040

@@ -1393,6 +1398,11 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo
13931398
$containerBuilderProphecy->getDefinition('api_platform.graphql.subscription.mercure_iri_generator')->willReturn($definitionDummy);
13941399
$this->childDefinitionProphecy->setPublic(true)->will(function () {});
13951400

1401+
$containerBuilderProphecy->getDefinition(Argument::type('string'))
1402+
->willReturn($this->prophesize(Definition::class)->reveal());
1403+
$containerBuilderProphecy->getAlias(Argument::type('string'))
1404+
->willReturn($this->prophesize(Alias::class)->reveal());
1405+
13961406
return $containerBuilderProphecy;
13971407
}
13981408

0 commit comments

Comments
 (0)