Completed
Push — repo_use_canUser ( 15529a...3deccb )
by André
34:10 queued 17:08
created

ConsoleCacheWarmupPass   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 28 7
1
<?php
2
3
/**
4
 * File containing the ConsoleCacheWarmupPass class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
10
11
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Reference;
14
15
/**
16
 * Cache related compiler pass.
17
 *
18
 * Ensures class cache warmup is disabled in console mode.
19
 */
20
class ConsoleCacheWarmupPass implements CompilerPassInterface
21
{
22
    public function process(ContainerBuilder $container)
23
    {
24
        // This pass is CLI only as CLI class cache warmup conflicts with web access, see EZP-29034
25
        if (PHP_SAPI !== 'cli' ||
26
            !$container->hasDefinition('kernel.class_cache.cache_warmer')) {
27
            return;
28
        }
29
30
        $warmers = array();
31
        foreach ($container->findTaggedServiceIds('kernel.cache_warmer') as $id => $attributes) {
32
            if ($id === 'kernel.class_cache.cache_warmer') {
33
                continue;
34
            }
35
36
            $priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
37
            $warmers[$priority][] = new Reference($id);
38
        }
39
40
        if (empty($warmers)) {
41
            return;
42
        }
43
44
        // sort by priority and flatten
45
        krsort($warmers);
46
        $warmers = \call_user_func_array('array_merge', $warmers);
47
48
        $container->getDefinition('cache_warmer')->replaceArgument(0, $warmers);
49
    }
50
}
51