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

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\AssetRegistrationCompilerPass;
  7. use Shopware\Core\Framework\DependencyInjection\CompilerPass\DisableTwigCacheWarmerCompilerPass;
  8. use Shopware\Core\Framework\DependencyInjection\CompilerPass\EntityCompilerPass;
  9. use Shopware\Core\Framework\DependencyInjection\CompilerPass\FeatureFlagCompilerPass;
  10. use Shopware\Core\Framework\DependencyInjection\CompilerPass\FilesystemConfigMigrationCompilerPass;
  11. use Shopware\Core\Framework\DependencyInjection\CompilerPass\RouteScopeCompilerPass;
  12. use Shopware\Core\Framework\DependencyInjection\CompilerPass\TwigLoaderConfigCompilerPass;
  13. use Shopware\Core\Framework\DependencyInjection\FrameworkExtension;
  14. use Shopware\Core\Framework\Migration\MigrationCompilerPass;
  15. use Shopware\Core\Kernel;
  16. use Shopware\Core\System\SalesChannel\Entity\SalesChannelDefinitionInstanceRegistry;
  17. use Symfony\Component\Config\FileLocator;
  18. use Symfony\Component\Config\Loader\DelegatingLoader;
  19. use Symfony\Component\Config\Loader\LoaderResolver;
  20. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  21. use Symfony\Component\DependencyInjection\ContainerBuilder;
  22. use Symfony\Component\DependencyInjection\Extension\Extension;
  23. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  24. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  25. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  26. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  27. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  28. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  29. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  30. class Framework extends Bundle
  31. {
  32.     public function getContainerExtension(): Extension
  33.     {
  34.         return new FrameworkExtension();
  35.     }
  36.     /**
  37.      * {@inheritdoc}
  38.      */
  39.     public function build(ContainerBuilder $container): void
  40.     {
  41.         $container->setParameter('locale''en-GB');
  42.         $environment $container->getParameter('kernel.environment');
  43.         $this->buildConfig($container$environment);
  44.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  45.         $loader->load('services.xml');
  46.         $loader->load('acl.xml');
  47.         $loader->load('api.xml');
  48.         $loader->load('custom-field.xml');
  49.         $loader->load('data-abstraction-layer.xml');
  50.         $loader->load('demodata.xml');
  51.         $loader->load('event.xml');
  52.         $loader->load('filesystem.xml');
  53.         $loader->load('message-queue.xml');
  54.         $loader->load('plugin.xml');
  55.         $loader->load('rule.xml');
  56.         $loader->load('scheduled-task.xml');
  57.         $loader->load('store.xml');
  58.         $loader->load('language.xml');
  59.         $loader->load('update.xml');
  60.         $loader->load('seo.xml');
  61.         if (Feature::isActive('FEATURE_NEXT_10286')) {
  62.             $loader->load('app.xml');
  63.             $loader->load('webhook.xml');
  64.         }
  65.         if ($container->getParameter('kernel.environment') === 'test') {
  66.             $loader->load('services_test.xml');
  67.         }
  68.         // make sure to remove services behind a feature flag, before some other compiler passes may reference them, therefore the high priority
  69.         $container->addCompilerPass(new FeatureFlagCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION1000);
  70.         $container->addCompilerPass(new EntityCompilerPass());
  71.         $container->addCompilerPass(new MigrationCompilerPass(), PassConfig::TYPE_AFTER_REMOVING);
  72.         $container->addCompilerPass(new ActionEventCompilerPass());
  73.         $container->addCompilerPass(new DisableTwigCacheWarmerCompilerPass());
  74.         $container->addCompilerPass(new TwigLoaderConfigCompilerPass());
  75.         $container->addCompilerPass(new RouteScopeCompilerPass());
  76.         $container->addCompilerPass(new AssetRegistrationCompilerPass());
  77.         $container->addCompilerPass(new FilesystemConfigMigrationCompilerPass());
  78.         $this->addCoreMigrationPath($container__DIR__ '/../Migration''Shopware\Core\Migration');
  79.         parent::build($container);
  80.     }
  81.     public function boot(): void
  82.     {
  83.         parent::boot();
  84.         Feature::setRegisteredFeatures(
  85.             $this->container->getParameter('shopware.feature.flags'),
  86.             $this->container->getParameter('kernel.cache_dir') . '/shopware_features.php'
  87.         );
  88.         $this->registerEntityExtensions(
  89.             $this->container->get(DefinitionInstanceRegistry::class),
  90.             $this->container->get(SalesChannelDefinitionInstanceRegistry::class),
  91.             $this->container->get(ExtensionRegistry::class)
  92.         );
  93.     }
  94.     protected function getCoreMigrationPaths(): array
  95.     {
  96.         return [
  97.             __DIR__ '/../Migration' => 'Shopware\Core\Migration',
  98.         ];
  99.     }
  100.     private function buildConfig(ContainerBuilder $container$environment): void
  101.     {
  102.         $locator = new FileLocator('Resources/config');
  103.         $resolver = new LoaderResolver([
  104.             new XmlFileLoader($container$locator),
  105.             new YamlFileLoader($container$locator),
  106.             new IniFileLoader($container$locator),
  107.             new PhpFileLoader($container$locator),
  108.             new GlobFileLoader($container$locator),
  109.             new DirectoryLoader($container$locator),
  110.             new ClosureLoader($container),
  111.         ]);
  112.         $configLoader = new DelegatingLoader($resolver);
  113.         $confDir $this->getPath() . '/Resources/config';
  114.         $configLoader->load($confDir '/{packages}/*' Kernel::CONFIG_EXTS'glob');
  115.         $configLoader->load($confDir '/{packages}/' $environment '/*' Kernel::CONFIG_EXTS'glob');
  116.         $shopwareFeaturesPath $container->getParameter('kernel.cache_dir') . '/shopware_features.php';
  117.         if (is_readable($shopwareFeaturesPath)) {
  118.             $configLoader->load($shopwareFeaturesPath'php');
  119.         }
  120.     }
  121.     private function registerEntityExtensions(
  122.         DefinitionInstanceRegistry $definitionRegistry,
  123.         SalesChannelDefinitionInstanceRegistry $salesChannelRegistry,
  124.         ExtensionRegistry $registry
  125.     ): void {
  126.         foreach ($registry->getExtensions() as $extension) {
  127.             /** @var string $class */
  128.             $class $extension->getDefinitionClass();
  129.             $definition $definitionRegistry->get($class);
  130.             $definition->addExtension($extension);
  131.             $salesChannelDefinition $salesChannelRegistry->get($class);
  132.             // same definition? do not added extension
  133.             if ($salesChannelDefinition !== $definition) {
  134.                 $salesChannelDefinition->addExtension($extension);
  135.             }
  136.         }
  137.     }
  138. }