vendor/shopware/platform/src/Core/Framework/Framework.php line 34

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\Framework\Migration\MigrationSource;
  16. use Shopware\Core\Kernel;
  17. use Shopware\Core\System\SalesChannel\Entity\SalesChannelDefinitionInstanceRegistry;
  18. use Symfony\Component\Config\FileLocator;
  19. use Symfony\Component\Config\Loader\DelegatingLoader;
  20. use Symfony\Component\Config\Loader\LoaderResolver;
  21. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  22. use Symfony\Component\DependencyInjection\ContainerBuilder;
  23. use Symfony\Component\DependencyInjection\Extension\Extension;
  24. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  25. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  26. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  27. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  28. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  29. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  30. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  31. class Framework extends Bundle
  32. {
  33.     public function getContainerExtension(): Extension
  34.     {
  35.         return new FrameworkExtension();
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function build(ContainerBuilder $container): void
  41.     {
  42.         $container->setParameter('locale''en-GB');
  43.         $environment $container->getParameter('kernel.environment');
  44.         $this->buildConfig($container$environment);
  45.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  46.         $loader->load('services.xml');
  47.         $loader->load('acl.xml');
  48.         $loader->load('api.xml');
  49.         $loader->load('app.xml');
  50.         $loader->load('custom-field.xml');
  51.         $loader->load('data-abstraction-layer.xml');
  52.         $loader->load('demodata.xml');
  53.         $loader->load('event.xml');
  54.         $loader->load('filesystem.xml');
  55.         $loader->load('message-queue.xml');
  56.         $loader->load('plugin.xml');
  57.         $loader->load('rule.xml');
  58.         $loader->load('scheduled-task.xml');
  59.         $loader->load('store.xml');
  60.         $loader->load('language.xml');
  61.         $loader->load('update.xml');
  62.         $loader->load('seo.xml');
  63.         $loader->load('webhook.xml');
  64.         if ($container->getParameter('kernel.environment') === 'test') {
  65.             $loader->load('services_test.xml');
  66.             $loader->load('store_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.         // configure migration directories
  79.         $migrationSourceV3 $container->getDefinition(MigrationSource::class . '.core.V6_3');
  80.         $migrationSourceV3->addMethodCall('addDirectory', [__DIR__ '/../Migration/V6_3''Shopware\Core\Migration\V6_3']);
  81.         // we've moved the migrations from Shopware\Core\Migration to Shopware\Core\Migration\V6_3
  82.         $migrationSourceV3->addMethodCall('addReplacementPattern', ['#^(Shopware\\\\Core\\\\Migration\\\\)V6_3\\\\([^\\\\]*)$#''$1$2']);
  83.         $migrationSourceV4 $container->getDefinition(MigrationSource::class . '.core.V6_4');
  84.         $migrationSourceV4->addMethodCall('addDirectory', [__DIR__ '/../Migration/V6_4''Shopware\Core\Migration\V6_4']);
  85.         $migrationSourceV3->addMethodCall('addReplacementPattern', ['#^(Shopware\\\\Core\\\\Migration\\\\)V6_4\\\\([^\\\\]*)$#''$1$2']);
  86.         $migrationSourceV5 $container->getDefinition(MigrationSource::class . '.core.V6_5');
  87.         $migrationSourceV5->addMethodCall('addDirectory', [__DIR__ '/../Migration/V6_5''Shopware\Core\Migration\V6_5']);
  88.         parent::build($container);
  89.     }
  90.     public function boot(): void
  91.     {
  92.         parent::boot();
  93.         $featureFlags $this->container->getParameter('shopware.feature.flags');
  94.         if (!\is_array($featureFlags)) {
  95.             throw new \RuntimeException('Container parameter "shopware.feature.flags" needs to be an array');
  96.         }
  97.         $cacheDir $this->container->getParameter('kernel.cache_dir');
  98.         if (!\is_string($cacheDir)) {
  99.             throw new \RuntimeException('Container parameter "kernel.cache_dir" needs to be a string');
  100.         }
  101.         Feature::registerFeatures($featureFlags$cacheDir '/shopware_features.php');
  102.         $this->registerEntityExtensions(
  103.             $this->container->get(DefinitionInstanceRegistry::class),
  104.             $this->container->get(SalesChannelDefinitionInstanceRegistry::class),
  105.             $this->container->get(ExtensionRegistry::class)
  106.         );
  107.     }
  108.     protected function getCoreMigrationPaths(): array
  109.     {
  110.         return [
  111.             __DIR__ '/../Migration' => 'Shopware\Core\Migration',
  112.         ];
  113.     }
  114.     private function buildConfig(ContainerBuilder $container$environment): void
  115.     {
  116.         $cacheDir $container->getParameter('kernel.cache_dir');
  117.         if (!\is_string($cacheDir)) {
  118.             throw new \RuntimeException('Container parameter "kernel.cache_dir" needs to be a string');
  119.         }
  120.         $locator = new FileLocator('Resources/config');
  121.         $resolver = new LoaderResolver([
  122.             new XmlFileLoader($container$locator),
  123.             new YamlFileLoader($container$locator),
  124.             new IniFileLoader($container$locator),
  125.             new PhpFileLoader($container$locator),
  126.             new GlobFileLoader($container$locator),
  127.             new DirectoryLoader($container$locator),
  128.             new ClosureLoader($container),
  129.         ]);
  130.         $configLoader = new DelegatingLoader($resolver);
  131.         $confDir $this->getPath() . '/Resources/config';
  132.         $configLoader->load($confDir '/{packages}/*' Kernel::CONFIG_EXTS'glob');
  133.         $configLoader->load($confDir '/{packages}/' $environment '/*' Kernel::CONFIG_EXTS'glob');
  134.         $shopwareFeaturesPath $cacheDir '/shopware_features.php';
  135.         if (is_readable($shopwareFeaturesPath)) {
  136.             $configLoader->load($shopwareFeaturesPath'php');
  137.         }
  138.     }
  139.     private function registerEntityExtensions(
  140.         DefinitionInstanceRegistry $definitionRegistry,
  141.         SalesChannelDefinitionInstanceRegistry $salesChannelRegistry,
  142.         ExtensionRegistry $registry
  143.     ): void {
  144.         foreach ($registry->getExtensions() as $extension) {
  145.             /** @var string $class */
  146.             $class $extension->getDefinitionClass();
  147.             $definition $definitionRegistry->get($class);
  148.             $definition->addExtension($extension);
  149.             $salesChannelDefinition $salesChannelRegistry->get($class);
  150.             // same definition? do not added extension
  151.             if ($salesChannelDefinition !== $definition) {
  152.                 $salesChannelDefinition->addExtension($extension);
  153.             }
  154.         }
  155.     }
  156. }