Completed
Push — travis_trusty ( b242e6...daf958 )
by André
17:21
created

HttpCachePass   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 0
cbo 3
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 25 3
1
<?php
2
3
/**
4
 * File containing the HttpCachePass 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
 * @version //autogentag//
10
 */
11
namespace eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler;
12
13
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use InvalidArgumentException;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
/**
19
 * HttpCache related compiler pass.
20
 *
21
 * Ensures Varnish proxy client is correctly configured.
22
 */
23
class HttpCachePass implements CompilerPassInterface
24
{
25
    public function process(ContainerBuilder $container)
26
    {
27
        if (!$container->hasDefinition('ezpublish.http_cache.cache_manager')) {
28
            return;
29
        }
30
31
        if (!$container->hasDefinition('fos_http_cache.proxy_client.varnish')) {
32
            throw new InvalidArgumentException('Varnish proxy client must be enabled in FOSHttpCacheBundle');
33
        }
34
35
        $varnishClientDef = $container->findDefinition('fos_http_cache.proxy_client.varnish');
36
        $varnishClientDef->setFactory(
37
            [
38
                new Reference('ezpublish.http_cache.proxy_client.varnish.factory'),
39
                'buildProxyClient',
40
            ]
41
        );
42
        // Set it lazy as it can be loaded during cache warming and factory depends on ConfigResolver while cache warming
43
        // occurs before SA matching.
44
        $varnishClientDef->setLazy(true);
45
46
        // Forcing cache manager to use Varnish proxy client, for BAN support.
47
        $cacheManagerDef = $container->findDefinition('ezpublish.http_cache.cache_manager');
48
        $cacheManagerDef->replaceArgument(0, new Reference('fos_http_cache.proxy_client.varnish'));
49
    }
50
}
51