Skip to content

[HttpKernel] Deprecate some compiler passes in favor of tagged iterator args #24362

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions UPGRADE-3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
-------

Expand Down
14 changes: 11 additions & 3 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
----

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

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>
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@
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;
Expand Down Expand Up @@ -102,8 +99,6 @@ public function build(ContainerBuilder $container)
$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);
Expand All @@ -124,7 +119,6 @@ public function build(ContainerBuilder $container)
$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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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" />
Expand All @@ -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">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +23,8 @@
*
* @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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;

/**
* @group legacy
*/
class ConfigCachePassTest extends TestCase
{
public function testThatCheckersAreProcessedInPriorityOrder()
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* ChainCacheClearer.
*
* @author Dustin Dobervich <ddobervich@gmail.com>
*
* @final since version 3.4
*/
class ChainCacheClearer implements CacheClearerInterface
{
Expand All @@ -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;
}
Expand All @@ -47,9 +49,13 @@ public function clear($cacheDir)
* 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't$this->clearers an iterator now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it, but here is my reasoning: this method is deprecated, and no code exists yet that uses both the method and an iterator. No new code should be written that would use both an iterator, and the deprecated method. Thus, all is fine :)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@
* 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()
Expand Down Expand Up @@ -53,6 +57,8 @@ public function warmUp($cacheDir)
* 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()
{
Expand All @@ -61,14 +67,23 @@ public function isOptional()

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;
}
}
Loading