Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #22620 [FrameworkBundle][HttpKernel] Move httpkernel pass (le…
…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
Showing
13 changed files
with
274 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
CHANGELOG | ||
========= | ||
|
||
3.4.0 | ||
----- | ||
|
||
* added `AddCacheClearerPass` | ||
* added `AddCacheWarmerPass` | ||
|
||
3.3.0 | ||
----- | ||
|
||
|
50 changes: 50 additions & 0 deletions
50
src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheClearerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Symfony/Component/HttpKernel/DependencyInjection/AddCacheWarmerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/Symfony/Component/HttpKernel/Tests/DependencyInjection/AddCacheClearerPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.