Skip to content

Commit

Permalink
feature #22620 [FrameworkBundle][HttpKernel] Move httpkernel pass (le…
Browse files Browse the repository at this point in the history
…piaf)

This PR was merged into the 3.4 branch.

Discussion
----------

[FrameworkBundle][HttpKernel] Move httpkernel pass

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | part of #21284
| License       | MIT
| Doc PR        | n/a

Move addcachearmer, addcacheclearer compiler pass to httpkernel

Commits
-------

83727c7 [FrameworkBundle][HttpKernel] Move addcachearmer, addcacheclearer compiler pass
  • Loading branch information
fabpot committed Jul 6, 2017
2 parents f7bca74 + 83727c7 commit 3981f9b
Show file tree
Hide file tree
Showing 13 changed files with 274 additions and 46 deletions.
8 changes: 8 additions & 0 deletions UPGRADE-3.4.md
Expand Up @@ -38,6 +38,14 @@ FrameworkBundle
will be removed in 4.0. Use the `--prefix` option with an empty string as value
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.

* 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.

Process
-------

Expand Down
6 changes: 6 additions & 0 deletions UPGRADE-4.0.md
Expand Up @@ -348,6 +348,12 @@ FrameworkBundle
* The `--no-prefix` option of the `translation:update` command has
been removed.

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass` class has been removed.
Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` class instead.

* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass` class has been removed.
Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` class instead.

HttpFoundation
--------------

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Expand Up @@ -10,6 +10,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.

3.3.0
-----
Expand Down
Expand Up @@ -11,31 +11,17 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
@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);

use Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass as BaseAddCacheClearerPass;

/**
* Registers the cache clearers.
*
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseAddCacheClearerPass instead}.
*
* @author Dustin Dobervich <ddobervich@gmail.com>
*/
class AddCacheClearerPass implements CompilerPassInterface
class AddCacheClearerPass extends BaseAddCacheClearerPass
{
/**
* {@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);
}
}
Expand Up @@ -11,34 +11,17 @@

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
@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);

use Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass as BaseAddCacheWarmerPass;

/**
* Registers the cache warmers.
*
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseAddCacheWarmerPass instead}.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class AddCacheWarmerPass implements CompilerPassInterface
class AddCacheWarmerPass extends BaseAddCacheWarmerPass
{
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);
}
}
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Expand Up @@ -21,15 +21,15 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheClearerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
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 @@ -16,6 +16,9 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass;

/**
* @group legacy
*/
class AddCacheWarmerPassTest extends TestCase
{
public function testThatCacheWarmersAreProcessedInPriorityOrder()
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Expand Up @@ -24,7 +24,7 @@
"symfony/config": "~3.3|~4.0",
"symfony/event-dispatcher": "^3.3.1|~4.0",
"symfony/http-foundation": "~3.3|~4.0",
"symfony/http-kernel": "~3.3|~4.0",
"symfony/http-kernel": "~3.4|~4.0",
"symfony/polyfill-mbstring": "~1.0",
"symfony/filesystem": "~2.8|~3.0|~4.0",
"symfony/finder": "~2.8|~3.0|~4.0",
Expand Down Expand Up @@ -66,6 +66,7 @@
"symfony/asset": "<3.3",
"symfony/console": "<3.3",
"symfony/form": "<3.3",
"symfony/http-kernel": "<3.4",
"symfony/property-info": "<3.3",
"symfony/serializer": "<3.3",
"symfony/translation": "<3.2",
Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
@@ -1,6 +1,12 @@
CHANGELOG
=========

3.4.0
-----

* added `AddCacheClearerPass`
* added `AddCacheWarmerPass`

3.3.0
-----

Expand Down
@@ -0,0 +1,50 @@
<?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);
}
}
@@ -0,0 +1,53 @@
<?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);
}
}
@@ -0,0 +1,53 @@
<?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);
}
}

0 comments on commit 3981f9b

Please sign in to comment.