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

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