Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deprecations from Symfony 5.1 #3589

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand Down Expand Up @@ -145,6 +146,19 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
$loader->load('data_provider.xml');
$loader->load('filter.xml');

$container->getDefinition('api_platform.operation_method_resolver')
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%service_id%" service is deprecated since API Platform 2.5.'));
$container->getDefinition('api_platform.formats_provider')
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%service_id%" service is deprecated since API Platform 2.5.'));
$container->getAlias('ApiPlatform\Core\Api\OperationAwareFormatsProviderInterface')
->setDeprecated(...$this->buildDeprecationArgs('2.5', 'The "%alias_id%" alias is deprecated since API Platform 2.5.'));
$container->getDefinition('api_platform.operation_path_resolver.underscore')
->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.'));
$container->getDefinition('api_platform.operation_path_resolver.dash')
->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.'));
$container->getDefinition('api_platform.filters')
->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.'));

if (class_exists(Uuid::class)) {
$loader->load('ramsey_uuid.xml');
}
Expand Down Expand Up @@ -416,6 +430,11 @@ private function registerLegacyBundlesConfiguration(ContainerBuilder $container,

if (isset($bundles['NelmioApiDocBundle']) && $config['enable_nelmio_api_doc']) {
$loader->load('nelmio_api_doc.xml');

$container->getDefinition('api_platform.nelmio_api_doc.annotations_provider')
->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.'));
$container->getDefinition('api_platform.nelmio_api_doc.parser')
->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.'));
}
}

Expand Down Expand Up @@ -609,4 +628,11 @@ private function registerSecurityConfiguration(ContainerBuilder $container, XmlF
$loader->load('security.xml');
}
}

private function buildDeprecationArgs(string $version, string $message): array
{
return method_exists(Definition::class, 'getDeprecation')
? ['api-platform/core', $version, $message]
: [true, $message];
}
}
12 changes: 10 additions & 2 deletions src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Symfony\Bundle\FullStack;
use Symfony\Bundle\MercureBundle\MercureBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Definition\BaseNode;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand Down Expand Up @@ -85,7 +86,7 @@ public function getConfigTreeBuilder()
->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
->scalarNode('default_operation_path_resolver')
->defaultValue('api_platform.operation_path_resolver.underscore')
->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.')
->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.'))
->info('Specify the default operation path resolver to use for generating resources operations path.')
->end()
->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
Expand All @@ -109,7 +110,7 @@ public function getConfigTreeBuilder()
->booleanNode('enable_fos_user')->defaultValue(class_exists(FOSUserBundle::class))->info('Enable the FOSUserBundle integration.')->end()
->booleanNode('enable_nelmio_api_doc')
->defaultFalse()
->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.')
->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.'))
->info('Enable the NelmioApiDocBundle integration.')
->end()
->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end()
Expand Down Expand Up @@ -494,4 +495,11 @@ private function addFormatSection(ArrayNodeDefinition $rootNode, string $key, ar
->end()
->end();
}

private function buildDeprecationArgs(string $version, string $message): array
{
return method_exists(BaseNode::class, 'getDeprecation')
? ['api-platform/core', $version, $message]
: [$message];
}
}
11 changes: 2 additions & 9 deletions src/Bridge/Symfony/Bundle/Resources/config/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<service id="api_platform.operation_method_resolver" class="ApiPlatform\Core\Bridge\Symfony\Routing\OperationMethodResolver" public="false">
<argument type="service" id="api_platform.router" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<deprecated>The "%service_id%" service is deprecated since API Platform 2.5.</deprecated>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 I haven't found a way to produce an XML file that can be loaded with DependencyInjection 4.4 and 5.1 without errors:

  • DI 5.1 triggers a deprecation if the attributes package and version are missing.
  • DI 4.4 throws an exception, if those attributes are present.

This is why I'm deprecating the services inside the extension now.

</service>

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

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

<!-- Serializer -->
Expand Down Expand Up @@ -139,13 +136,9 @@
<argument type="service" id="api_platform.path_segment_name_generator" />
</service>

<service id="api_platform.operation_path_resolver.underscore" class="ApiPlatform\Core\PathResolver\UnderscoreOperationPathResolver" public="false">
<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>
</service>
<service id="api_platform.operation_path_resolver.underscore" class="ApiPlatform\Core\PathResolver\UnderscoreOperationPathResolver" public="false" />

<service id="api_platform.operation_path_resolver.dash" class="ApiPlatform\Core\PathResolver\DashOperationPathResolver" public="false">
<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>
</service>
<service id="api_platform.operation_path_resolver.dash" class="ApiPlatform\Core\PathResolver\DashOperationPathResolver" public="false" />

<!-- Path name generator -->

Expand Down
1 change: 0 additions & 1 deletion src/Bridge/Symfony/Bundle/Resources/config/filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<service id="api_platform.filter_collection_factory" class="ApiPlatform\Core\Api\FilterCollectionFactory" />

<service id="api_platform.filters" class="ApiPlatform\Core\Api\FilterCollection">
<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>
<factory service="api_platform.filter_collection_factory" method="createFilterCollectionFromLocator" />
<argument type="service" id="api_platform.filter_locator" />
</service>
Expand Down
4 changes: 0 additions & 4 deletions src/Bridge/Symfony/Bundle/Resources/config/nelmio_api_doc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

<services>
<service id="api_platform.nelmio_api_doc.annotations_provider" class="ApiPlatform\Core\Bridge\NelmioApiDoc\Extractor\AnnotationsProvider\ApiPlatformProvider">
<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>

<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />
<argument type="service" id="api_platform.hydra.normalizer.documentation" />
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
Expand All @@ -18,8 +16,6 @@
</service>

<service id="api_platform.nelmio_api_doc.parser" class="ApiPlatform\Core\Bridge\NelmioApiDoc\Parser\ApiPlatformParser">
<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>

<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument type="service" id="api_platform.metadata.property.name_collection_factory" />
<argument type="service" id="api_platform.metadata.property.metadata_factory" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,11 @@ private function getPartialContainerBuilderProphecy($configuration = null)
$containerBuilderProphecy->removeBindings(Argument::type('string'))->will(function () {});
}

$containerBuilderProphecy->getDefinition(Argument::type('string'))
->willReturn($this->prophesize(Definition::class)->reveal());
$containerBuilderProphecy->getAlias(Argument::type('string'))
->willReturn($this->prophesize(Alias::class)->reveal());

return $containerBuilderProphecy;
}

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

$containerBuilderProphecy->getDefinition(Argument::type('string'))
->willReturn($this->prophesize(Definition::class)->reveal());
$containerBuilderProphecy->getAlias(Argument::type('string'))
->willReturn($this->prophesize(Alias::class)->reveal());

return $containerBuilderProphecy;
}

Expand Down