vendor/contao/core-bundle/src/ContaoCoreBundle.php line 56

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of Contao.
  5.  *
  6.  * (c) Leo Feyer
  7.  *
  8.  * @license LGPL-3.0-or-later
  9.  */
  10. namespace Contao\CoreBundle;
  11. use Composer\InstalledVersions;
  12. use Contao\CoreBundle\DependencyInjection\Compiler\AddAssetsPackagesPass;
  13. use Contao\CoreBundle\DependencyInjection\Compiler\AddAvailableTransportsPass;
  14. use Contao\CoreBundle\DependencyInjection\Compiler\AddCronJobsPass;
  15. use Contao\CoreBundle\DependencyInjection\Compiler\AddNativeTransportFactoryPass;
  16. use Contao\CoreBundle\DependencyInjection\Compiler\AddPackagesPass;
  17. use Contao\CoreBundle\DependencyInjection\Compiler\AddResourcesPathsPass;
  18. use Contao\CoreBundle\DependencyInjection\Compiler\AddSessionBagsPass;
  19. use Contao\CoreBundle\DependencyInjection\Compiler\ConfigureFilesystemPass;
  20. use Contao\CoreBundle\DependencyInjection\Compiler\CrawlerPass;
  21. use Contao\CoreBundle\DependencyInjection\Compiler\DataContainerCallbackPass;
  22. use Contao\CoreBundle\DependencyInjection\Compiler\IntlInstalledLocalesAndCountriesPass;
  23. use Contao\CoreBundle\DependencyInjection\Compiler\LoggerChannelPass;
  24. use Contao\CoreBundle\DependencyInjection\Compiler\MakeServicesPublicPass;
  25. use Contao\CoreBundle\DependencyInjection\Compiler\PickerProviderPass;
  26. use Contao\CoreBundle\DependencyInjection\Compiler\RegisterFragmentsPass;
  27. use Contao\CoreBundle\DependencyInjection\Compiler\RegisterHookListenersPass;
  28. use Contao\CoreBundle\DependencyInjection\Compiler\RegisterPagesPass;
  29. use Contao\CoreBundle\DependencyInjection\Compiler\RemembermeServicesPass;
  30. use Contao\CoreBundle\DependencyInjection\Compiler\RewireTwigPathsPass;
  31. use Contao\CoreBundle\DependencyInjection\Compiler\SearchIndexerPass;
  32. use Contao\CoreBundle\DependencyInjection\Compiler\TaggedMigrationsPass;
  33. use Contao\CoreBundle\DependencyInjection\Compiler\TranslationDataCollectorPass;
  34. use Contao\CoreBundle\DependencyInjection\ContaoCoreExtension;
  35. use Contao\CoreBundle\DependencyInjection\Security\ContaoLoginFactory;
  36. use Contao\CoreBundle\Event\ContaoCoreEvents;
  37. use Contao\CoreBundle\Event\GenerateSymlinksEvent;
  38. use Contao\CoreBundle\Event\MenuEvent;
  39. use Contao\CoreBundle\Event\PreviewUrlConvertEvent;
  40. use Contao\CoreBundle\Event\PreviewUrlCreateEvent;
  41. use Contao\CoreBundle\Event\RobotsTxtEvent;
  42. use Contao\CoreBundle\Event\SlugValidCharactersEvent;
  43. use Contao\CoreBundle\Fragment\Reference\ContentElementReference;
  44. use Contao\CoreBundle\Fragment\Reference\FrontendModuleReference;
  45. use Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension;
  46. use Symfony\Cmf\Component\Routing\DependencyInjection\Compiler\RegisterRouteEnhancersPass;
  47. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  48. use Symfony\Component\DependencyInjection\ContainerBuilder;
  49. use Symfony\Component\EventDispatcher\DependencyInjection\AddEventAliasesPass;
  50. use Symfony\Component\HttpKernel\Bundle\Bundle;
  51. class ContaoCoreBundle extends Bundle
  52. {
  53.     public const SCOPE_BACKEND 'backend';
  54.     public const SCOPE_FRONTEND 'frontend';
  55.     public function getContainerExtension(): ContaoCoreExtension
  56.     {
  57.         return new ContaoCoreExtension();
  58.     }
  59.     public function build(ContainerBuilder $container): void
  60.     {
  61.         parent::build($container);
  62.         /** @var SecurityExtension $extension */
  63.         $extension $container->getExtension('security');
  64.         $extension->addSecurityListenerFactory(new ContaoLoginFactory());
  65.         $container->addCompilerPass(
  66.             new AddEventAliasesPass([
  67.                 GenerateSymlinksEvent::class => ContaoCoreEvents::GENERATE_SYMLINKS,
  68.                 MenuEvent::class => ContaoCoreEvents::BACKEND_MENU_BUILD,
  69.                 PreviewUrlCreateEvent::class => ContaoCoreEvents::PREVIEW_URL_CREATE,
  70.                 PreviewUrlConvertEvent::class => ContaoCoreEvents::PREVIEW_URL_CONVERT,
  71.                 RobotsTxtEvent::class => ContaoCoreEvents::ROBOTS_TXT,
  72.                 SlugValidCharactersEvent::class => ContaoCoreEvents::SLUG_VALID_CHARACTERS,
  73.             ])
  74.         );
  75.         $container->addCompilerPass(new MakeServicesPublicPass());
  76.         $container->addCompilerPass(new AddPackagesPass());
  77.         $container->addCompilerPass(new AddAssetsPackagesPass());
  78.         $container->addCompilerPass(new AddSessionBagsPass());
  79.         $container->addCompilerPass(new AddResourcesPathsPass());
  80.         $container->addCompilerPass(new TaggedMigrationsPass());
  81.         $container->addCompilerPass(new PickerProviderPass());
  82.         $container->addCompilerPass(new RegisterPagesPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION1);
  83.         $container->addCompilerPass(
  84.             new RegisterFragmentsPass(
  85.                 FrontendModuleReference::TAG_NAME,
  86.                 FrontendModuleReference::GLOBALS_KEY,
  87.                 FrontendModuleReference::PROXY_CLASS,
  88.                 'contao.listener.module_template_options'
  89.             )
  90.         );
  91.         $container->addCompilerPass(
  92.             new RegisterFragmentsPass(
  93.                 ContentElementReference::TAG_NAME,
  94.                 ContentElementReference::GLOBALS_KEY,
  95.                 ContentElementReference::PROXY_CLASS,
  96.                 'contao.listener.element_template_options'
  97.             )
  98.         );
  99.         $container->addCompilerPass(new RemembermeServicesPass('contao_frontend'));
  100.         $container->addCompilerPass(new DataContainerCallbackPass());
  101.         $container->addCompilerPass(new TranslationDataCollectorPass());
  102.         $container->addCompilerPass(new RegisterHookListenersPass(), PassConfig::TYPE_OPTIMIZE);
  103.         $container->addCompilerPass(new SearchIndexerPass()); // Must be before the CrawlerPass
  104.         $container->addCompilerPass(new CrawlerPass());
  105.         $container->addCompilerPass(new AddCronJobsPass());
  106.         $container->addCompilerPass(new AddAvailableTransportsPass());
  107.         $container->addCompilerPass(new RegisterRouteEnhancersPass('contao.routing.page_router''contao.page_router_enhancer'));
  108.         $container->addCompilerPass(new RewireTwigPathsPass());
  109.         $container->addCompilerPass(new AddNativeTransportFactoryPass());
  110.         $container->addCompilerPass(new IntlInstalledLocalesAndCountriesPass());
  111.         $container->addCompilerPass(new LoggerChannelPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1);
  112.         $container->addCompilerPass(new ConfigureFilesystemPass());
  113.     }
  114.     public static function getVersion(): string
  115.     {
  116.         try {
  117.             $version = (string) InstalledVersions::getPrettyVersion('contao/core-bundle');
  118.         } catch (\OutOfBoundsException $e) {
  119.             $version '';
  120.         }
  121.         if ('' === $version) {
  122.             $version = (string) InstalledVersions::getPrettyVersion('contao/contao');
  123.         }
  124.         return $version;
  125.     }
  126. }