Skip to content

Commit

Permalink
Handle deprecations from Symfony 5.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed May 31, 2020
1 parent d84282f commit c163d51
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
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>
</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 @@ -1348,6 +1348,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

0 comments on commit c163d51

Please sign in to comment.