forked from ezsystems/ezpublish-kernel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
eZ/Bundle/EzPublishCoreBundle/DependencyInjection/Compiler/ConsoleCacheWarmupPass.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 | ||
|
||
/** | ||
* File containing the ConsoleCacheWarmupPass class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Cache related compiler pass. | ||
* | ||
* Ensures class cache warmup is disabled in console mode. | ||
*/ | ||
class ConsoleCacheWarmupPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
// This pass is CLI only as CLI class cache warmup conflicts with web access, see EZP-29034 | ||
if (PHP_SAPI !== 'cli' || | ||
!$container->hasDefinition('kernel.class_cache.cache_warmer')) { | ||
return; | ||
} | ||
|
||
$warmers = array(); | ||
foreach ($container->findTaggedServiceIds('kernel.cache_warmer') as $id => $attributes) { | ||
if ($id === 'kernel.class_cache.cache_warmer') { | ||
continue; | ||
} | ||
|
||
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0; | ||
$warmers[$priority][] = new Reference($id); | ||
} | ||
|
||
if (empty($warmers)) { | ||
return; | ||
} | ||
|
||
// sort by priority and flatten | ||
krsort($warmers); | ||
$warmers = \call_user_func_array('array_merge', $warmers); | ||
|
||
$container->getDefinition('cache_warmer')->replaceArgument(0, $warmers); | ||
} | ||
} |
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