8000 feature #24362 [HttpKernel] Deprecate some compiler passes in favor o… · symfony/symfony@a442e37 · GitHub
[go: up one dir, main page]

Skip to content

Commit a442e37

Browse files
committed
feature #24362 [HttpKernel] Deprecate some compiler passes in favor of tagged iterator args (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [HttpKernel] Deprecate some compiler passes in favor of tagged iterator args | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - More code that we can drop :) Commits ------- fa62e50 [HttpKernel] Deprecate some compiler passes in favor of tagged iterator args
2 parents 537c496 + fa62e50 commit a442e37

File tree

19 files changed

+119
-264
lines changed

19 files changed

+119
-264
lines changed

UPGRADE-3.4.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,10 @@ FrameworkBundle
136136
instead (e.g. `--prefix=""`)
137137

138138
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass`
139-
class has been deprecated and will be removed in 4.0. Use the
140-
`Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` class instead.
139+
class has been deprecated and will be removed in 4.0. Use tagged iterator arguments instead.
141140

142141
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass`
143-
class has been deprecated and will be removed in 4.0. Use the
144-
`Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` class instead.
142+
class has been deprecated and will be removed in 4.0. Use tagged iterator arguments instead.
145143

146144
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass`
147145
class has been deprecated and will be removed in 4.0. Use the
@@ -260,6 +258,14 @@ HttpKernel
260258

261259
* The `Symfony\Component\HttpKernel\Config\EnvParametersResource` class has been deprecated and will be removed in 4.0.
262260

261+
* The `ChainCacheClearer::add()` method has been deprecated and will be removed in 4.0,
262+
inject the list of clearers as a constructor argument instead.
263+
264+
* The `CacheWarmerAggregate::add()` and `setWarmers()` methods have been deprecated and will be removed in 4.0,
265+
inject the list of clearers as a constructor argument instead.
266+
267+
* The `CacheWarmerAggregate` and `ChainCacheClearer` classes have been made final.
268+
263269
Process
264270
-------
265271

UPGRADE-4.0.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ FrameworkBundle
384384
class instead.
385385

386386
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` class has been removed.
387-
Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` class instead.
387+
Use tagged iterator arguments instead.
388388

389389
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass` class has been
390390
removed. Use the `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass`
@@ -439,10 +439,10 @@ FrameworkBundle
439439
been removed.
440440

441441
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass` class has been removed.
442-
Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` class instead.
442+
Use tagged iterator arguments instead.
443443

444444
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass` class has been removed.
445-
Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` class instead.
445+
Use tagged iterator arguments instead.
446446

447447
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass`
448448
class has been removed. Use the
@@ -603,6 +603,14 @@ HttpKernel
603603

604604
* The `Symfony\Component\HttpKernel\Config\EnvParametersResource` class has been removed.
605605

606+
* The `ChainCacheClearer::add()` method has been removed,
607+
inject the list of clearers as a constructor argument instead.
608+
609+
* The `CacheWarmerAggregate::add()` and `setWarmers()` methods have been removed,
610+
inject the list of clearers as a constructor argument instead.
611+
612+
* The `CacheWarmerAggregate` and `ChainCacheClearer` classes have been made final.
613+
606614
Ldap
607615
----
608616

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ CHANGELOG
1212
require symfony/stopwatch` in your `dev` environment.
1313
* Deprecated using the `KERNEL_DIR` environment variable with `KernelTestCase::getKernelClass()`.
1414
* Deprecated the `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()` methods.
15-
* Deprecated `AddCacheClearerPass`, use `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` instead.
16-
* Deprecated `AddCacheWarmerPass`, use `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` instead.
15+
* Deprecated `AddCacheClearerPass`, use tagged iterator arguments instead.
16+
* Deprecated `AddCacheWarmerPass`, use tagged iterator arguments instead.
1717
* Deprecated `TranslationDumperPass`, use
1818
`Symfony\Component\Translation\DependencyInjection\TranslationDumperPass` instead
1919
* Deprecated `TranslationExtractorPass`, use
@@ -84,7 +84,7 @@ CHANGELOG
8484
* Deprecated `SessionListener`
8585
* Deprecated `TestSessionListener`
8686
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`.
87-
Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead.
87+
Use tagged iterator arguments instead.
8888
* Deprecated `PropertyInfoPass`, use `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` instead
8989
* Deprecated `ControllerArgumentValueResolverPass`. Use
9090
`Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass` instead

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheClearerPass.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,35 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass instead.', AddCacheClearerPass::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use tagged iterator arguments instead.', AddCacheClearerPass::class), E_USER_DEPRECATED);
1515

16-
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass as BaseAddCacheClearerPass;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18+
use Symfony\Component\DependencyInjection\Reference;
1719

1820
/**
1921
* Registers the cache clearers.
2022
*
21-
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseAddCacheClearerPass instead}.
23+
* @deprecated since version 3.4, to be removed in 4.0. Use tagged iterator arguments.
2224
*
2325
* @author Dustin Dobervich <ddobervich@gmail.com>
2426
*/
25-
class AddCacheClearerPass extends BaseAddCacheClearerPass
27+
class AddCacheClearerPass implements CompilerPassInterface
2628
{
29+
/**
30+
* {@inheritdoc}
31+
*/
32+
public function process(ContainerBuilder $container)
33+
{
34+
if (!$container->hasDefinition('cache_clearer')) {
35+
return;
36+
}
37+
38+
$clearers = array();
39+
foreach ($container->findTaggedServiceIds('kernel.cache_clearer', true) as $id => $attributes) {
40+
$clearers[] = new Reference($id);
41+
}
42+
43+
$container->getDefinition('cache_clearer')->replaceArgument(0, $clearers);
44+
}
2745
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,38 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass instead.', AddCacheWarmerPass::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use tagged iterator arguments instead.', AddCacheWarmerPass::class), E_USER_DEPRECATED);
1515

16-
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass as BaseAddCacheWarmerPass;
16+
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1719

1820
/**
1921
* Registers the cache warmers.
2022
*
21-
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseAddCacheWarmerPass instead}.
23+
* @deprecated since version 3.4, to be removed in 4.0. Use tagged iterator arguments instead.
2224
*
2325
* @author Fabien Potencier <fabien@symfony.com>
2426
*/
25-
class AddCacheWarmerPass extends BaseAddCacheWarmerPass
27+
class AddCacheWarmerPass implements CompilerPassInterface
2628
{
29+
use PriorityTaggedServiceTrait;
30+
31+
/**
32+
* {@inheritdoc}
33+
*/
34+
public function process(ContainerBuilder $container)
35+
{
36+
if (!$container->hasDefinition('cache_warmer')) {
37+
return;
38+
}
39+
40+
$warmers = $this->findAndSortTaggedServices('kernel.cache_warmer', $container);
41+
42+
if (empty($warmers)) {
43+
return;
44+
}
45+
46+
$container->getDefinition('cache_warmer')->replaceArgument(0, $warmers);
47+
}
2748
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ConfigCachePass.php

Lines changed: 2 additions & 2 deletions
< 10000 td data-grid-cell-id="diff-6aca67501ead607ec8ec838ed212f270d3d2dd947872b0b2f394027fc02d745c-21-21-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-additionNum-bgColor, var(--diffBlob-addition-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
use Symfony\Component\Config\DependencyInjection\ConfigCachePass as BaseConfigCachePass;
1515

16-
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Config\DependencyInjection\ConfigCachePass instead.', ConfigCachePass::class), E_USER_DEPRECATED);
16+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use tagged iterator arguments instead.', ConfigCachePass::class), E_USER_DEPRECATED);
1717

1818
/**
1919
* Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority.
2020
*
21-
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseConfigCachePass} instead.
21+
* @deprecated since version 3.3, to be removed in 4.0. Use tagged iterator arguments instead.
2222
*
2323
* @author Matthias Pigulla <mp@webfactory.de>
2424
* @author Benjamin Klotz <bk@webfactory.de>

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
2626
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
2727
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
28-
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
2928
use Symfony\Component\Console\Application;
3029
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
31-
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass;
32-
use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass;
3330
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
3431
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
3532
use Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass;
@@ -102,8 +99,6 @@ public function build(ContainerBuilder $container)
10299
$container->addCompilerPass(new TranslatorPass('translator.default', 'translation.loader'));
103100
}
104101
$container->addCompilerPass(new LoggingTranslatorPass());
105-
$container->addCompilerPass(new AddCacheWarmerPass());
106-
$container->addCompilerPass(new AddCacheClearerPass());
107102
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
108103
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);
109104
$this->addCompilerPassIfExists($container, TranslationDumperPass::class);
@@ -124,7 +119,6 @@ public function build(ContainerBuilder $container)
124119
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
125120
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
126121
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);
127-
$this->addCompilerPassIfExists($container, ConfigCachePass::class);
128122
$container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING);
129123
}
130124
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<service id="Symfony\Component\HttpFoundation\RequestStack" alias="request_stack" />
2525

2626
<service id="cache_warmer" class="Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate" public="true">
27-
<argument type="collection" />
27+
<argument type="tagged" tag="kernel.cache_warmer" />
2828
</service>
2929

3030
<service id="kernel.class_cache.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassCacheCacheWarmer">
@@ -40,7 +40,7 @@
4040
</service>
4141

4242
<service id="cache_clearer" class="Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer" public="true">
43-
<argument type="collection" />
43+
<argument type="tagged" tag="kernel.cache_clearer" />
4444
</service>
4545

4646
<service id="kernel" synthetic="true" public="true" />
@@ -63,7 +63,7 @@
6363
</service>
6464

6565
<service id="config_cache_factory" class="Symfony\Component\Config\ResourceCheckerConfigCacheFactory">
66-
<argument /> <!-- resource checkers -->
66+
<argument type="tagged" tag="config_cache.resource_checker" />
6767
</service>
6868

6969
<service id="Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker">

src/Symfony/Component/Config/DependencyInjection/ConfigCachePass.php

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

1212
namespace Symfony\Component\Config\DependencyInjection;
1313

14+
@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4 37BF .0. Use tagged iterator arguments instead.', ConfigCachePass::class), E_USER_DEPRECATED);
15+
1416
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
1517
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1618
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
@@ -21,6 +23,8 @@
2123
*
2224
* @author Matthias Pigulla <mp@webfactory.de>
2325
* @author Benjamin Klotz <bk@webfactory.de>
26+
*
27+
* @deprecated since version 3.4, to be removed in 4.0. Use tagged iterator arguments instead.
2428
*/
2529
class ConfigCachePass implements CompilerPassInterface
2630
{

src/Symfony/Component/Config/Tests/DependencyInjection/ConfigCachePassTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
1919

20+
/**
21+
* @group legacy
22+
*/
2023
class ConfigCachePassTest extends TestCase
2124
{
2225
public function testThatCheckersAreProcessedInPriorityOrder()

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ CHANGELOG
1212
* added `AddCacheWarmerPass`
1313
* deprecated `EnvParametersResource`
1414
* added `Symfony\Component\HttpKernel\Client::catchExceptions()`
15+
* deprecated the `ChainCacheClearer::add()` method
16+
* deprecated the `CacheaWarmerAggregate::add()` and `setWarmers()` methods
17+
* made `CacheWarmerAggregate` and `ChainCacheClearer` classes final
18+
1519

1620
3.3.0
1721
-----

src/Symfony/Component/HttpKernel/CacheClearer/ChainCacheClearer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* ChainCacheClearer.
1616
*
1717
* @author Dustin Dobervich <ddobervich@gmail.com>
18+
*
19+
* @final since version 3.4
1820
*/
1921
class ChainCacheClearer implements CacheClearerInterface
2022
{
@@ -28,7 +30,7 @@ class ChainCacheClearer implements CacheClearerInterface
2830
*
2931
* @param array $clearers The initial clearers
3032
*/
31-
public function __construct(array $clearers = array())
33+
public function __construct($clearers = array())
3234
{
3335
$this->clearers = $clearers;
3436
}
@@ -47,9 +49,13 @@ public function clear($cacheDir)
4749
* Adds a cache clearer to the aggregate.
4850
*
4951
* @param CacheClearerInterface $clearer
52+
*
53+
* @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead.
5054
*/
5155
public function add(CacheClearerInterface $clearer)
5256
{
57+
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.4 and will be removed in 4.0, inject the list of clearers as a constructor argument instead.', __METHOD__), E_USER_DEPRECATED);
58+
5359
$this->clearers[] = $clearer;
5460
}
5561
}

src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,21 @@
1515
* Aggregates several cache warmers into a single one.
1616
*
1717
* @author Fabien Potencier <fabien@symfony.com>
18+
*
19+
* @final since version 3.4
1820
*/
1921
class CacheWarmerAggregate implements CacheWarmerInterface
2022
{
2123
protected $warmers = array();
2224
protected $optionalsEnabled = false;
25+
private $triggerDeprecation = false;
2326

24-
public function __construct(array $warmers = array())
27+
public function __construct($warmers = array())
2528
{
2629
foreach ($warmers as $warmer) {
2730
$this->add($warmer);
2831
}
32+
$this->triggerDeprecation = true;
2933
}
3034

3135
public function enableOptionalWarmers()
@@ -53,6 +57,8 @@ public function warmUp($cacheDir)
5357
* Checks whether this warmer is optional or not.
5458
*
5559
* @return bool always false
60+
*
61+
* @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead.
5662
*/
5763
public function isOptional()
5864
{
@@ -61,14 +67,23 @@ public function isOptional()
6167

6268
public function setWarmers(array $warmers)
6369
{
70+
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.4 and will be removed in 4.0, inject the list of clearers as a constructor argument instead.', __METHOD__), E_USER_DEPRECATED);
71+
6472
$this->warmers = array();
6573
foreach ($warmers as $warmer) {
6674
$this->add($warmer);
6775
}
6876
}
6977

78+
/**
79+
* @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead.
80+
*/
7081
public function add(CacheWarmerInterface $warmer)
7182
{
83+
if ($this->triggerDeprecation) {
84+
@trigger_error(sprintf('The "%s()" method is deprecated since version 3.4 and will be removed in 4.0, inject the list of clearers as a constructor argument instead.', __METHOD__), E_USER_DEPRECATED);
85+
}
86+
7287
$this->warmers[] = $warmer;
7388
}
7489
}

0 commit comments

Comments
 (0)
0