From fa62e5068e81c65cd2676675da4caeec438a33cc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 28 Sep 2017 16:57:16 +0200 Subject: [PATCH] [HttpKernel] Deprecate some compiler passes in favor of tagged iterator args --- UPGRADE-3.4.md | 14 +++- UPGRADE-4.0.md | 14 +++- .../Bundle/FrameworkBundle/CHANGELOG.md | 6 +- .../Compiler/AddCacheClearerPass.php | 26 ++++++- .../Compiler/AddCacheWarmerPass.php | 29 ++++++- .../Compiler/ConfigCachePass.php | 4 +- .../FrameworkBundle/FrameworkBundle.php | 6 -- .../Resources/config/services.xml | 6 +- .../DependencyInjection/ConfigCachePass.php | 4 + .../ConfigCachePassTest.php | 3 + src/Symfony/Component/HttpKernel/CHANGELOG.md | 4 + .../CacheClearer/ChainCacheClearer.php | 8 +- .../CacheWarmer/CacheWarmerAggregate.php | 17 +++- .../AddCacheClearerPass.php | 50 ------------ .../AddCacheWarmerPass.php | 53 ------------- .../CacheClearer/ChainCacheClearerTest.php | 3 + .../CacheWarmer/CacheWarmerAggregateTest.php | 6 ++ .../AddCacheClearerPassTest.php | 53 ------------- .../AddCacheWarmerPassTest.php | 77 ------------------- 19 files changed, 119 insertions(+), 264 deletions(-) delete mode 100644 src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheClearerPass.php delete mode 100644 src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheWarmerPass.php delete mode 100644 src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheClearerPassTest.php delete mode 100644 src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheWarmerPassTest.php diff --git a/UPGRADE-3.4.md b/UPGRADE-3.4.md index f6d137842b..ffc6458fec 100644 --- a/UPGRADE-3.4.md +++ b/UPGRADE-3.4.md @@ -136,12 +136,10 @@ FrameworkBundle instead (e.g. `--prefix=""`) * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass` - class has been deprecated and will be removed in 4.0. Use the - `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` class instead. + class has been deprecated and will be removed in 4.0. Use tagged iterator arguments instead. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass` - class has been deprecated and will be removed in 4.0. Use the - `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` class instead. + class has been deprecated and will be removed in 4.0. Use tagged iterator arguments instead. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass` class has been deprecated and will be removed in 4.0. Use the @@ -260,6 +258,14 @@ HttpKernel * The `Symfony\Component\HttpKernel\Config\EnvParametersResource` class has been deprecated and will be removed in 4.0. + * The `ChainCacheClearer::add()` method has been deprecated and will be removed in 4.0, + inject the list of clearers as a constructor argument instead. + + * The `CacheWarmerAggregate::add()` and `setWarmers()` methods have been deprecated and will be removed in 4.0, + inject the list of clearers as a constructor argument instead. + + * The `CacheWarmerAggregate` and `ChainCacheClearer` classes have been made final. + Process ------- diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 8174f1a4d2..1f122c002d 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -384,7 +384,7 @@ FrameworkBundle class instead. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass` class has been removed. - Use `Symfony\Component\Config\DependencyInjection\ConfigCachePass` class instead. + Use tagged iterator arguments instead. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass` class has been removed. Use the `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` @@ -439,10 +439,10 @@ FrameworkBundle been removed. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass` class has been removed. - Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` class instead. + Use tagged iterator arguments instead. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass` class has been removed. - Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` class instead. + Use tagged iterator arguments instead. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass` class has been removed. Use the @@ -603,6 +603,14 @@ HttpKernel * The `Symfony\Component\HttpKernel\Config\EnvParametersResource` class has been removed. + * The `ChainCacheClearer::add()` method has been removed, + inject the list of clearers as a constructor argument instead. + + * The `CacheWarmerAggregate::add()` and `setWarmers()` methods have been removed, + inject the list of clearers as a constructor argument instead. + + * The `CacheWarmerAggregate` and `ChainCacheClearer` classes have been made final. + Ldap ---- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 0c7581e7c0..4ff27e13a4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -12,8 +12,8 @@ CHANGELOG require symfony/stopwatch` in your `dev` environment. * Deprecated using the `KERNEL_DIR` environment variable with `KernelTestCase::getKernelClass()`. * Deprecated the `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()` methods. - * Deprecated `AddCacheClearerPass`, use `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` instead. - * Deprecated `AddCacheWarmerPass`, use `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` instead. + * Deprecated `AddCacheClearerPass`, use tagged iterator arguments instead. + * Deprecated `AddCacheWarmerPass`, use tagged iterator arguments instead. * Deprecated `TranslationDumperPass`, use `Symfony\Component\Translation\DependencyInjection\TranslationDumperPass` instead * Deprecated `TranslationExtractorPass`, use @@ -82,7 +82,7 @@ CHANGELOG * Deprecated `SessionListener` * Deprecated `TestSessionListener` * Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass`. - Use `Symfony\Component\Console\DependencyInjection\ConfigCachePass` instead. + Use tagged iterator arguments instead. * Deprecated `PropertyInfoPass`, use `Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass` instead * Deprecated `ControllerArgumentValueResolverPass`. Use `Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass` instead diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheClearerPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheClearerPass.php index c58fd6843d..f650826be0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheClearerPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheClearerPass.php @@ -11,17 +11,35 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; -@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); +@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); -use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass as BaseAddCacheClearerPass; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Reference; /** * Registers the cache clearers. * - * @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseAddCacheClearerPass instead}. + * @deprecated since version 3.4, to be removed in 4.0. Use tagged iterator arguments. * * @author Dustin Dobervich */ -class AddCacheClearerPass extends BaseAddCacheClearerPass +class AddCacheClearerPass implements CompilerPassInterface { + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('cache_clearer')) { + return; + } + + $clearers = array(); + foreach ($container->findTaggedServiceIds('kernel.cache_clearer', true) as $id => $attributes) { + $clearers[] = new Reference($id); + } + + $container->getDefinition('cache_clearer')->replaceArgument(0, $clearers); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php index 4b427684a9..7a1b2e98bb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddCacheWarmerPass.php @@ -11,17 +11,38 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; -@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); +@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); -use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass as BaseAddCacheWarmerPass; +use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; /** * Registers the cache warmers. * - * @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseAddCacheWarmerPass instead}. + * @deprecated since version 3.4, to be removed in 4.0. Use tagged iterator arguments instead. * * @author Fabien Potencier */ -class AddCacheWarmerPass extends BaseAddCacheWarmerPass +class AddCacheWarmerPass implements CompilerPassInterface { + use PriorityTaggedServiceTrait; + + /** + * {@inheritdoc} + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasDefinition('cache_warmer')) { + return; + } + + $warmers = $this->findAndSortTaggedServices('kernel.cache_warmer', $container); + + if (empty($warmers)) { + return; + } + + $container->getDefinition('cache_warmer')->replaceArgument(0, $warmers); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ConfigCachePass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ConfigCachePass.php index 7fcea3b0e5..eae4311a34 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ConfigCachePass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ConfigCachePass.php @@ -13,12 +13,12 @@ namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler; use Symfony\Component\Config\DependencyInjection\ConfigCachePass as BaseConfigCachePass; -@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); +@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); /** * Adds services tagged config_cache.resource_checker to the config_cache_factory service, ordering them by priority. * - * @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseConfigCachePass} instead. + * @deprecated since version 3.3, to be removed in 4.0. Use tagged iterator arguments instead. * * @author Matthias Pigulla * @author Benjamin Klotz diff --git a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php index c6936d35be..62df8c5ed9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php +++ b/src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php @@ -25,11 +25,8 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLan use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass; use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass; -use Symfony\Component\Config\DependencyInjection\ConfigCachePass; use Symfony\Component\Console\Application; use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass; -use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass; -use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass; use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass; use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass; use Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass; @@ -102,8 +99,6 @@ class FrameworkBundle extends Bundle $container->addCompilerPass(new TranslatorPass('translator.default', 'translation.loader')); } $container->addCompilerPass(new LoggingTranslatorPass()); - $container->addCompilerPass(new AddCacheWarmerPass()); - $container->addCompilerPass(new AddCacheClearerPass()); $container->addCompilerPass(new AddExpressionLanguageProvidersPass()); $this->addCompilerPassIfExists($container, TranslationExtractorPass::class); $this->addCompilerPassIfExists($container, TranslationDumperPass::class); @@ -124,7 +119,6 @@ class FrameworkBundle extends Bundle $container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32); $container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING); $container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255); - $this->addCompilerPassIfExists($container, ConfigCachePass::class); $container->addCompilerPass(new CacheCollectorPass(), PassConfig::TYPE_BEFORE_REMOVING); } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml index 0bae93663b..31ca2075e4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml @@ -24,7 +24,7 @@ - + @@ -40,7 +40,7 @@ - + @@ -63,7 +63,7 @@ - + diff --git a/src/Symfony/Component/Config/DependencyInjection/ConfigCachePass.php b/src/Symfony/Component/Config/DependencyInjection/ConfigCachePass.php index 02cae0d2b2..665cd39e8d 100644 --- a/src/Symfony/Component/Config/DependencyInjection/ConfigCachePass.php +++ b/src/Symfony/Component/Config/DependencyInjection/ConfigCachePass.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Config\DependencyInjection; +@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use tagged iterator arguments instead.', ConfigCachePass::class), E_USER_DEPRECATED); + use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; @@ -21,6 +23,8 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; * * @author Matthias Pigulla * @author Benjamin Klotz + * + * @deprecated since version 3.4, to be removed in 4.0. Use tagged iterator arguments instead. */ class ConfigCachePass implements CompilerPassInterface { diff --git a/src/Symfony/Component/Config/Tests/DependencyInjection/ConfigCachePassTest.php b/src/Symfony/Component/Config/Tests/DependencyInjection/ConfigCachePassTest.php index 7452755f50..4f9c12f8c4 100644 --- a/src/Symfony/Component/Config/Tests/DependencyInjection/ConfigCachePassTest.php +++ b/src/Symfony/Component/Config/Tests/DependencyInjection/ConfigCachePassTest.php @@ -17,6 +17,9 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\Config\DependencyInjection\ConfigCachePass; +/** + * @group legacy + */ class ConfigCachePassTest extends TestCase { public function testThatCheckersAreProcessedInPriorityOrder() diff --git a/src/Symfony/Component/HttpKernel/CHANGELOG.md b/src/Symfony/Component/HttpKernel/CHANGELOG.md index 66e3b38e25..0c4ee8fa01 100644 --- a/src/Symfony/Component/HttpKernel/CHANGELOG.md +++ b/src/Symfony/Component/HttpKernel/CHANGELOG.md @@ -12,6 +12,10 @@ CHANGELOG * added `AddCacheWarmerPass` * deprecated `EnvParametersResource` * added `Symfony\Component\HttpKernel\Client::catchExceptions()` + * deprecated the `ChainCacheClearer::add()` method + * deprecated the `CacheaWarmerAggregate::add()` and `setWarmers()` methods + * made `CacheWarmerAggregate` and `ChainCacheClearer` classes final + 3.3.0 ----- diff --git a/src/Symfony/Component/HttpKernel/CacheClearer/ChainCacheClearer.php b/src/Symfony/Component/HttpKernel/CacheClearer/ChainCacheClearer.php index c749c7c0a4..f85d6d1435 100644 --- a/src/Symfony/Component/HttpKernel/CacheClearer/ChainCacheClearer.php +++ b/src/Symfony/Component/HttpKernel/CacheClearer/ChainCacheClearer.php @@ -15,6 +15,8 @@ namespace Symfony\Component\HttpKernel\CacheClearer; * ChainCacheClearer. * * @author Dustin Dobervich + * + * @final since version 3.4 */ class ChainCacheClearer implements CacheClearerInterface { @@ -28,7 +30,7 @@ class ChainCacheClearer implements CacheClearerInterface * * @param array $clearers The initial clearers */ - public function __construct(array $clearers = array()) + public function __construct($clearers = array()) { $this->clearers = $clearers; } @@ -47,9 +49,13 @@ class ChainCacheClearer implements CacheClearerInterface * Adds a cache clearer to the aggregate. * * @param CacheClearerInterface $clearer + * + * @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead. */ public function add(CacheClearerInterface $clearer) { + @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); + $this->clearers[] = $clearer; } } diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php index e5f4e4fa4a..c53b4e4bf0 100644 --- a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php +++ b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php @@ -15,17 +15,21 @@ namespace Symfony\Component\HttpKernel\CacheWarmer; * Aggregates several cache warmers into a single one. * * @author Fabien Potencier + * + * @final since version 3.4 */ class CacheWarmerAggregate implements CacheWarmerInterface { protected $warmers = array(); protected $optionalsEnabled = false; + private $triggerDeprecation = false; - public function __construct(array $warmers = array()) + public function __construct($warmers = array()) { foreach ($warmers as $warmer) { $this->add($warmer); } + $this->triggerDeprecation = true; } public function enableOptionalWarmers() @@ -53,6 +57,8 @@ class CacheWarmerAggregate implements CacheWarmerInterface * Checks whether this warmer is optional or not. * * @return bool always false + * + * @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead. */ public function isOptional() { @@ -61,14 +67,23 @@ class CacheWarmerAggregate implements CacheWarmerInterface public function setWarmers(array $warmers) { + @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); + $this->warmers = array(); foreach ($warmers as $warmer) { $this->add($warmer); } } + /** + * @deprecated since version 3.4, to be removed in 4.0, inject the list of clearers as a constructor argument instead. + */ public function add(CacheWarmerInterface $warmer) { + if ($this->triggerDeprecation) { + @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); + } + $this->warmers[] = $warmer; } } diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheClearerPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheClearerPass.php deleted file mode 100644 index 2689440bd7..0000000000 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheClearerPass.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\DependencyInjection; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\Reference; - -/** - * Registers the cache clearers. - * - * @author Dustin Dobervich - */ -class AddCacheClearerPass implements CompilerPassInterface -{ - private $cacheClearerId; - private $cacheClearerTag; - - public function __construct($cacheClearerId = 'cache_clearer', $cacheClearerTag = 'kernel.cache_clearer') - { - $this->cacheClearerId = $cacheClearerId; - $this->cacheClearerTag = $cacheClearerTag; - } - - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) - { - if (!$container->hasDefinition($this->cacheClearerId)) { - return; - } - - $clearers = array(); - foreach ($container->findTaggedServiceIds($this->cacheClearerTag, true) as $id => $attributes) { - $clearers[] = new Reference($id); - } - - $container->getDefinition($this->cacheClearerId)->replaceArgument(0, $clearers); - } -} diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheWarmerPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheWarmerPass.php deleted file mode 100644 index 6d13e1cbcb..0000000000 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheWarmerPass.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\DependencyInjection; - -use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; - -/** - * Registers the cache warmers. - * - * @author Fabien Potencier - */ -class AddCacheWarmerPass implements CompilerPassInterface -{ - use PriorityTaggedServiceTrait; - - private $cacheWarmerId; - private $cacheWarmerTag; - - public function __construct($cacheWarmerId = 'cache_warmer', $cacheWarmerTag = 'kernel.cache_warmer') - { - $this->cacheWarmerId = $cacheWarmerId; - $this->cacheWarmerTag = $cacheWarmerTag; - } - - /** - * {@inheritdoc} - */ - public function process(ContainerBuilder $container) - { - if (!$container->hasDefinition($this->cacheWarmerId)) { - return; - } - - $warmers = $this->findAndSortTaggedServices($this->cacheWarmerTag, $container); - - if (empty($warmers)) { - return; - } - - $container->getDefinition($this->cacheWarmerId)->replaceArgument(0, $warmers); - } -} diff --git a/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php b/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php index 1bc853349f..ec2ecff948 100644 --- a/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/CacheClearer/ChainCacheClearerTest.php @@ -39,6 +39,9 @@ class ChainCacheClearerTest extends TestCase $chainClearer->clear(self::$cacheDir); } + /** + * @group legacy + */ public function testInjectClearerUsingAdd() { $clearer = $this->getMockClearer(); diff --git a/src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerAggregateTest.php b/src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerAggregateTest.php index d07ade303f..ba159124c9 100644 --- a/src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerAggregateTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/CacheWarmer/CacheWarmerAggregateTest.php @@ -38,6 +38,9 @@ class CacheWarmerAggregateTest extends TestCase $aggregate->warmUp(self::$cacheDir); } + /** + * @group legacy + */ public function testInjectWarmersUsingAdd() { $warmer = $this->getCacheWarmerMock(); @@ -49,6 +52,9 @@ class CacheWarmerAggregateTest extends TestCase $aggregate->warmUp(self::$cacheDir); } + /** + * @group legacy + */ public function testInjectWarmersUsingSetWarmers() { $warmer = $this->getCacheWarmerMock(); diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheClearerPassTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheClearerPassTest.php deleted file mode 100644 index 3bdb84ad10..0000000000 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheClearerPassTest.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\Tests\DependencyInjection; - -use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass; - -class AddCacheClearerPassTest extends TestCase -{ - public function testThatCacheClearer() - { - $container = new ContainerBuilder(); - - $definition = $container->register('cache_clearer')->addArgument(null); - $container->register('my_cache_clearer_service1')->addTag('kernel.cache_clearer'); - - $addCacheWarmerPass = new AddCacheClearerPass(); - $addCacheWarmerPass->process($container); - - $expected = array( - new Reference('my_cache_clearer_service1'), - ); - $this->assertEquals($expected, $definition->getArgument(0)); - } - - public function testThatCompilerPassIsIgnoredIfThereIsNoCacheClearerDefinition() - { - $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock(); - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock(); - - $container->expects($this->never())->method('findTaggedServiceIds'); - $container->expects($this->never())->method('getDefinition'); - $container->expects($this->atLeastOnce()) - ->method('hasDefinition') - ->with('cache_clearer') - ->will($this->returnValue(false)); - $definition->expects($this->never())->method('replaceArgument'); - - $addCacheWarmerPass = new AddCacheClearerPass(); - $addCacheWarmerPass->process($container); - } -} diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheWarmerPassTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheWarmerPassTest.php deleted file mode 100644 index 3f7bc6e65e..0000000000 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheWarmerPassTest.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\HttpKernel\Tests\DependencyInjection; - -use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; -use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass; - -class AddCacheWarmerPassTest extends TestCase -{ - public function testThatCacheWarmersAreProcessedInPriorityOrder() - { - $container = new ContainerBuilder(); - - $definition = $container->register('cache_warmer')->addArgument(null); - $container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', array('priority' => 100)); - $container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', array('priority' => 200)); - $container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer'); - - $addCacheWarmerPass = new AddCacheWarmerPass(); - $addCacheWarmerPass->process($container); - - $expected = array( - new Reference('my_cache_warmer_service2'), - new Reference('my_cache_warmer_service1'), - new Reference('my_cache_warmer_service3'), - ); - $this->assertEquals($expected, $definition->getArgument(0)); - } - - public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition() - { - $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock(); - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock(); - - $container->expects($this->never())->method('findTaggedServiceIds'); - $container->expects($this->never())->method('getDefinition'); - $container->expects($this->atLeastOnce()) - ->method('hasDefinition') - ->with('cache_warmer') - ->will($this->returnValue(false)); - $definition->expects($this->never())->method('replaceArgument'); - - $addCacheWarmerPass = new AddCacheWarmerPass(); - $addCacheWarmerPass->process($container); - } - - public function testThatCacheWarmersMightBeNotDefined() - { - $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock(); - $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock(); - - $container->expects($this->atLeastOnce()) - ->method('findTaggedServiceIds') - ->will($this->returnValue(array())); - $container->expects($this->never())->method('getDefinition'); - $container->expects($this->atLeastOnce()) - ->method('hasDefinition') - ->with('cache_warmer') - ->will($this->returnValue(true)); - - $definition->expects($this->never())->method('replaceArgument'); - - $addCacheWarmerPass = new AddCacheWarmerPass(); - $addCacheWarmerPass->process($container); - } -}