8000 [Kernel+DIC] Fixed as_files habavior · symfony/symfony@e109e8a · GitHub
[go: up one dir, main page]

Skip to content

Commit e109e8a

Browse files
committed
[Kernel+DIC] Fixed as_files habavior
Many issue about this: * Kernel does not handle when the dumper returns a string * Kernel does not handle when the compiled Container file does not return a new instance of itself * Kernel try to old load and clean old container, but if the container does not change its name, it tries to load 2 time the same file, and so the same class This patch fixed all theses case. Now we can use with easy a multifiles container or a simple unique file.
1 parent 370682c commit e109e8a

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ public function dump(array $options = [])
269269
foreach ($this->generateProxyClasses() as $c) {
270270
$code .= $c;
271271
}
272+
273+
$code .= sprintf("\nreturn new %s();\n", $options['class']);
272274
}
273275

274276
$this->targetDirRegex = null;
@@ -1308,6 +1310,10 @@ private function addDefaultParametersMethod()
13081310
}
13091311
}
13101312

1313+
if (!$this->asFiles) {
1314+
$php[] = sprintf("%s'container.build_id' => 'static',", $export[0]);
1315+
}
1316+
13111317
$parameters = sprintf("[\n%s\n%s]", implode("\n", $php), str_repeat(' ', 8));
13121318

13131319
$code = '';

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,9 @@ protected function initializeContainer()
644644
}
645645
}
646646

647-
if (null === $oldContainer && file_exists($cache->getPath())) {
647+
$asFiles = true;
648+
649+
if ($asFiles && null === $oldContainer && file_exists($cache->getPath())) {
648650
$errorLevel = error_reporting(\E_ALL ^ \E_WARNING);
649651
try {
650652
$oldContainer = include $cache->getPath();
@@ -655,8 +657,7 @@ protected function initializeContainer()
655657
}
656658
}
657659
$oldContainer = \is_object($oldContainer) ? new \ReflectionClass($oldContainer) : false;
658-
659-
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());
660+
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass(), $asFiles);
660661
$this->container = require $cache->getPath();
661662
$this->container->set('kernel', $this);
662663

@@ -835,7 +836,7 @@ protected function getContainerBuilder()
835836
* @param string $class The name of the class to generate
836837
* @param string $baseClass The name of the container's base class
837838
*/
838-
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass)
839+
protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass, bool $asFiles = true)
839840
{
840841
// cache the container
841842
$dumper = new PhpDumper($container);
@@ -848,23 +849,28 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container
848849
'class' => $class,
849850
'base_class' => $baseClass,
850851
'file' => $cache->getPath(),
851-
'as_files' => true,
852+
'as_files' => $asFiles,
852853
'debug' => $this->debug,
853854
'inline_class_loader_parameter' => \PHP_VERSION_ID >= 70000 && !$this->loadClassCache && !class_exists( 8000 ClassCollectionLoader::class, false) ? 'container.dumper.inline_class_loader' : null,
854855
'build_time' => $container->hasParameter('kernel.container_build_time') ? $container->getParameter('kernel.container_build_time') : time(),
855856
]);
856857

857-
$rootCode = array_pop($content);
858-
$dir = \dirname($cache->getPath()).'/';
859858
$fs = new Filesystem();
860859

861-
foreach ($content as $file => $code) {
862-
$fs->dumpFile($dir.$file, $code);
863-
@chmod($dir.$file, 0666 & ~umask());
864-
}
865-
$legacyFile = \dirname($dir.$file).'.legacy';
866-
if (file_exists($legacyFile)) {
867-
@unlink($legacyFile);
860+
if (\is_array($content)) {
861+
$rootCode = array_pop($content);
862+
$dir = \dirname($cache->getPath()).'/';
863+
864+
foreach ($content as $file => $code) {
865+
$fs->dumpFile($dir.$file, $code);
866+
@chmod($dir.$file, 0666 & ~umask());
867+
}
868+
$legacyFile = \dirname($dir.$file).'.legacy';
869+
if (file_exists($legacyFile)) {
870+
@unlink($legacyFile);
871+
}
872+
} else {
873+
$rootCode = $content;
868874
}
869875

870876
$cache->write($rootCode, $container->getResources());

0 commit comments

Comments
 (0)
0