vendor/shopware/core/Framework/Framework.php line 31

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework;
  3. use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry;
  4. use Shopware\Core\Framework\DataAbstractionLayer\ExtensionRegistry;
  5. use Shopware\Core\Framework\DependencyInjection\CompilerPass\ActionEventCompilerPass;
  6. use Shopware\Core\Framework\DependencyInjection\CompilerPass\DisableTwigCacheWarmerCompilerPass;
  7. use Shopware\Core\Framework\DependencyInjection\CompilerPass\EntityCompilerPass;
  8. use Shopware\Core\Framework\DependencyInjection\CompilerPass\FeatureFlagCompilerPass;
  9. use Shopware\Core\Framework\DependencyInjection\CompilerPass\RouteScopeCompilerPass;
  10. use Shopware\Core\Framework\DependencyInjection\CompilerPass\TwigLoaderConfigCompilerPass;
  11. use Shopware\Core\Framework\DependencyInjection\FrameworkExtension;
  12. use Shopware\Core\Framework\Migration\MigrationCompilerPass;
  13. use Shopware\Core\Kernel;
  14. use Shopware\Core\System\SalesChannel\Entity\SalesChannelDefinitionInstanceRegistry;
  15. use Symfony\Component\Config\FileLocator;
  16. use Symfony\Component\Config\Loader\DelegatingLoader;
  17. use Symfony\Component\Config\Loader\LoaderResolver;
  18. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. use Symfony\Component\DependencyInjection\Extension\Extension;
  21. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  22. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  23. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  24. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  25. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  26. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  27. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  28. class Framework extends Bundle
  29. {
  30.     public function getContainerExtension(): Extension
  31.     {
  32.         return new FrameworkExtension();
  33.     }
  34.     /**
  35.      * {@inheritdoc}
  36.      */
  37.     public function build(ContainerBuilder $container): void
  38.     {
  39.         $container->setParameter('locale''en-GB');
  40.         $environment $container->getParameter('kernel.environment');
  41.         $this->buildConfig($container$environment);
  42.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  43.         $loader->load('services.xml');
  44.         $loader->load('acl.xml');
  45.         $loader->load('api.xml');
  46.         $loader->load('custom-field.xml');
  47.         $loader->load('data-abstraction-layer.xml');
  48.         $loader->load('demodata.xml');
  49.         $loader->load('event.xml');
  50.         $loader->load('filesystem.xml');
  51.         $loader->load('message-queue.xml');
  52.         $loader->load('plugin.xml');
  53.         $loader->load('rule.xml');
  54.         $loader->load('scheduled-task.xml');
  55.         $loader->load('store.xml');
  56.         $loader->load('language.xml');
  57.         $loader->load('update.xml');
  58.         $loader->load('seo.xml');
  59.         if ($container->getParameter('kernel.environment') === 'test') {
  60.             $loader->load('services_test.xml');
  61.         }
  62.         $container->addCompilerPass(new FeatureFlagCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
  63.         $container->addCompilerPass(new EntityCompilerPass());
  64.         $container->addCompilerPass(new MigrationCompilerPass(), PassConfig::TYPE_AFTER_REMOVING);
  65.         $container->addCompilerPass(new ActionEventCompilerPass());
  66.         $container->addCompilerPass(new DisableTwigCacheWarmerCompilerPass());
  67.         $container->addCompilerPass(new TwigLoaderConfigCompilerPass());
  68.         $container->addCompilerPass(new RouteScopeCompilerPass());
  69.         $this->addCoreMigrationPath($container__DIR__ '/../Migration''Shopware\Core\Migration');
  70.         parent::build($container);
  71.     }
  72.     public function boot(): void
  73.     {
  74.         parent::boot();
  75.         $this->registerEntityExtensions(
  76.             $this->container->get(DefinitionInstanceRegistry::class),
  77.             $this->container->get(SalesChannelDefinitionInstanceRegistry::class),
  78.             $this->container->get(ExtensionRegistry::class)
  79.         );
  80.     }
  81.     protected function getCoreMigrationPaths(): array
  82.     {
  83.         return [
  84.             __DIR__ '/../Migration' => 'Shopware\Core\Migration',
  85.         ];
  86.     }
  87.     private function buildConfig(ContainerBuilder $container$environment): void
  88.     {
  89.         $locator = new FileLocator('Resources/config');
  90.         $resolver = new LoaderResolver([
  91.             new XmlFileLoader($container$locator),
  92.             new YamlFileLoader($container$locator),
  93.             new IniFileLoader($container$locator),
  94.             new PhpFileLoader($container$locator),
  95.             new GlobFileLoader($container$locator),
  96.             new DirectoryLoader($container$locator),
  97.             new ClosureLoader($container),
  98.         ]);
  99.         $configLoader = new DelegatingLoader($resolver);
  100.         $confDir $this->getPath() . '/Resources/config';
  101.         $configLoader->load($confDir '/{packages}/*' Kernel::CONFIG_EXTS'glob');
  102.         $configLoader->load($confDir '/{packages}/' $environment '/*' Kernel::CONFIG_EXTS'glob');
  103.     }
  104.     private function registerEntityExtensions(
  105.         DefinitionInstanceRegistry $definitionRegistry,
  106.         SalesChannelDefinitionInstanceRegistry $salesChannelRegistry,
  107.         ExtensionRegistry $registry
  108.     ): void {
  109.         foreach ($registry->getExtensions() as $extension) {
  110.             /** @var string $class */
  111.             $class $extension->getDefinitionClass();
  112.             $definition $definitionRegistry->get($class);
  113.             $definition->addExtension($extension);
  114.             $salesChannelDefinition $salesChannelRegistry->get($class);
  115.             // same definition? do not added extension
  116.             if ($salesChannelDefinition !== $definition) {
  117.                 $salesChannelDefinition->addExtension($extension);
  118.             }
  119.         }
  120.     }
  121. }