vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Infrastructure/Symfony/DependencyInjection/SuluPreviewExtension.php line 52

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\PreviewBundle\Infrastructure\Symfony\DependencyInjection;
  11. use Sulu\Bundle\PersistenceBundle\DependencyInjection\PersistenceExtensionTrait;
  12. use Sulu\Bundle\PreviewBundle\Domain\Model\PreviewLinkInterface;
  13. use Sulu\Bundle\PreviewBundle\Domain\Repository\PreviewLinkRepositoryInterface;
  14. use Symfony\Component\Config\FileLocator;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
  17. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  18. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  19. /**
  20.  * Extends the container and initializes the preview budle.
  21.  */
  22. class SuluPreviewExtension extends Extension implements PrependExtensionInterface
  23. {
  24.     use PersistenceExtensionTrait;
  25.     public function load(array $configsContainerBuilder $container): void
  26.     {
  27.         $configuration = new Configuration();
  28.         $config $this->processConfiguration($configuration$configs);
  29.         $container->setParameter('sulu_preview.mode'$config['mode']);
  30.         $container->setParameter('sulu_preview.delay'$config['delay']);
  31.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/../../../Resources/config'));
  32.         $loader->load('services.xml');
  33.         $this->configurePersistence($config['objects'], $container);
  34.         $container->addAliases(
  35.             [
  36.                 PreviewLinkRepositoryInterface::class => 'sulu_preview.preview_link_repository',
  37.             ]
  38.         );
  39.     }
  40.     public function prepend(ContainerBuilder $container): void
  41.     {
  42.         $configs $container->getExtensionConfig($this->getAlias());
  43.         $config $this->processConfiguration(new Configuration(), $configs);
  44.         if ($config['cache']['type']) {
  45.             if (!$container->hasExtension('doctrine_cache')) {
  46.                 throw new \RuntimeException(
  47.                     'Deprecated "sulu_preview.cache" configuration used, but DoctrineCacheBundle was not registered.' . \PHP_EOL .
  48.                     'Register the DoctrineCacheBundle or use the "sulu_preview.cache_adapter" configuration.'
  49.                 );
  50.             }
  51.             $container->prependExtensionConfig('doctrine_cache',
  52.                 [
  53.                     'aliases' => [
  54.                         'sulu_preview.preview.cache' => 'sulu_preview',
  55.                     ],
  56.                     'providers' => [
  57.                         'sulu_preview' => $config['cache'],
  58.                     ],
  59.                 ]
  60.             );
  61.         } else {
  62.             $container->prependExtensionConfig('framework',
  63.                 [
  64.                     'cache' => [
  65.                         'pools' => [
  66.                             'sulu_preview.preview.cache' => [
  67.                                 'adapter' => $config['cache_adapter'],
  68.                             ],
  69.                         ],
  70.                     ],
  71.                 ]
  72.             );
  73.         }
  74.         if ($container->hasExtension('doctrine')) {
  75.             $container->prependExtensionConfig(
  76.                 'doctrine',
  77.                 [
  78.                     'orm' => [
  79.                         'mappings' => [
  80.                             'SuluPreviewBundle' => [
  81.                                 'type' => 'xml',
  82.                                 'dir' => __DIR__ '/../../../Resources/config/doctrine',
  83.                                 'prefix' => 'Sulu\Bundle\PreviewBundle\Domain\Model',
  84.                                 'alias' => 'SuluPreviewBundle',
  85.                             ],
  86.                         ],
  87.                     ],
  88.                 ]
  89.             );
  90.         }
  91.         if ($container->hasExtension('sulu_admin')) {
  92.             $container->prependExtensionConfig(
  93.                 'sulu_admin',
  94.                 [
  95.                     'resources' => [
  96.                         PreviewLinkInterface::RESOURCE_KEY => [
  97.                             'routes' => [
  98.                                 'detail' => 'sulu_preview.get_preview-link',
  99.                             ],
  100.                         ],
  101.                     ],
  102.                 ]
  103.             );
  104.         }
  105.     }
  106. }