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