vendor/symfony/http-kernel/Kernel.php line 187

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpKernel;
  11. use Symfony\Component\Config\Builder\ConfigBuilderGenerator;
  12. use Symfony\Component\Config\ConfigCache;
  13. use Symfony\Component\Config\Loader\DelegatingLoader;
  14. use Symfony\Component\Config\Loader\LoaderResolver;
  15. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  16. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  17. use Symfony\Component\DependencyInjection\Compiler\RemoveBuildParametersPass;
  18. use Symfony\Component\DependencyInjection\ContainerBuilder;
  19. use Symfony\Component\DependencyInjection\ContainerInterface;
  20. use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
  21. use Symfony\Component\DependencyInjection\Dumper\Preloader;
  22. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  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. use Symfony\Component\ErrorHandler\DebugClassLoader;
  31. use Symfony\Component\Filesystem\Filesystem;
  32. use Symfony\Component\HttpFoundation\Request;
  33. use Symfony\Component\HttpFoundation\Response;
  34. use Symfony\Component\HttpKernel\Bundle\BundleInterface;
  35. use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
  36. use Symfony\Component\HttpKernel\Config\FileLocator;
  37. use Symfony\Component\HttpKernel\DependencyInjection\AddAnnotatedClassesToCachePass;
  38. use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
  39. // Help opcache.preload discover always-needed symbols
  40. class_exists(ConfigCache::class);
  41. /**
  42.  * The Kernel is the heart of the Symfony system.
  43.  *
  44.  * It manages an environment made of bundles.
  45.  *
  46.  * Environment names must always start with a letter and
  47.  * they must only contain letters and numbers.
  48.  *
  49.  * @author Fabien Potencier <fabien@symfony.com>
  50.  */
  51. abstract class Kernel implements KernelInterfaceRebootableInterfaceTerminableInterface
  52. {
  53.     /**
  54.      * @var array<string, BundleInterface>
  55.      */
  56.     protected $bundles = [];
  57.     protected $container;
  58.     protected $environment;
  59.     protected $debug;
  60.     protected $booted false;
  61.     protected $startTime;
  62.     private string $projectDir;
  63.     private ?string $warmupDir null;
  64.     private int $requestStackSize 0;
  65.     private bool $resetServices false;
  66.     /**
  67.      * @var array<string, bool>
  68.      */
  69.     private static array $freshCache = [];
  70.     public const VERSION '6.3.8';
  71.     public const VERSION_ID 60308;
  72.     public const MAJOR_VERSION 6;
  73.     public const MINOR_VERSION 3;
  74.     public const RELEASE_VERSION 8;
  75.     public const EXTRA_VERSION '';
  76.     public const END_OF_MAINTENANCE '01/2024';
  77.     public const END_OF_LIFE '01/2024';
  78.     public function __construct(string $environmentbool $debug)
  79.     {
  80.         if (!$this->environment $environment) {
  81.             throw new \InvalidArgumentException(sprintf('Invalid environment provided to "%s": the environment cannot be empty.'get_debug_type($this)));
  82.         }
  83.         $this->debug $debug;
  84.     }
  85.     public function __clone()
  86.     {
  87.         $this->booted false;
  88.         $this->container null;
  89.         $this->requestStackSize 0;
  90.         $this->resetServices false;
  91.     }
  92.     /**
  93.      * @return void
  94.      */
  95.     public function boot()
  96.     {
  97.         if (true === $this->booted) {
  98.             if (!$this->requestStackSize && $this->resetServices) {
  99.                 if ($this->container->has('services_resetter')) {
  100.                     $this->container->get('services_resetter')->reset();
  101.                 }
  102.                 $this->resetServices false;
  103.                 if ($this->debug) {
  104.                     $this->startTime microtime(true);
  105.                 }
  106.             }
  107.             return;
  108.         }
  109.         if (null === $this->container) {
  110.             $this->preBoot();
  111.         }
  112.         foreach ($this->getBundles() as $bundle) {
  113.             $bundle->setContainer($this->container);
  114.             $bundle->boot();
  115.         }
  116.         $this->booted true;
  117.     }
  118.     /**
  119.      * @return void
  120.      */
  121.     public function reboot(?string $warmupDir)
  122.     {
  123.         $this->shutdown();
  124.         $this->warmupDir $warmupDir;
  125.         $this->boot();
  126.     }
  127.     /**
  128.      * @return void
  129.      */
  130.     public function terminate(Request $requestResponse $response)
  131.     {
  132.         if (false === $this->booted) {
  133.             return;
  134.         }
  135.         if ($this->getHttpKernel() instanceof TerminableInterface) {
  136.             $this->getHttpKernel()->terminate($request$response);
  137.         }
  138.     }
  139.     /**
  140.      * @return void
  141.      */
  142.     public function shutdown()
  143.     {
  144.         if (false === $this->booted) {
  145.             return;
  146.         }
  147.         $this->booted false;
  148.         foreach ($this->getBundles() as $bundle) {
  149.             $bundle->shutdown();
  150.             $bundle->setContainer(null);
  151.         }
  152.         $this->container null;
  153.         $this->requestStackSize 0;
  154.         $this->resetServices false;
  155.     }
  156.     public function handle(Request $requestint $type HttpKernelInterface::MAIN_REQUESTbool $catch true): Response
  157.     {
  158.         if (!$this->booted) {
  159.             $container $this->container ?? $this->preBoot();
  160.             if ($container->has('http_cache')) {
  161.                 return $container->get('http_cache')->handle($request$type$catch);
  162.             }
  163.         }
  164.         $this->boot();
  165.         ++$this->requestStackSize;
  166.         $this->resetServices true;
  167.         try {
  168.             return $this->getHttpKernel()->handle($request$type$catch);
  169.         } finally {
  170.             --$this->requestStackSize;
  171.         }
  172.     }
  173.     /**
  174.      * Gets an HTTP kernel from the container.
  175.      */
  176.     protected function getHttpKernel(): HttpKernelInterface
  177.     {
  178.         return $this->container->get('http_kernel');
  179.     }
  180.     public function getBundles(): array
  181.     {
  182.         return $this->bundles;
  183.     }
  184.     public function getBundle(string $name): BundleInterface
  185.     {
  186.         if (!isset($this->bundles[$name])) {
  187.             throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the "registerBundles()" method of your "%s.php" file?'$nameget_debug_type($this)));
  188.         }
  189.         return $this->bundles[$name];
  190.     }
  191.     public function locateResource(string $name): string
  192.     {
  193.         if ('@' !== $name[0]) {
  194.             throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).'$name));
  195.         }
  196.         if (str_contains($name'..')) {
  197.             throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).'$name));
  198.         }
  199.         $bundleName substr($name1);
  200.         $path '';
  201.         if (str_contains($bundleName'/')) {
  202.             [$bundleName$path] = explode('/'$bundleName2);
  203.         }
  204.         $bundle $this->getBundle($bundleName);
  205.         if (file_exists($file $bundle->getPath().'/'.$path)) {
  206.             return $file;
  207.         }
  208.         throw new \InvalidArgumentException(sprintf('Unable to find file "%s".'$name));
  209.     }
  210.     public function getEnvironment(): string
  211.     {
  212.         return $this->environment;
  213.     }
  214.     public function isDebug(): bool
  215.     {
  216.         return $this->debug;
  217.     }
  218.     /**
  219.      * Gets the application root dir (path of the project's composer file).
  220.      */
  221.     public function getProjectDir(): string
  222.     {
  223.         if (!isset($this->projectDir)) {
  224.             $r = new \ReflectionObject($this);
  225.             if (!is_file($dir $r->getFileName())) {
  226.                 throw new \LogicException(sprintf('Cannot auto-detect project dir for kernel of class "%s".'$r->name));
  227.             }
  228.             $dir $rootDir \dirname($dir);
  229.             while (!is_file($dir.'/composer.json')) {
  230.                 if ($dir === \dirname($dir)) {
  231.                     return $this->projectDir $rootDir;
  232.                 }
  233.                 $dir \dirname($dir);
  234.             }
  235.             $this->projectDir $dir;
  236.         }
  237.         return $this->projectDir;
  238.     }
  239.     public function getContainer(): ContainerInterface
  240.     {
  241.         if (!$this->container) {
  242.             throw new \LogicException('Cannot retrieve the container from a non-booted kernel.');
  243.         }
  244.         return $this->container;
  245.     }
  246.     /**
  247.      * @internal
  248.      */
  249.     public function setAnnotatedClassCache(array $annotatedClasses): void
  250.     {
  251.         file_put_contents(($this->warmupDir ?: $this->getBuildDir()).'/annotations.map'sprintf('<?php return %s;'var_export($annotatedClassestrue)));
  252.     }
  253.     public function getStartTime(): float
  254.     {
  255.         return $this->debug && null !== $this->startTime $this->startTime : -\INF;
  256.     }
  257.     public function getCacheDir(): string
  258.     {
  259.         return $this->getProjectDir().'/var/cache/'.$this->environment;
  260.     }
  261.     public function getBuildDir(): string
  262.     {
  263.         // Returns $this->getCacheDir() for backward compatibility
  264.         return $this->getCacheDir();
  265.     }
  266.     public function getLogDir(): string
  267.     {
  268.         return $this->getProjectDir().'/var/log';
  269.     }
  270.     public function getCharset(): string
  271.     {
  272.         return 'UTF-8';
  273.     }
  274.     /**
  275.      * Gets the patterns defining the classes to parse and cache for annotations.
  276.      */
  277.     public function getAnnotatedClassesToCompile(): array
  278.     {
  279.         return [];
  280.     }
  281.     /**
  282.      * Initializes bundles.
  283.      *
  284.      * @return void
  285.      *
  286.      * @throws \LogicException if two bundles share a common name
  287.      */
  288.     protected function initializeBundles()
  289.     {
  290.         // init bundles
  291.         $this->bundles = [];
  292.         foreach ($this->registerBundles() as $bundle) {
  293.             $name $bundle->getName();
  294.             if (isset($this->bundles[$name])) {
  295.                 throw new \LogicException(sprintf('Trying to register two bundles with the same name "%s".'$name));
  296.             }
  297.             $this->bundles[$name] = $bundle;
  298.         }
  299.     }
  300.     /**
  301.      * The extension point similar to the Bundle::build() method.
  302.      *
  303.      * Use this method to register compiler passes and manipulate the container during the building process.
  304.      *
  305.      * @return void
  306.      */
  307.     protected function build(ContainerBuilder $container)
  308.     {
  309.     }
  310.     /**
  311.      * Gets the container class.
  312.      *
  313.      * @throws \InvalidArgumentException If the generated classname is invalid
  314.      */
  315.     protected function getContainerClass(): string
  316.     {
  317.         $class = static::class;
  318.         $class str_contains($class"@anonymous\0") ? get_parent_class($class).str_replace('.''_'ContainerBuilder::hash($class)) : $class;
  319.         $class str_replace('\\''_'$class).ucfirst($this->environment).($this->debug 'Debug' '').'Container';
  320.         if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/'$class)) {
  321.             throw new \InvalidArgumentException(sprintf('The environment "%s" contains invalid characters, it can only contain characters allowed in PHP class names.'$this->environment));
  322.         }
  323.         return $class;
  324.     }
  325.     /**
  326.      * Gets the container's base class.
  327.      *
  328.      * All names except Container must be fully qualified.
  329.      */
  330.     protected function getContainerBaseClass(): string
  331.     {
  332.         return 'Container';
  333.     }
  334.     /**
  335.      * Initializes the service container.
  336.      *
  337.      * The built version of the service container is used when fresh, otherwise the
  338.      * container is built.
  339.      *
  340.      * @return void
  341.      */
  342.     protected function initializeContainer()
  343.     {
  344.         $class $this->getContainerClass();
  345.         $buildDir $this->warmupDir ?: $this->getBuildDir();
  346.         $cache = new ConfigCache($buildDir.'/'.$class.'.php'$this->debug);
  347.         $cachePath $cache->getPath();
  348.         // Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors
  349.         $errorLevel error_reporting(\E_ALL \E_WARNING);
  350.         try {
  351.             if (is_file($cachePath) && \is_object($this->container = include $cachePath)
  352.                 && (!$this->debug || (self::$freshCache[$cachePath] ?? $cache->isFresh()))
  353.             ) {
  354.                 self::$freshCache[$cachePath] = true;
  355.                 $this->container->set('kernel'$this);
  356.                 error_reporting($errorLevel);
  357.                 return;
  358.             }
  359.         } catch (\Throwable $e) {
  360.         }
  361.         $oldContainer \is_object($this->container) ? new \ReflectionClass($this->container) : $this->container null;
  362.         try {
  363.             is_dir($buildDir) ?: mkdir($buildDir0777true);
  364.             if ($lock fopen($cachePath.'.lock''w+')) {
  365.                 if (!flock($lock\LOCK_EX \LOCK_NB$wouldBlock) && !flock($lock$wouldBlock \LOCK_SH \LOCK_EX)) {
  366.                     fclose($lock);
  367.                     $lock null;
  368.                 } elseif (!is_file($cachePath) || !\is_object($this->container = include $cachePath)) {
  369.                     $this->container null;
  370.                 } elseif (!$oldContainer || $this->container::class !== $oldContainer->name) {
  371.                     flock($lock\LOCK_UN);
  372.                     fclose($lock);
  373.                     $this->container->set('kernel'$this);
  374.                     return;
  375.                 }
  376.             }
  377.         } catch (\Throwable $e) {
  378.         } finally {
  379.             error_reporting($errorLevel);
  380.         }
  381.         if ($collectDeprecations $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
  382.             $collectedLogs = [];
  383.             $previousHandler set_error_handler(function ($type$message$file$line) use (&$collectedLogs, &$previousHandler) {
  384.                 if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type) {
  385.                     return $previousHandler $previousHandler($type$message$file$line) : false;
  386.                 }
  387.                 if (isset($collectedLogs[$message])) {
  388.                     ++$collectedLogs[$message]['count'];
  389.                     return null;
  390.                 }
  391.                 $backtrace debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS5);
  392.                 // Clean the trace by removing first frames added by the error handler itself.
  393.                 for ($i 0; isset($backtrace[$i]); ++$i) {
  394.                     if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) {
  395.                         $backtrace \array_slice($backtrace$i);
  396.                         break;
  397.                     }
  398.                 }
  399.                 for ($i 0; isset($backtrace[$i]); ++$i) {
  400.                     if (!isset($backtrace[$i]['file'], $backtrace[$i]['line'], $backtrace[$i]['function'])) {
  401.                         continue;
  402.                     }
  403.                     if (!isset($backtrace[$i]['class']) && 'trigger_deprecation' === $backtrace[$i]['function']) {
  404.                         $file $backtrace[$i]['file'];
  405.                         $line $backtrace[$i]['line'];
  406.                         $backtrace \array_slice($backtrace$i);
  407.                         break;
  408.                     }
  409.                 }
  410.                 // Remove frames added by DebugClassLoader.
  411.                 for ($i \count($backtrace) - 2$i; --$i) {
  412.                     if (DebugClassLoader::class === ($backtrace[$i]['class'] ?? null)) {
  413.                         $backtrace = [$backtrace[$i 1]];
  414.                         break;
  415.                     }
  416.                 }
  417.                 $collectedLogs[$message] = [
  418.                     'type' => $type,
  419.                     'message' => $message,
  420.                     'file' => $file,
  421.                     'line' => $line,
  422.                     'trace' => [$backtrace[0]],
  423.                     'count' => 1,
  424.                 ];
  425.                 return null;
  426.             });
  427.         }
  428.         try {
  429.             $container null;
  430.             $container $this->buildContainer();
  431.             $container->compile();
  432.         } finally {
  433.             if ($collectDeprecations) {
  434.                 restore_error_handler();
  435.                 @file_put_contents($buildDir.'/'.$class.'Deprecations.log'serialize(array_values($collectedLogs)));
  436.                 @file_put_contents($buildDir.'/'.$class.'Compiler.log'null !== $container implode("\n"$container->getCompiler()->getLog()) : '');
  437.             }
  438.         }
  439.         $this->dumpContainer($cache$container$class$this->getContainerBaseClass());
  440.         if ($lock) {
  441.             flock($lock\LOCK_UN);
  442.             fclose($lock);
  443.         }
  444.         $this->container = require $cachePath;
  445.         $this->container->set('kernel'$this);
  446.         if ($oldContainer && $this->container::class !== $oldContainer->name) {
  447.             // Because concurrent requests might still be using them,
  448.             // old container files are not removed immediately,
  449.             // but on a next dump of the container.
  450.             static $legacyContainers = [];
  451.             $oldContainerDir \dirname($oldContainer->getFileName());
  452.             $legacyContainers[$oldContainerDir.'.legacy'] = true;
  453.             foreach (glob(\dirname($oldContainerDir).\DIRECTORY_SEPARATOR.'*.legacy'\GLOB_NOSORT) as $legacyContainer) {
  454.                 if (!isset($legacyContainers[$legacyContainer]) && @unlink($legacyContainer)) {
  455.                     (new Filesystem())->remove(substr($legacyContainer0, -7));
  456.                 }
  457.             }
  458.             touch($oldContainerDir.'.legacy');
  459.         }
  460.         $preload $this instanceof WarmableInterface ? (array) $this->warmUp($this->container->getParameter('kernel.cache_dir')) : [];
  461.         if ($this->container->has('cache_warmer')) {
  462.             $preload array_merge($preload, (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir')));
  463.         }
  464.         if ($preload && file_exists($preloadFile $buildDir.'/'.$class.'.preload.php')) {
  465.             Preloader::append($preloadFile$preload);
  466.         }
  467.     }
  468.     /**
  469.      * Returns the kernel parameters.
  470.      */
  471.     protected function getKernelParameters(): array
  472.     {
  473.         $bundles = [];
  474.         $bundlesMetadata = [];
  475.         foreach ($this->bundles as $name => $bundle) {
  476.             $bundles[$name] = $bundle::class;
  477.             $bundlesMetadata[$name] = [
  478.                 'path' => $bundle->getPath(),
  479.                 'namespace' => $bundle->getNamespace(),
  480.             ];
  481.         }
  482.         return [
  483.             'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(),
  484.             'kernel.environment' => $this->environment,
  485.             'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%',
  486.             'kernel.debug' => $this->debug,
  487.             'kernel.build_dir' => realpath($buildDir $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir,
  488.             'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir,
  489.             'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(),
  490.             'kernel.bundles' => $bundles,
  491.             'kernel.bundles_metadata' => $bundlesMetadata,
  492.             'kernel.charset' => $this->getCharset(),
  493.             'kernel.container_class' => $this->getContainerClass(),
  494.         ];
  495.     }
  496.     /**
  497.      * Builds the service container.
  498.      *
  499.      * @throws \RuntimeException
  500.      */
  501.     protected function buildContainer(): ContainerBuilder
  502.     {
  503.         foreach (['cache' => $this->getCacheDir(), 'build' => $this->warmupDir ?: $this->getBuildDir(), 'logs' => $this->getLogDir()] as $name => $dir) {
  504.             if (!is_dir($dir)) {
  505.                 if (false === @mkdir($dir0777true) && !is_dir($dir)) {
  506.                     throw new \RuntimeException(sprintf('Unable to create the "%s" directory (%s).'$name$dir));
  507.                 }
  508.             } elseif (!is_writable($dir)) {
  509.                 throw new \RuntimeException(sprintf('Unable to write in the "%s" directory (%s).'$name$dir));
  510.             }
  511.         }
  512.         $container $this->getContainerBuilder();
  513.         $container->addObjectResource($this);
  514.         $this->prepareContainer($container);
  515.         $this->registerContainerConfiguration($this->getContainerLoader($container));
  516.         $container->addCompilerPass(new AddAnnotatedClassesToCachePass($this));
  517.         return $container;
  518.     }
  519.     /**
  520.      * Prepares the ContainerBuilder before it is compiled.
  521.      *
  522.      * @return void
  523.      */
  524.     protected function prepareContainer(ContainerBuilder $container)
  525.     {
  526.         $extensions = [];
  527.         foreach ($this->bundles as $bundle) {
  528.             if ($extension $bundle->getContainerExtension()) {
  529.                 $container->registerExtension($extension);
  530.             }
  531.             if ($this->debug) {
  532.                 $container->addObjectResource($bundle);
  533.             }
  534.         }
  535.         foreach ($this->bundles as $bundle) {
  536.             $bundle->build($container);
  537.         }
  538.         $this->build($container);
  539.         foreach ($container->getExtensions() as $extension) {
  540.             $extensions[] = $extension->getAlias();
  541.         }
  542.         // ensure these extensions are implicitly loaded
  543.         $container->getCompilerPassConfig()->setMergePass(new MergeExtensionConfigurationPass($extensions));
  544.     }
  545.     /**
  546.      * Gets a new ContainerBuilder instance used to build the service container.
  547.      */
  548.     protected function getContainerBuilder(): ContainerBuilder
  549.     {
  550.         $container = new ContainerBuilder();
  551.         $container->getParameterBag()->add($this->getKernelParameters());
  552.         if ($this instanceof ExtensionInterface) {
  553.             $container->registerExtension($this);
  554.         }
  555.         if ($this instanceof CompilerPassInterface) {
  556.             $container->addCompilerPass($thisPassConfig::TYPE_BEFORE_OPTIMIZATION, -10000);
  557.         }
  558.         return $container;
  559.     }
  560.     /**
  561.      * Dumps the service container to PHP code in the cache.
  562.      *
  563.      * @param string $class     The name of the class to generate
  564.      * @param string $baseClass The name of the container's base class
  565.      *
  566.      * @return void
  567.      */
  568.     protected function dumpContainer(ConfigCache $cacheContainerBuilder $containerstring $classstring $baseClass)
  569.     {
  570.         // cache the container
  571.         $dumper = new PhpDumper($container);
  572.         $buildParameters = [];
  573.         foreach ($container->getCompilerPassConfig()->getPasses() as $pass) {
  574.             if ($pass instanceof RemoveBuildParametersPass) {
  575.                 $buildParameters array_merge($buildParameters$pass->getRemovedParameters());
  576.             }
  577.         }
  578.         $inlineFactories false;
  579.         if (isset($buildParameters['.container.dumper.inline_factories'])) {
  580.             $inlineFactories $buildParameters['.container.dumper.inline_factories'];
  581.         } elseif ($container->hasParameter('container.dumper.inline_factories')) {
  582.             trigger_deprecation('symfony/http-kernel''6.3''Parameter "%s" is deprecated, use ".%1$s" instead.''container.dumper.inline_factories');
  583.             $inlineFactories $container->getParameter('container.dumper.inline_factories');
  584.         }
  585.         $inlineClassLoader $this->debug;
  586.         if (isset($buildParameters['.container.dumper.inline_class_loader'])) {
  587.             $inlineClassLoader $buildParameters['.container.dumper.inline_class_loader'];
  588.         } elseif ($container->hasParameter('container.dumper.inline_class_loader')) {
  589.             trigger_deprecation('symfony/http-kernel''6.3''Parameter "%s" is deprecated, use ".%1$s" instead.''container.dumper.inline_class_loader');
  590.             $inlineClassLoader $container->getParameter('container.dumper.inline_class_loader');
  591.         }
  592.         $content $dumper->dump([
  593.             'class' => $class,
  594.             'base_class' => $baseClass,
  595.             'file' => $cache->getPath(),
  596.             'as_files' => true,
  597.             'debug' => $this->debug,
  598.             'inline_factories' => $inlineFactories,
  599.             'inline_class_loader' => $inlineClassLoader,
  600.             'build_time' => $container->hasParameter('kernel.container_build_time') ? $container->getParameter('kernel.container_build_time') : time(),
  601.             'preload_classes' => array_map('get_class'$this->bundles),
  602.         ]);
  603.         $rootCode array_pop($content);
  604.         $dir \dirname($cache->getPath()).'/';
  605.         $fs = new Filesystem();
  606.         foreach ($content as $file => $code) {
  607.             $fs->dumpFile($dir.$file$code);
  608.             @chmod($dir.$file0666 & ~umask());
  609.         }
  610.         $legacyFile \dirname($dir.key($content)).'.legacy';
  611.         if (is_file($legacyFile)) {
  612.             @unlink($legacyFile);
  613.         }
  614.         $cache->write($rootCode$container->getResources());
  615.     }
  616.     /**
  617.      * Returns a loader for the container.
  618.      */
  619.     protected function getContainerLoader(ContainerInterface $container): DelegatingLoader
  620.     {
  621.         $env $this->getEnvironment();
  622.         $locator = new FileLocator($this);
  623.         $resolver = new LoaderResolver([
  624.             new XmlFileLoader($container$locator$env),
  625.             new YamlFileLoader($container$locator$env),
  626.             new IniFileLoader($container$locator$env),
  627.             new PhpFileLoader($container$locator$envclass_exists(ConfigBuilderGenerator::class) ? new ConfigBuilderGenerator($this->getBuildDir()) : null),
  628.             new GlobFileLoader($container$locator$env),
  629.             new DirectoryLoader($container$locator$env),
  630.             new ClosureLoader($container$env),
  631.         ]);
  632.         return new DelegatingLoader($resolver);
  633.     }
  634.     private function preBoot(): ContainerInterface
  635.     {
  636.         if ($this->debug) {
  637.             $this->startTime microtime(true);
  638.         }
  639.         if ($this->debug && !isset($_ENV['SHELL_VERBOSITY']) && !isset($_SERVER['SHELL_VERBOSITY'])) {
  640.             if (\function_exists('putenv')) {
  641.                 putenv('SHELL_VERBOSITY=3');
  642.             }
  643.             $_ENV['SHELL_VERBOSITY'] = 3;
  644.             $_SERVER['SHELL_VERBOSITY'] = 3;
  645.         }
  646.         $this->initializeBundles();
  647.         $this->initializeContainer();
  648.         $container $this->container;
  649.         if ($container->hasParameter('kernel.trusted_hosts') && $trustedHosts $container->getParameter('kernel.trusted_hosts')) {
  650.             Request::setTrustedHosts($trustedHosts);
  651.         }
  652.         if ($container->hasParameter('kernel.trusted_proxies') && $container->hasParameter('kernel.trusted_headers') && $trustedProxies $container->getParameter('kernel.trusted_proxies')) {
  653.             Request::setTrustedProxies(\is_array($trustedProxies) ? $trustedProxies array_map('trim'explode(','$trustedProxies)), $container->getParameter('kernel.trusted_headers'));
  654.         }
  655.         return $container;
  656.     }
  657.     /**
  658.      * Removes comments from a PHP source string.
  659.      *
  660.      * We don't use the PHP php_strip_whitespace() function
  661.      * as we want the content to be readable and well-formatted.
  662.      */
  663.     public static function stripComments(string $source): string
  664.     {
  665.         if (!\function_exists('token_get_all')) {
  666.             return $source;
  667.         }
  668.         $rawChunk '';
  669.         $output '';
  670.         $tokens token_get_all($source);
  671.         $ignoreSpace false;
  672.         for ($i 0; isset($tokens[$i]); ++$i) {
  673.             $token $tokens[$i];
  674.             if (!isset($token[1]) || 'b"' === $token) {
  675.                 $rawChunk .= $token;
  676.             } elseif (\T_START_HEREDOC === $token[0]) {
  677.                 $output .= $rawChunk.$token[1];
  678.                 do {
  679.                     $token $tokens[++$i];
  680.                     $output .= isset($token[1]) && 'b"' !== $token $token[1] : $token;
  681.                 } while (\T_END_HEREDOC !== $token[0]);
  682.                 $rawChunk '';
  683.             } elseif (\T_WHITESPACE === $token[0]) {
  684.                 if ($ignoreSpace) {
  685.                     $ignoreSpace false;
  686.                     continue;
  687.                 }
  688.                 // replace multiple new lines with a single newline
  689.                 $rawChunk .= preg_replace(['/\n{2,}/S'], "\n"$token[1]);
  690.             } elseif (\in_array($token[0], [\T_COMMENT\T_DOC_COMMENT])) {
  691.                 if (!\in_array($rawChunk[\strlen($rawChunk) - 1], [' '"\n""\r""\t"], true)) {
  692.                     $rawChunk .= ' ';
  693.                 }
  694.                 $ignoreSpace true;
  695.             } else {
  696.                 $rawChunk .= $token[1];
  697.                 // The PHP-open tag already has a new-line
  698.                 if (\T_OPEN_TAG === $token[0]) {
  699.                     $ignoreSpace true;
  700.                 } else {
  701.                     $ignoreSpace false;
  702.                 }
  703.             }
  704.         }
  705.         $output .= $rawChunk;
  706.         unset($tokens$rawChunk);
  707.         gc_mem_caches();
  708.         return $output;
  709.     }
  710.     public function __sleep(): array
  711.     {
  712.         return ['environment''debug'];
  713.     }
  714.     public function __wakeup()
  715.     {
  716.         if (\is_object($this->environment) || \is_object($this->debug)) {
  717.             throw new \BadMethodCallException('Cannot unserialize '.__CLASS__);
  718.         }
  719.         $this->__construct($this->environment$this->debug);
  720.     }
  721. }