platform/src/Core/Framework/Framework.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework;
  3. use Shopware\Core\Framework\Compatibility\AnnotationReaderCompilerPass;
  4. use Shopware\Core\Framework\DataAbstractionLayer\DefinitionInstanceRegistry;
  5. use Shopware\Core\Framework\DataAbstractionLayer\ExtensionRegistry;
  6. use Shopware\Core\Framework\DependencyInjection\CompilerPass\ActionEventCompilerPass;
  7. use Shopware\Core\Framework\DependencyInjection\CompilerPass\AssetRegistrationCompilerPass;
  8. use Shopware\Core\Framework\DependencyInjection\CompilerPass\DefaultTransportCompilerPass;
  9. use Shopware\Core\Framework\DependencyInjection\CompilerPass\DisableTwigCacheWarmerCompilerPass;
  10. use Shopware\Core\Framework\DependencyInjection\CompilerPass\EntityCompilerPass;
  11. use Shopware\Core\Framework\DependencyInjection\CompilerPass\FeatureFlagCompilerPass;
  12. use Shopware\Core\Framework\DependencyInjection\CompilerPass\FilesystemConfigMigrationCompilerPass;
  13. use Shopware\Core\Framework\DependencyInjection\CompilerPass\RateLimiterCompilerPass;
  14. use Shopware\Core\Framework\DependencyInjection\CompilerPass\RouteScopeCompilerPass;
  15. use Shopware\Core\Framework\DependencyInjection\CompilerPass\TwigLoaderConfigCompilerPass;
  16. use Shopware\Core\Framework\DependencyInjection\FrameworkExtension;
  17. use Shopware\Core\Framework\Increment\IncrementerGatewayCompilerPass;
  18. use Shopware\Core\Framework\Migration\MigrationCompilerPass;
  19. use Shopware\Core\Framework\Migration\MigrationSource;
  20. use Shopware\Core\Framework\Test\DependencyInjection\CompilerPass\ContainerVisibilityCompilerPass;
  21. use Shopware\Core\Framework\Test\RateLimiter\DisableRateLimiterCompilerPass;
  22. use Shopware\Core\Kernel;
  23. use Shopware\Core\System\SalesChannel\Entity\SalesChannelDefinitionInstanceRegistry;
  24. use Symfony\Component\Config\FileLocator;
  25. use Symfony\Component\Config\Loader\DelegatingLoader;
  26. use Symfony\Component\Config\Loader\LoaderResolver;
  27. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  28. use Symfony\Component\DependencyInjection\ContainerBuilder;
  29. use Symfony\Component\DependencyInjection\Extension\Extension;
  30. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  31. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  32. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  33. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  34. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  35. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  36. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  37. class Framework extends Bundle
  38. {
  39.     public function getContainerExtension(): Extension
  40.     {
  41.         return new FrameworkExtension();
  42.     }
  43.     /**
  44.      * {@inheritdoc}
  45.      */
  46.     public function build(ContainerBuilder $container): void
  47.     {
  48.         $container->setParameter('locale''en-GB');
  49.         $environment $container->getParameter('kernel.environment');
  50.         $this->buildConfig($container$environment);
  51.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  52.         $loader->load('services.xml');
  53.         $loader->load('acl.xml');
  54.         $loader->load('api.xml');
  55.         $loader->load('app.xml');
  56.         $loader->load('custom-field.xml');
  57.         $loader->load('data-abstraction-layer.xml');
  58.         $loader->load('demodata.xml');
  59.         $loader->load('event.xml');
  60.         $loader->load('hydrator.xml');
  61.         $loader->load('filesystem.xml');
  62.         $loader->load('message-queue.xml');
  63.         $loader->load('plugin.xml');
  64.         $loader->load('rule.xml');
  65.         $loader->load('scheduled-task.xml');
  66.         $loader->load('store.xml');
  67.         $loader->load('script.xml');
  68.         $loader->load('language.xml');
  69.         $loader->load('update.xml');
  70.         $loader->load('seo.xml');
  71.         $loader->load('webhook.xml');
  72.         $loader->load('rate-limiter.xml');
  73.         $loader->load('increment.xml');
  74.         if ($container->getParameter('kernel.environment') === 'test') {
  75.             $loader->load('services_test.xml');
  76.             $loader->load('store_test.xml');
  77.             $loader->load('seo_test.xml');
  78.         }
  79.         // make sure to remove services behind a feature flag, before some other compiler passes may reference them, therefore the high priority
  80.         $container->addCompilerPass(new FeatureFlagCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION1000);
  81.         $container->addCompilerPass(new EntityCompilerPass());
  82.         $container->addCompilerPass(new MigrationCompilerPass(), PassConfig::TYPE_AFTER_REMOVING);
  83.         $container->addCompilerPass(new ActionEventCompilerPass());
  84.         $container->addCompilerPass(new DisableTwigCacheWarmerCompilerPass());
  85.         $container->addCompilerPass(new DefaultTransportCompilerPass());
  86.         $container->addCompilerPass(new TwigLoaderConfigCompilerPass());
  87.         $container->addCompilerPass(new RouteScopeCompilerPass());
  88.         $container->addCompilerPass(new AssetRegistrationCompilerPass());
  89.         $container->addCompilerPass(new FilesystemConfigMigrationCompilerPass());
  90.         $container->addCompilerPass(new AnnotationReaderCompilerPass());
  91.         $container->addCompilerPass(new RateLimiterCompilerPass());
  92.         $container->addCompilerPass(new IncrementerGatewayCompilerPass());
  93.         if ($container->getParameter('kernel.environment') === 'test') {
  94.             $container->addCompilerPass(new DisableRateLimiterCompilerPass());
  95.             $container->addCompilerPass(new ContainerVisibilityCompilerPass());
  96.         }
  97.         // configure migration directories
  98.         $migrationSourceV3 $container->getDefinition(MigrationSource::class . '.core.V6_3');
  99.         $migrationSourceV3->addMethodCall('addDirectory', [__DIR__ '/../Migration/V6_3''Shopware\Core\Migration\V6_3']);
  100.         // we've moved the migrations from Shopware\Core\Migration to Shopware\Core\Migration\V6_3
  101.         $migrationSourceV3->addMethodCall('addReplacementPattern', ['#^(Shopware\\\\Core\\\\Migration\\\\)V6_3\\\\([^\\\\]*)$#''$1$2']);
  102.         $migrationSourceV4 $container->getDefinition(MigrationSource::class . '.core.V6_4');
  103.         $migrationSourceV4->addMethodCall('addDirectory', [__DIR__ '/../Migration/V6_4''Shopware\Core\Migration\V6_4']);
  104.         $migrationSourceV3->addMethodCall('addReplacementPattern', ['#^(Shopware\\\\Core\\\\Migration\\\\)V6_4\\\\([^\\\\]*)$#''$1$2']);
  105.         $migrationSourceV5 $container->getDefinition(MigrationSource::class . '.core.V6_5');
  106.         $migrationSourceV5->addMethodCall('addDirectory', [__DIR__ '/../Migration/V6_5''Shopware\Core\Migration\V6_5']);
  107.         parent::build($container);
  108.     }
  109.     public function boot(): void
  110.     {
  111.         parent::boot();
  112.         $featureFlags $this->container->getParameter('shopware.feature.flags');
  113.         if (!\is_array($featureFlags)) {
  114.             throw new \RuntimeException('Container parameter "shopware.feature.flags" needs to be an array');
  115.         }
  116.         $cacheDir $this->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.         Feature::registerFeatures($featureFlags);
  121.         $this->registerEntityExtensions(
  122.             $this->container->get(DefinitionInstanceRegistry::class),
  123.             $this->container->get(SalesChannelDefinitionInstanceRegistry::class),
  124.             $this->container->get(ExtensionRegistry::class)
  125.         );
  126.     }
  127.     protected function getCoreMigrationPaths(): array
  128.     {
  129.         return [
  130.             __DIR__ '/../Migration' => 'Shopware\Core\Migration',
  131.         ];
  132.     }
  133.     private function buildConfig(ContainerBuilder $container$environment): void
  134.     {
  135.         $cacheDir $container->getParameter('kernel.cache_dir');
  136.         if (!\is_string($cacheDir)) {
  137.             throw new \RuntimeException('Container parameter "kernel.cache_dir" needs to be a string');
  138.         }
  139.         $locator = new FileLocator('Resources/config');
  140.         $resolver = new LoaderResolver([
  141.             new XmlFileLoader($container$locator),
  142.             new YamlFileLoader($container$locator),
  143.             new IniFileLoader($container$locator),
  144.             new PhpFileLoader($container$locator),
  145.             new GlobFileLoader($container$locator),
  146.             new DirectoryLoader($container$locator),
  147.             new ClosureLoader($container),
  148.         ]);
  149.         $configLoader = new DelegatingLoader($resolver);
  150.         $confDir $this->getPath() . '/Resources/config';
  151.         $configLoader->load($confDir '/{packages}/*' Kernel::CONFIG_EXTS'glob');
  152.         $configLoader->load($confDir '/{packages}/' $environment '/*' Kernel::CONFIG_EXTS'glob');
  153.         if ($environment === 'e2e') {
  154.             $configLoader->load($confDir '/{packages}/prod/*' Kernel::CONFIG_EXTS'glob');
  155.         }
  156.     }
  157.     private function registerEntityExtensions(
  158.         DefinitionInstanceRegistry $definitionRegistry,
  159.         SalesChannelDefinitionInstanceRegistry $salesChannelRegistry,
  160.         ExtensionRegistry $registry
  161.     ): void {
  162.         foreach ($registry->getExtensions() as $extension) {
  163.             /** @var string $class */
  164.             $class $extension->getDefinitionClass();
  165.             $definition $definitionRegistry->get($class);
  166.             $definition->addExtension($extension);
  167.             $salesChannelDefinition $salesChannelRegistry->get($class);
  168.             // same definition? do not added extension
  169.             if ($salesChannelDefinition !== $definition) {
  170.                 $salesChannelDefinition->addExtension($extension);
  171.             }
  172.         }
  173.     }
  174. }