[HttpKernel] Deprecate some compiler passes in favor of tagged iterator args
This commit is contained in:
parent
648a8953dd
commit
fa62e5068e
@ -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
|
||||
-------
|
||||
|
||||
|
@ -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
|
||||
----
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 <ddobervich@gmail.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <fabien@symfony.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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 <mp@webfactory.de>
|
||||
* @author Benjamin Klotz <bk@webfactory.de>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
<service id="Symfony\Component\HttpFoundation\RequestStack" alias="request_stack" />
|
||||
|
||||
<service id="cache_warmer" class="Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate" public="true">
|
||||
<argument type="collection" />
|
||||
<argument type="tagged" tag="kernel.cache_warmer" />
|
||||
</service>
|
||||
|
||||
<service id="kernel.class_cache.cache_warmer" class="Symfony\Bundle\FrameworkBundle\CacheWarmer\ClassCacheCacheWarmer">
|
||||
@ -40,7 +40,7 @@
|
||||
</service>
|
||||
|
||||
<service id="cache_clearer" class="Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer" public="true">
|
||||
<argument type="collection" />
|
||||
<argument type="tagged" tag="kernel.cache_clearer" />
|
||||
</service>
|
||||
|
||||
<service id="kernel" synthetic="true" public="true" />
|
||||
@ -63,7 +63,7 @@
|
||||
</service>
|
||||
|
||||
<service id="config_cache_factory" class="Symfony\Component\Config\ResourceCheckerConfigCacheFactory">
|
||||
<argument /> <!-- resource checkers -->
|
||||
<argument type="tagged" tag="config_cache.resource_checker" />
|
||||
</service>
|
||||
|
||||
<service id="Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker">
|
||||
|
@ -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 <mp@webfactory.de>
|
||||
* @author Benjamin Klotz <bk@webfactory.de>
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Use tagged iterator arguments instead.
|
||||
*/
|
||||
class ConfigCachePass implements CompilerPassInterface
|
||||
{
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
-----
|
||||
|
@ -15,6 +15,8 @@ namespace Symfony\Component\HttpKernel\CacheClearer;
|
||||
* ChainCacheClearer.
|
||||
*
|
||||
* @author Dustin Dobervich <ddobervich@gmail.com>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,21 @@ namespace Symfony\Component\HttpKernel\CacheWarmer;
|
||||
* Aggregates several cache warmers into a single one.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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 <ddobervich@gmail.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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 <fabien@symfony.com>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
@ -39,6 +39,9 @@ class ChainCacheClearerTest extends TestCase
|
||||
$chainClearer->clear(self::$cacheDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testInjectClearerUsingAdd()
|
||||
{
|
||||
$clearer = $this->getMockClearer();
|
||||
|
@ -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();
|
||||
|
@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user