Skip to content

Commit d26805c

Browse files
soyukathbil
andauthored
Fix sf5 deprecation notices (#3)
* Fix sf5 deprecation notices * Use final Co-authored-by: Thomas Billard <[email protected]>
1 parent 9f3f840 commit d26805c

File tree

6 files changed

+109
-15
lines changed

6 files changed

+109
-15
lines changed

src/Bridge/Symfony/Bundle/ApiPlatformBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\AnnotationFilterPass;
1717
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\DataProviderPass;
18+
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\DeprecateMercurePublisherPass;
1819
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\ElasticsearchClientPass;
1920
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\FilterPass;
2021
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\GraphQlMutationResolverPass;
@@ -48,6 +49,7 @@ public function build(ContainerBuilder $container)
4849
$container->addCompilerPass(new GraphQlTypePass());
4950
$container->addCompilerPass(new GraphQlQueryResolverPass());
5051
$container->addCompilerPass(new GraphQlMutationResolverPass());
52+
$container->addCompilerPass(new DeprecateMercurePublisherPass());
5153
$container->addCompilerPass(new MetadataAwareNameConverterPass());
5254
}
5355
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler;
15+
16+
use Symfony\Component\Config\Definition\BaseNode;
17+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18+
use Symfony\Component\DependencyInjection\ContainerBuilder;
19+
20+
/**
21+
* Handles Mercure Publisher depreciation.
22+
*
23+
* @internal calls `setDeprecated` method with valid arguments
24+
* depending which version of symfony/dependency-injection is used
25+
*/
26+
final class DeprecateMercurePublisherPass implements CompilerPassInterface
27+
{
28+
public function process(ContainerBuilder $container)
29+
{
30+
$container
31+
->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish')
32+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'Using "%alias_id%" service is deprecated since API Platform 2.6. Use "api_platform.doctrine.orm.listener.mercure.publish" instead.'));
33+
}
34+
35+
private function buildDeprecationArgs(string $version, string $message): array
36+
{
37+
return method_exists(BaseNode::class, 'getDeprecation')
38+
? ['api-platform/core', $version, $message]
39+
: [$message];
40+
}
41+
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,37 +136,37 @@ public function getConfigTreeBuilder()
136136
->addDefaultsIfNotSet()
137137
->children()
138138
->booleanNode('enabled')
139-
->setDeprecated('The use of the `collection.pagination.enabled` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_enabled` instead.')
139+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `collection.pagination.enabled` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_enabled` instead.'))
140140
->defaultTrue()
141141
->info('To enable or disable pagination for all resource collections by default.')
142142
->end()
143143
->booleanNode('partial')
144-
->setDeprecated('The use of the `collection.pagination.partial` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_partial` instead.')
144+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `collection.pagination.partial` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_partial` instead.'))
145145
->defaultFalse()
146146
->info('To enable or disable partial pagination for all resource collections by default when pagination is enabled.')
147147
->end()
148148
->booleanNode('client_enabled')
149-
->setDeprecated('The use of the `collection.pagination.client_enabled` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_client_enabled` instead.')
149+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `collection.pagination.client_enabled` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_client_enabled` instead.'))
150150
->defaultFalse()
151151
->info('To allow the client to enable or disable the pagination.')
152152
->end()
153153
->booleanNode('client_items_per_page')
154-
->setDeprecated('The use of the `collection.pagination.client_items_per_page` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_client_items_per_page` instead.')
154+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `collection.pagination.client_items_per_page` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_client_items_per_page` instead.'))
155155
->defaultFalse()
156156
->info('To allow the client to set the number of items per page.')
157157
->end()
158158
->booleanNode('client_partial')
159-
->setDeprecated('The use of the `collection.pagination.client_partial` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_client_partial` instead.')
159+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `collection.pagination.client_partial` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_client_partial` instead.'))
160160
->defaultFalse()
161161
->info('To allow the client to enable or disable partial pagination.')
162162
->end()
163163
->integerNode('items_per_page')
164-
->setDeprecated('The use of the `collection.pagination.items_per_page` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_items_per_page` instead.')
164+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `collection.pagination.items_per_page` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_items_per_page` instead.'))
165165
->defaultValue(30)
166166
->info('The default number of items per page.')
167167
->end()
168168
->integerNode('maximum_items_per_page')
169-
->setDeprecated('The use of the `collection.pagination.maximum_items_per_page` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_maximum_items_per_page` instead.')
169+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `collection.pagination.maximum_items_per_page` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.pagination_maximum_items_per_page` instead.'))
170170
->defaultNull()
171171
->info('The maximum number of items per page.')
172172
->end()
@@ -350,22 +350,22 @@ private function addHttpCacheSection(ArrayNodeDefinition $rootNode): void
350350
->addDefaultsIfNotSet()
351351
->children()
352352
->booleanNode('etag')
353-
->setDeprecated('The use of the `http_cache.etag` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.cache_headers.etag` instead.')
353+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `http_cache.etag` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.cache_headers.etag` instead.'))
354354
->defaultTrue()
355355
->info('Automatically generate etags for API responses.')
356356
->end()
357357
->integerNode('max_age')
358-
->setDeprecated('The use of the `http_cache.max_age` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.cache_headers.max_age` instead.')
358+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `http_cache.max_age` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.cache_headers.max_age` instead.'))
359359
->defaultNull()
360360
->info('Default value for the response max age.')
361361
->end()
362362
->integerNode('shared_max_age')
363-
->setDeprecated('The use of the `http_cache.shared_max_age` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.cache_headers.shared_max_age` instead.')
363+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `http_cache.shared_max_age` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.cache_headers.shared_max_age` instead.'))
364364
->defaultNull()
365365
->info('Default value for the response shared (proxy) max age.')
366366
->end()
367367
->arrayNode('vary')
368-
->setDeprecated('The use of the `http_cache.vary` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.cache_headers.vary` instead.')
368+
->setDeprecated(...$this->buildDeprecationArgs('2.6', 'The use of the `http_cache.vary` has been deprecated in 2.6 and will be removed in 3.0. Use `defaults.cache_headers.vary` instead.'))
369369
->defaultValue(['Accept'])
370370
->prototype('scalar')->end()
371371
->info('Default values of the "Vary" HTTP header.')

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
<tag name="doctrine.event_listener" event="postFlush" />
2424
</service>
2525

26-
<service id="api_platform.doctrine.listener.mercure.publish" alias="api_platform.doctrine.orm.listener.mercure.publish">
27-
<deprecated>Using "%alias_id%" service is deprecated since API Platform 2.6. Use "api_platform.doctrine.orm.listener.mercure.publish" instead.</deprecated>
28-
</service>
29-
3026
</services>
3127

3228
</container>

tests/Bridge/Symfony/Bundle/ApiPlatformBundleTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle;
1717
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\AnnotationFilterPass;
1818
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\DataProviderPass;
19+
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\DeprecateMercurePublisherPass;
1920
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\ElasticsearchClientPass;
2021
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\FilterPass;
2122
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\GraphQlMutationResolverPass;
@@ -45,6 +46,7 @@ public function testBuild()
4546
$containerProphecy->addCompilerPass(Argument::type(GraphQlTypePass::class))->shouldBeCalled();
4647
$containerProphecy->addCompilerPass(Argument::type(GraphQlQueryResolverPass::class))->shouldBeCalled();
4748
$containerProphecy->addCompilerPass(Argument::type(GraphQlMutationResolverPass::class))->shouldBeCalled();
49+
$containerProphecy->addCompilerPass(Argument::type(DeprecateMercurePublisherPass::class))->shouldBeCalled();
4850
$containerProphecy->addCompilerPass(Argument::type(MetadataAwareNameConverterPass::class))->shouldBeCalled();
4951

5052
$bundle = new ApiPlatformBundle();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Bridge\Symfony\Bundle\DependencyInjection\Compiler;
15+
16+
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\DeprecateMercurePublisherPass;
17+
use ApiPlatform\Core\Tests\ProphecyTrait;
18+
use PHPUnit\Framework\TestCase;
19+
use Symfony\Component\Config\Definition\BaseNode;
20+
use Symfony\Component\DependencyInjection\Alias;
21+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
22+
use Symfony\Component\DependencyInjection\ContainerBuilder;
23+
24+
final class DeprecateMercurePublisherPassTest extends TestCase
25+
{
26+
use ProphecyTrait;
27+
28+
public function testProcess()
29+
{
30+
$deprecateMercurePublisherPass = new DeprecateMercurePublisherPass();
31+
32+
$this->assertInstanceOf(CompilerPassInterface::class, $deprecateMercurePublisherPass);
33+
34+
$containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
35+
$aliasProphecy = $this->prophesize(Alias::class);
36+
37+
$containerBuilderProphecy
38+
->setAlias('api_platform.doctrine.listener.mercure.publish', 'api_platform.doctrine.orm.listener.mercure.publish')
39+
->willReturn($aliasProphecy->reveal())
40+
->shouldBeCalled();
41+
42+
$setDeprecatedArgs = method_exists(BaseNode::class, 'getDeprecation')
43+
? ['api-platform/core', '2.6', 'Using "%alias_id%" service is deprecated since API Platform 2.6. Use "api_platform.doctrine.orm.listener.mercure.publish" instead.']
44+
: ['Using "%alias_id%" service is deprecated since API Platform 2.6. Use "api_platform.doctrine.orm.listener.mercure.publish" instead.'];
45+
46+
$aliasProphecy
47+
->setDeprecated(...$setDeprecatedArgs)
48+
->willReturn($aliasProphecy->reveal())
49+
->shouldBeCalled();
50+
51+
$deprecateMercurePublisherPass->process($containerBuilderProphecy->reveal());
52+
}
53+
}

0 commit comments

Comments
 (0)