src/Core/Profiling/Profiling.php line 23

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Profiling;
  3. use Composer\InstalledVersions;
  4. use Shopware\Core\Framework\Bundle;
  5. use Shopware\Core\Framework\Log\Package;
  6. use Shopware\Core\Kernel;
  7. use Shopware\Core\Profiling\Compiler\RemoveDevServices;
  8. use Symfony\Component\Config\FileLocator;
  9. use Symfony\Component\Config\Loader\DelegatingLoader;
  10. use Symfony\Component\Config\Loader\LoaderResolver;
  11. use Symfony\Component\DependencyInjection\ContainerBuilder;
  12. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  13. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  14. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  15. use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
  16. /**
  17.  * @internal
  18.  */
  19. #[Package('core')]
  20. class Profiling extends Bundle
  21. {
  22.     public function getTemplatePriority(): int
  23.     {
  24.         return -2;
  25.     }
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function build(ContainerBuilder $container): void
  30.     {
  31.         /** @var string $environment */
  32.         $environment $container->getParameter('kernel.environment');
  33.         parent::build($container);
  34.         $this->buildConfig($container$environment);
  35.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  36.         $loader->load('services.xml');
  37.         if ($environment === 'dev') {
  38.             $loader->load('services_dev.xml');
  39.         }
  40.         $container->addCompilerPass(new RemoveDevServices());
  41.     }
  42.     public function boot(): void
  43.     {
  44.         parent::boot();
  45.         // The profiler registers all profiler integrations in the constructor
  46.         // Therefor we need to get the service once to initialize it
  47.         $this->container->get(Profiler::class);
  48.     }
  49.     public function configureRoutes(RoutingConfigurator $routesstring $environment): void
  50.     {
  51.         if (!InstalledVersions::isInstalled('symfony/web-profiler-bundle')) {
  52.             return;
  53.         }
  54.         parent::configureRoutes($routes$environment);
  55.     }
  56.     private function buildConfig(ContainerBuilder $containerstring $environment): void
  57.     {
  58.         if (!InstalledVersions::isInstalled('symfony/web-profiler-bundle')) {
  59.             return;
  60.         }
  61.         $locator = new FileLocator('Resources/config');
  62.         $resolver = new LoaderResolver([
  63.             new YamlFileLoader($container$locator),
  64.             new GlobFileLoader($container$locator),
  65.         ]);
  66.         $configLoader = new DelegatingLoader($resolver);
  67.         $confDir $this->getPath() . '/Resources/config';
  68.         $configLoader->load($confDir '/{packages}/*' Kernel::CONFIG_EXTS'glob');
  69.         $configLoader->load($confDir '/{packages}/' $environment '/*' Kernel::CONFIG_EXTS'glob');
  70.     }
  71. }