vendor/sulu/sulu/src/Sulu/Bundle/HttpCacheBundle/DependencyInjection/SuluHttpCacheExtension.php line 74

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of Sulu.
  4.  *
  5.  * (c) Sulu GmbH
  6.  *
  7.  * This source file is subject to the MIT license that is bundled
  8.  * with this source code in the file LICENSE.
  9.  */
  10. namespace Sulu\Bundle\HttpCacheBundle\DependencyInjection;
  11. use Symfony\Component\Config\FileLocator;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
  14. use Symfony\Component\DependencyInjection\Loader;
  15. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  16. /**
  17.  * Container extension for sulu-http-cache bundle.
  18.  */
  19. class SuluHttpCacheExtension extends Extension implements PrependExtensionInterface
  20. {
  21.     public function prepend(ContainerBuilder $container)
  22.     {
  23.         $configs $container->getExtensionConfig($this->getAlias());
  24.         $configuration $this->getConfiguration($configs$container);
  25.         $resolvingBag $container->getParameterBag();
  26.         $configs $resolvingBag->resolveValue($configs);
  27.         $config $this->processConfiguration($configuration$configs);
  28.         $fosHttpCacheConfig = [
  29.             'debug' => [
  30.                 'enabled' => $config['debug']['enabled'],
  31.             ],
  32.         ];
  33.         if (!$container->hasExtension('sensio_framework_extra')) {
  34.             $fosHttpCacheConfig['tags'] = [
  35.                 'annotations' => [
  36.                     'enabled' => false,
  37.                 ],
  38.             ];
  39.         }
  40.         if ($config['proxy_client']['symfony']['enabled']) {
  41.             $symfonyProxyClient $config['proxy_client']['symfony'];
  42.             $fosHttpCacheConfig['proxy_client']['symfony']['http']['servers'] =
  43.                 \count($symfonyProxyClient['servers']) ? $symfonyProxyClient['servers'] : ['127.0.0.1'];
  44.         }
  45.         if ($config['proxy_client']['varnish']['enabled']) {
  46.             $varnishProxyClient $config['proxy_client']['varnish'];
  47.             $fosHttpCacheConfig['proxy_client']['varnish']['http']['servers'] =
  48.                 \count($varnishProxyClient['servers']) ? $varnishProxyClient['servers'] : ['127.0.0.1'];
  49.             $fosHttpCacheConfig['proxy_client']['varnish']['tag_mode'] = $varnishProxyClient['tag_mode'];
  50.             if (\array_key_exists('tags_header'$varnishProxyClient)) {
  51.                 $fosHttpCacheConfig['proxy_client']['varnish']['tags_header'] = $varnishProxyClient['tags_header'];
  52.             }
  53.         }
  54.         if (\array_key_exists('proxy_client'$fosHttpCacheConfig)) {
  55.             $fosHttpCacheConfig['tags']['enabled'] = $config['tags']['enabled'];
  56.         }
  57.         $container->prependExtensionConfig('fos_http_cache'$fosHttpCacheConfig);
  58.     }
  59.     public function getConfiguration(array $configContainerBuilder $container)
  60.     {
  61.         return new Configuration($container->getParameter('kernel.debug'));
  62.     }
  63.     public function load(array $configsContainerBuilder $container)
  64.     {
  65.         $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ '/../Resources/config'));
  66.         $loader->load('event-subscribers.xml');
  67.         $loader->load('services.xml');
  68.         $configuration $this->getConfiguration($configs$container);
  69.         $config $this->processConfiguration($configuration$configs);
  70.         $container->setParameter('sulu_http_cache.cache.max_age'$config['cache']['max_age']);
  71.         $container->setParameter('sulu_http_cache.cache.shared_max_age'$config['cache']['shared_max_age']);
  72.         $container->setParameter('sulu_http_cache.tags.enabled'$config['tags']['enabled']);
  73.         $proxyClientAvailable false;
  74.         if (\array_key_exists('proxy_client'$config)) {
  75.             foreach ($config['proxy_client'] as $proxyClient) {
  76.                 if (true === $proxyClient['enabled']) {
  77.                     $proxyClientAvailable true;
  78.                     break;
  79.                 }
  80.             }
  81.         }
  82.         $loader->load('cache-lifetime-enhancer.xml');
  83.         if ($proxyClientAvailable) {
  84.             $loader->load('cache-manager.xml');
  85.             if (true === $config['tags']['enabled']) {
  86.                 $loader->load('tags.xml');
  87.             }
  88.         }
  89.     }
  90. }