Files
archived-framework-bundle/Command/BuildDebugContainerTrait.php
Nicolas Grekas 52fc4dea53 Merge branch '7.4' into 8.0
* 7.4: (21 commits)
  [SecurityBundle] Fix tests with Symfony 7.4
  [DependencyInjection] Ensure deprecation detection does not trigger a PHP error
  [DependencyInjection][FrameworkBundle] fix BC break when dumping container for build/lint commands
  [Form] Clean up wrong method docblocks in data transformers
  Fix merge
  [DependencyInjection] Throw when using `$this` or its internal scope from PHP config files; use the `$loader` variable instead
  [HttpClient] Fix sharing CurlClientState between clones of CurlHttpClient instances
  [FrameworkBundle] Don't exclude classes with constraint/serialization attributes from being registered as services
  Revert "[HttpClient] Lazily initialize CurlClientState"
  [Yaml] Fix regression handling blank lines in unquoted scalars
  [Cache] Fix NullAdapter must set taggable
  [FrameworkBundle] Order alphabetically known tags of `UnusedTagsPass`
  allow the installation of MercureBundle 0.4
  [Console] don't discard existing aliases when constructing Command
  Import all node definition classes to DefinitionConfigurator
  Fix the creation of a redis connection with only ext-relay
  [FrameworkBundle] Dump bundles config reference first
  [DependencyInjection] Don't add the .container.known_envs parameter when empty
  [DependencyInjection] Reset resolved state when setting a parameter
  [HttpKernel] Don't reset services between fragments redering when using in HttpCache
  ...
2025-12-04 19:17:06 +01:00

72 lines
2.3 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* @internal
*
* @author Robin Chalas <robin.chalas@gmail.com>
* @author Nicolas Grekas <p@tchwork.com>
*/
trait BuildDebugContainerTrait
{
protected ContainerBuilder $container;
/**
* Loads the ContainerBuilder from the cache.
*
* @throws \LogicException
*/
protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilder
{
if (isset($this->container)) {
return $this->container;
}
$file = $kernel->isDebug() ? $kernel->getContainer()->getParameter('debug.container.dump') : false;
if (!$file || !(new ConfigCache($file, true))->isFresh()) {
$buildContainer = \Closure::bind(function () {
$this->initializeBundles();
return $this->buildContainer();
}, $kernel, $kernel::class);
$container = $buildContainer();
$container->getCompilerPassConfig()->setRemovingPasses([]);
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
$container->compile();
} else {
$buildContainer = \Closure::bind(function () {
$containerBuilder = $this->getContainerBuilder();
$this->prepareContainer($containerBuilder);
return $containerBuilder;
}, $kernel, $kernel::class);
$container = $buildContainer();
$dumpedContainer = unserialize(file_get_contents(substr_replace($file, '.ser', -4)));
$container->setDefinitions($dumpedContainer->getDefinitions());
$container->setAliases($dumpedContainer->getAliases());
$parameterBag = $container->getParameterBag();
$parameterBag->clear();
$parameterBag->add($dumpedContainer->getParameterBag()->all());
}
return $this->container = $container;
}
}