bug #36581 [DI] fix not preloading excluded service factories (nicolas-grekas)
This PR was merged into the 5.1-dev branch.
Discussion
----------
[DI] fix not preloading excluded service factories
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR | -
Commits
-------
2a20c6e605
[DI] fix not preloading excluded service factories
This commit is contained in:
commit
4170346ea7
@ -118,9 +118,9 @@ EOF
|
||||
$warmer = $kernel->getContainer()->get('cache_warmer');
|
||||
// non optional warmers already ran during container compilation
|
||||
$warmer->enableOnlyOptionalWarmers();
|
||||
$preload = (array) $warmer->warmUp($warmupDir);
|
||||
$preload = (array) $warmer->warmUp($realCacheDir);
|
||||
|
||||
if (file_exists($preloadFile = $warmupDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
|
||||
if (file_exists($preloadFile = $realCacheDir.'/'.$kernel->getContainer()->getParameter('kernel.container_class').'.preload.php')) {
|
||||
Preloader::append($preloadFile, $preload);
|
||||
}
|
||||
}
|
||||
|
@ -270,7 +270,7 @@ class %s extends {$options['class']}
|
||||
|
||||
EOF;
|
||||
$files = [];
|
||||
|
||||
$preloadedFiles = [];
|
||||
$ids = $this->container->getRemovedIds();
|
||||
foreach ($this->container->getDefinitions() as $id => $definition) {
|
||||
if (!$definition->isPublic()) {
|
||||
@ -287,11 +287,16 @@ EOF;
|
||||
}
|
||||
|
||||
if (!$this->inlineFactories) {
|
||||
foreach ($this->generateServiceFiles($services) as $file => $c) {
|
||||
foreach ($this->generateServiceFiles($services) as $file => [$c, $preload]) {
|
||||
$files[$file] = sprintf($fileTemplate, substr($file, 0, -4), $c);
|
||||
|
||||
if ($preload) {
|
||||
$preloadedFiles[$file] = $file;
|
||||
}
|
||||
}
|
||||
foreach ($proxyClasses as $file => $c) {
|
||||
$files[$file] = "<?php\n".$c;
|
||||
$preloadedFiles[$file] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
@ -304,11 +309,16 @@ EOF;
|
||||
}
|
||||
|
||||
$files[$options['class'].'.php'] = $code;
|
||||
$preloadedFiles[$options['class'].'.php'] = $options['class'].'.php';
|
||||
$hash = ucfirst(strtr(ContainerBuilder::hash($files), '._', 'xx'));
|
||||
$code = [];
|
||||
|
||||
foreach ($files as $file => $c) {
|
||||
$code["Container{$hash}/{$file}"] = substr_replace($c, "<?php\n\nnamespace Container{$hash};\n", 0, 6);
|
||||
|
||||
if (isset($preloadedFiles[$file])) {
|
||||
$preloadedFiles[$file] = "Container{$hash}/{$file}";
|
||||
}
|
||||
}
|
||||
$namespaceLine = $this->namespace ? "\nnamespace {$this->namespace};\n" : '';
|
||||
$time = $options['build_time'];
|
||||
@ -318,8 +328,8 @@ EOF;
|
||||
if ($this->preload && null !== $autoloadFile = $this->getAutoloadFile()) {
|
||||
$autoloadFile = substr($this->export($autoloadFile), 2, -1);
|
||||
|
||||
$factoryFiles = array_reverse(array_keys($code));
|
||||
$factoryFiles = implode("';\nrequire __DIR__.'/", $factoryFiles);
|
||||
$preloadedFiles = array_reverse($preloadedFiles);
|
||||
$preloadedFiles = implode("';\nrequire __DIR__.'/", $preloadedFiles);
|
||||
|
||||
$code[$options['class'].'.preload.php'] = <<<EOF
|
||||
<?php
|
||||
@ -330,7 +340,7 @@ EOF;
|
||||
use Symfony\Component\DependencyInjection\Dumper\Preloader;
|
||||
|
||||
require $autoloadFile;
|
||||
require __DIR__.'/$factoryFiles';
|
||||
require __DIR__.'/$preloadedFiles';
|
||||
|
||||
\$classes = [];
|
||||
|
||||
@ -1036,7 +1046,7 @@ EOTXT
|
||||
ksort($definitions);
|
||||
foreach ($definitions as $id => $definition) {
|
||||
if ((list($file, $code) = $services[$id]) && null !== $file && ($definition->isPublic() || !$this->isTrivialInstance($definition) || isset($this->locatedIds[$id]))) {
|
||||
yield $file => $code;
|
||||
yield $file => [$code, !$definition->hasTag($this->preloadTags[1]) && !$definition->isDeprecated() && !$definition->hasErrors()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -907,10 +907,8 @@ require __DIR__.'/Container%s/getFooWithInlineService.php';
|
||||
require __DIR__.'/Container%s/getFooBarService.php';
|
||||
require __DIR__.'/Container%s/getFoo_BazService.php';
|
||||
require __DIR__.'/Container%s/getFooService.php';
|
||||
require __DIR__.'/Container%s/getFactorySimpleService.php';
|
||||
require __DIR__.'/Container%s/getFactoryServiceSimpleService.php';
|
||||
require __DIR__.'/Container%s/getFactoryServiceService.php';
|
||||
require __DIR__.'/Container%s/getDeprecatedServiceService.php';
|
||||
require __DIR__.'/Container%s/getDecoratorServiceWithNameService.php';
|
||||
require __DIR__.'/Container%s/getDecoratorServiceService.php';
|
||||
require __DIR__.'/Container%s/getConfiguredServiceSimpleService.php';
|
||||
@ -919,7 +917,6 @@ require __DIR__.'/Container%s/getBazService.php';
|
||||
require __DIR__.'/Container%s/getBar23Service.php';
|
||||
require __DIR__.'/Container%s/getBAR22Service.php';
|
||||
require __DIR__.'/Container%s/getBAR2Service.php';
|
||||
require __DIR__.'/Container%s/removed-ids.php';
|
||||
|
||||
$classes = [];
|
||||
$classes[] = 'Bar\FooClass';
|
||||
|
@ -548,7 +548,6 @@ use Symfony\Component\DependencyInjection\Dumper\Preloader;
|
||||
|
||||
require dirname(__DIR__, %d).'%svendor/autoload.php';
|
||||
require __DIR__.'/Container%s/ProjectServiceContainer.php';
|
||||
require __DIR__.'/Container%s/removed-ids.php';
|
||||
|
||||
$classes = [];
|
||||
$classes[] = 'Bar\FooClass';
|
||||
|
@ -171,7 +171,6 @@ use Symfony\Component\DependencyInjection\Dumper\Preloader;
|
||||
|
||||
require dirname(__DIR__, %d).'%svendor/autoload.php';
|
||||
require __DIR__.'/Container%s/ProjectServiceContainer.php';
|
||||
require __DIR__.'/Container%s/removed-ids.php';
|
||||
|
||||
$classes = [];
|
||||
$classes[] = 'Bar\FooClass';
|
||||
|
@ -113,7 +113,6 @@ use Symfony\Component\DependencyInjection\Dumper\Preloader;
|
||||
require dirname(__DIR__, %d).'%svendor/autoload.php';
|
||||
require __DIR__.'/Container%s/ProjectServiceContainer.php';
|
||||
require __DIR__.'/Container%s/getNonSharedFooService.php';
|
||||
require __DIR__.'/Container%s/removed-ids.php';
|
||||
|
||||
$classes = [];
|
||||
$classes[] = 'Bar\FooLazyClass';
|
||||
|
Reference in New Issue
Block a user