bug #26662 [DI] Fix hardcoded cache dir for warmups (nicolas-grekas)
This PR was merged into the 3.4 branch.
Discussion
----------
[DI] Fix hardcoded cache dir for warmups
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #26506, #26219
| License | MIT
| Doc PR | -
Commits
-------
599dbca3cd
[DI] Fix hardcoded cache dir for warmups
This commit is contained in:
commit
02e59d4610
@ -241,7 +241,7 @@ return new \\Container{$hash}\\{$options['class']}(array(
|
||||
'container.build_hash' => '$hash',
|
||||
'container.build_id' => '$id',
|
||||
'container.build_time' => $time,
|
||||
));
|
||||
), __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}');
|
||||
|
||||
EOF;
|
||||
} else {
|
||||
@ -789,7 +789,7 @@ EOF;
|
||||
}
|
||||
|
||||
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
|
||||
$factoryCode = $asFile ? "\$this->load(__DIR__.'/%s.php', false)" : '$this->%s(false)';
|
||||
$factoryCode = $asFile ? "\$this->load('%s.php', false)" : '$this->%s(false)';
|
||||
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName));
|
||||
}
|
||||
|
||||
@ -963,7 +963,7 @@ class $class extends $baseClass
|
||||
|
||||
EOF;
|
||||
if (null !== $this->targetDirRegex) {
|
||||
$dir = $this->asFiles ? '$this->targetDirs[0] = \\dirname(__DIR__)' : '__DIR__';
|
||||
$dir = $this->asFiles ? '$this->targetDirs[0] = \\dirname($containerDir)' : '__DIR__';
|
||||
$code .= <<<EOF
|
||||
\$dir = {$dir};
|
||||
for (\$i = 1; \$i <= {$this->targetDirMaxMatches}; ++\$i) {
|
||||
@ -973,9 +973,10 @@ EOF;
|
||||
EOF;
|
||||
}
|
||||
if ($this->asFiles) {
|
||||
$code = str_replace('$parameters', "\$buildParameters;\n private \$parameters", $code);
|
||||
$code = str_replace('__construct()', '__construct(array $buildParameters = array())', $code);
|
||||
$code = str_replace('$parameters', "\$buildParameters;\n private \$containerDir;\n private \$parameters", $code);
|
||||
$code = str_replace('__construct()', '__construct(array $buildParameters = array(), $containerDir = __DIR__)', $code);
|
||||
$code .= " \$this->buildParameters = \$buildParameters;\n";
|
||||
$code .= " \$this->containerDir = \$containerDir;\n";
|
||||
}
|
||||
|
||||
if ($this->container->isCompiled()) {
|
||||
@ -1042,7 +1043,7 @@ EOF;
|
||||
|
||||
protected function load(\$file, \$lazyLoad = true)
|
||||
{
|
||||
return require \$file;
|
||||
return require \$this->containerDir.\\DIRECTORY_SEPARATOR.\$file;
|
||||
}
|
||||
|
||||
EOF;
|
||||
@ -1054,7 +1055,7 @@ EOF;
|
||||
continue;
|
||||
}
|
||||
if ($this->asFiles) {
|
||||
$proxyLoader = '$this->load(__DIR__."/{$class}.php")';
|
||||
$proxyLoader = '$this->load("{$class}.php")';
|
||||
} elseif ($this->namespace) {
|
||||
$proxyLoader = 'class_alias("'.$this->namespace.'\\\\{$class}", $class, false)';
|
||||
} else {
|
||||
@ -1126,7 +1127,7 @@ EOF;
|
||||
return '';
|
||||
}
|
||||
if ($this->asFiles) {
|
||||
$code = "require __DIR__.'/removed-ids.php'";
|
||||
$code = "require \$this->containerDir.\\DIRECTORY_SEPARATOR.'removed-ids.php'";
|
||||
} else {
|
||||
$code = '';
|
||||
$ids = array_keys($ids);
|
||||
@ -1179,7 +1180,7 @@ EOF;
|
||||
ksort($definitions);
|
||||
foreach ($definitions as $id => $definition) {
|
||||
if (!$definition->isSynthetic() && $definition->isShared() && !$this->isHotPath($definition)) {
|
||||
$code .= sprintf(" %s => __DIR__.'/%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
|
||||
$code .= sprintf(" %s => '%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1901,7 +1902,7 @@ EOF;
|
||||
$code = sprintf('$this->services[\'%s\'] = %s', $id, $code);
|
||||
}
|
||||
} elseif ($this->asFiles && $definition->isShared() && !$this->isHotPath($definition)) {
|
||||
$code = sprintf("\$this->load(__DIR__.'/%s.php')", $this->generateMethodName($id));
|
||||
$code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id));
|
||||
} else {
|
||||
$code = sprintf('$this->%s()', $this->generateMethodName($id));
|
||||
}
|
||||
@ -2043,7 +2044,7 @@ EOF;
|
||||
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
|
||||
$suffix = $matches[0][1] + strlen($matches[0][0]);
|
||||
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
|
||||
$dirname = '__DIR__';
|
||||
$dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
|
||||
$offset = 1 + $this->targetDirMaxMatches - count($matches);
|
||||
|
||||
if ($this->asFiles || 0 < $offset) {
|
||||
|
@ -24,7 +24,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
|
||||
$this->services['baz'] = $instance = new \Baz();
|
||||
|
||||
$instance->setFoo(${($_ = isset($this->services['foo_with_inline']) ? $this->services['foo_with_inline'] : $this->load(__DIR__.'/getFooWithInlineService.php')) && false ?: '_'});
|
||||
$instance->setFoo(${($_ = isset($this->services['foo_with_inline']) ? $this->services['foo_with_inline'] : $this->load('getFooWithInlineService.php')) && false ?: '_'});
|
||||
|
||||
return $instance;
|
||||
|
||||
@ -38,7 +38,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
$this->services['configured_service'] = $instance = new \stdClass();
|
||||
|
||||
$a = new \ConfClass();
|
||||
$a->setFoo(${($_ = isset($this->services['baz']) ? $this->services['baz'] : $this->load(__DIR__.'/getBazService.php')) && false ?: '_'});
|
||||
$a->setFoo(${($_ = isset($this->services['baz']) ? $this->services['baz'] : $this->load('getBazService.php')) && false ?: '_'});
|
||||
|
||||
$a->configureStdClass($instance);
|
||||
|
||||
@ -93,7 +93,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
|
||||
// Returns the public 'factory_service' shared service.
|
||||
|
||||
return $this->services['factory_service'] = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'}->getInstance();
|
||||
return $this->services['factory_service'] = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'}->getInstance();
|
||||
|
||||
[Container%s/getFactoryServiceSimpleService.php] => <?php
|
||||
|
||||
@ -102,7 +102,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
|
||||
// Returns the public 'factory_service_simple' shared service.
|
||||
|
||||
return $this->services['factory_service_simple'] = ${($_ = isset($this->services['factory_simple']) ? $this->services['factory_simple'] : $this->load(__DIR__.'/getFactorySimpleService.php')) && false ?: '_'}->getInstance();
|
||||
return $this->services['factory_service_simple'] = ${($_ = isset($this->services['factory_simple']) ? $this->services['factory_simple'] : $this->load('getFactorySimpleService.php')) && false ?: '_'}->getInstance();
|
||||
|
||||
[Container%s/getFactorySimpleService.php] => <?php
|
||||
|
||||
@ -122,7 +122,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
|
||||
// Returns the public 'foo' shared service.
|
||||
|
||||
$a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'};
|
||||
$a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'};
|
||||
|
||||
$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
|
||||
|
||||
@ -160,7 +160,7 @@ $this->services['foo_with_inline'] = $instance = new \Foo();
|
||||
$a = new \Bar();
|
||||
|
||||
$a->pub = 'pub';
|
||||
$a->setBaz(${($_ = isset($this->services['baz']) ? $this->services['baz'] : $this->load(__DIR__.'/getBazService.php')) && false ?: '_'});
|
||||
$a->setBaz(${($_ = isset($this->services['baz']) ? $this->services['baz'] : $this->load('getBazService.php')) && false ?: '_'});
|
||||
|
||||
$instance->setBar($a);
|
||||
|
||||
@ -174,7 +174,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
// Returns the public 'lazy_context' shared service.
|
||||
|
||||
return $this->services['lazy_context'] = new \LazyContext(new RewindableGenerator(function () {
|
||||
yield 'k1' => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'};
|
||||
yield 'k1' => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'};
|
||||
yield 'k2' => $this;
|
||||
}, 2), new RewindableGenerator(function () {
|
||||
return new \EmptyIterator();
|
||||
@ -188,7 +188,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
// Returns the public 'lazy_context_ignore_invalid_ref' shared service.
|
||||
|
||||
return $this->services['lazy_context_ignore_invalid_ref'] = new \LazyContext(new RewindableGenerator(function () {
|
||||
yield 0 => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'};
|
||||
yield 0 => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'};
|
||||
}, 1), new RewindableGenerator(function () {
|
||||
return new \EmptyIterator();
|
||||
}, 0));
|
||||
@ -204,9 +204,9 @@ include_once ($this->targetDirs[0].'/Fixtures/includes/foo.php');
|
||||
|
||||
$this->services['method_call1'] = $instance = new \Bar\FooClass();
|
||||
|
||||
$instance->setBar(${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load(__DIR__.'/getFooService.php')) && false ?: '_'});
|
||||
$instance->setBar(${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load('getFooService.php')) && false ?: '_'});
|
||||
$instance->setBar(NULL);
|
||||
$instance->setBar((${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load(__DIR__.'/getFooService.php')) && false ?: '_'}->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
|
||||
$instance->setBar((${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load('getFooService.php')) && false ?: '_'}->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
|
||||
|
||||
return $instance;
|
||||
|
||||
@ -243,7 +243,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
|
||||
// Returns the public 'tagged_iterator' shared service.
|
||||
|
||||
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
|
||||
yield 0 => ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load(__DIR__.'/getFooService.php')) && false ?: '_'};
|
||||
yield 0 => ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load('getFooService.php')) && false ?: '_'};
|
||||
yield 1 => ${($_ = isset($this->services['tagged_iterator_foo']) ? $this->services['tagged_iterator_foo'] : $this->services['tagged_iterator_foo'] = new \Bar()) && false ?: '_'};
|
||||
}, 2));
|
||||
|
||||
@ -277,16 +277,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
|
||||
class ProjectServiceContainer extends Container
|
||||
{
|
||||
private $buildParameters;
|
||||
private $containerDir;
|
||||
private $parameters;
|
||||
private $targetDirs = array();
|
||||
|
||||
public function __construct(array $buildParameters = array())
|
||||
public function __construct(array $buildParameters = array(), $containerDir = __DIR__)
|
||||
{
|
||||
$dir = $this->targetDirs[0] = \dirname(__DIR__);
|
||||
$dir = $this->targetDirs[0] = \dirname($containerDir);
|
||||
for ($i = 1; $i <= 5; ++$i) {
|
||||
$this->targetDirs[$i] = $dir = \dirname($dir);
|
||||
}
|
||||
$this->buildParameters = $buildParameters;
|
||||
$this->containerDir = $containerDir;
|
||||
$this->parameters = $this->getDefaultParameters();
|
||||
|
||||
$this->services = array();
|
||||
@ -298,25 +300,25 @@ class ProjectServiceContainer extends Container
|
||||
'foo_bar' => 'getFooBarService',
|
||||
);
|
||||
$this->fileMap = array(
|
||||
'baz' => __DIR__.'/getBazService.php',
|
||||
'configured_service' => __DIR__.'/getConfiguredServiceService.php',
|
||||
'configured_service_simple' => __DIR__.'/getConfiguredServiceSimpleService.php',
|
||||
'decorator_service' => __DIR__.'/getDecoratorServiceService.php',
|
||||
'decorator_service_with_name' => __DIR__.'/getDecoratorServiceWithNameService.php',
|
||||
'deprecated_service' => __DIR__.'/getDeprecatedServiceService.php',
|
||||
'factory_service' => __DIR__.'/getFactoryServiceService.php',
|
||||
'factory_service_simple' => __DIR__.'/getFactoryServiceSimpleService.php',
|
||||
'factory_simple' => __DIR__.'/getFactorySimpleService.php',
|
||||
'foo' => __DIR__.'/getFooService.php',
|
||||
'foo.baz' => __DIR__.'/getFoo_BazService.php',
|
||||
'foo_with_inline' => __DIR__.'/getFooWithInlineService.php',
|
||||
'lazy_context' => __DIR__.'/getLazyContextService.php',
|
||||
'lazy_context_ignore_invalid_ref' => __DIR__.'/getLazyContextIgnoreInvalidRefService.php',
|
||||
'method_call1' => __DIR__.'/getMethodCall1Service.php',
|
||||
'new_factory_service' => __DIR__.'/getNewFactoryServiceService.php',
|
||||
'service_from_static_method' => __DIR__.'/getServiceFromStaticMethodService.php',
|
||||
'tagged_iterator' => __DIR__.'/getTaggedIteratorService.php',
|
||||
'tagged_iterator_foo' => __DIR__.'/getTaggedIteratorFooService.php',
|
||||
'baz' => 'getBazService.php',
|
||||
'configured_service' => 'getConfiguredServiceService.php',
|
||||
'configured_service_simple' => 'getConfiguredServiceSimpleService.php',
|
||||
'decorator_service' => 'getDecoratorServiceService.php',
|
||||
'decorator_service_with_name' => 'getDecoratorServiceWithNameService.php',
|
||||
'deprecated_service' => 'getDeprecatedServiceService.php',
|
||||
'factory_service' => 'getFactoryServiceService.php',
|
||||
'factory_service_simple' => 'getFactoryServiceSimpleService.php',
|
||||
'factory_simple' => 'getFactorySimpleService.php',
|
||||
'foo' => 'getFooService.php',
|
||||
'foo.baz' => 'getFoo_BazService.php',
|
||||
'foo_with_inline' => 'getFooWithInlineService.php',
|
||||
'lazy_context' => 'getLazyContextService.php',
|
||||
'lazy_context_ignore_invalid_ref' => 'getLazyContextIgnoreInvalidRefService.php',
|
||||
'method_call1' => 'getMethodCall1Service.php',
|
||||
'new_factory_service' => 'getNewFactoryServiceService.php',
|
||||
'service_from_static_method' => 'getServiceFromStaticMethodService.php',
|
||||
'tagged_iterator' => 'getTaggedIteratorService.php',
|
||||
'tagged_iterator_foo' => 'getTaggedIteratorFooService.php',
|
||||
);
|
||||
$this->privates = array(
|
||||
'factory_simple' => true,
|
||||
@ -331,7 +333,7 @@ class ProjectServiceContainer extends Container
|
||||
|
||||
public function getRemovedIds()
|
||||
{
|
||||
return require __DIR__.'/removed-ids.php';
|
||||
return require $this->containerDir.\DIRECTORY_SEPARATOR.'removed-ids.php';
|
||||
}
|
||||
|
||||
public function compile()
|
||||
@ -353,7 +355,7 @@ class ProjectServiceContainer extends Container
|
||||
|
||||
protected function load($file, $lazyLoad = true)
|
||||
{
|
||||
return require $file;
|
||||
return require $this->containerDir.\DIRECTORY_SEPARATOR.$file;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -363,7 +365,7 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getBarService()
|
||||
{
|
||||
$a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'};
|
||||
$a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'};
|
||||
|
||||
$this->services['bar'] = $instance = new \Bar\FooClass('foo', $a, $this->getParameter('foo_bar'));
|
||||
|
||||
@ -379,7 +381,7 @@ class ProjectServiceContainer extends Container
|
||||
*/
|
||||
protected function getFooBarService()
|
||||
{
|
||||
return new \Bar\FooClass(${($_ = isset($this->services['deprecated_service']) ? $this->services['deprecated_service'] : $this->load(__DIR__.'/getDeprecatedServiceService.php')) && false ?: '_'});
|
||||
return new \Bar\FooClass(${($_ = isset($this->services['deprecated_service']) ? $this->services['deprecated_service'] : $this->load('getDeprecatedServiceService.php')) && false ?: '_'});
|
||||
}
|
||||
|
||||
public function getParameter($name)
|
||||
@ -502,6 +504,6 @@ return new \Container%s\ProjectServiceContainer(array(
|
||||
'container.build_hash' => '%s',
|
||||
'container.build_id' => '%s',
|
||||
'container.build_time' => %d,
|
||||
));
|
||||
), __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
|
||||
|
||||
)
|
||||
|
Reference in New Issue
Block a user