Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 599dbca

Browse filesBrowse files
[DI] Fix hardcoded cache dir for warmups
1 parent b9a2e21 commit 599dbca
Copy full SHA for 599dbca

File tree

2 files changed

+51
-48
lines changed
Filter options

2 files changed

+51
-48
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
+12-11Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public function dump(array $options = array())
241241
'container.build_hash' => '$hash',
242242
'container.build_id' => '$id',
243243
'container.build_time' => $time,
244-
));
244+
), __DIR__.\\DIRECTORY_SEPARATOR.'Container{$hash}');
245245
246246
EOF;
247247
} else {
@@ -789,7 +789,7 @@ protected function {$methodName}($lazyInitialization)
789789
}
790790

791791
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
792-
$factoryCode = $asFile ? "\$this->load(__DIR__.'/%s.php', false)" : '$this->%s(false)';
792+
$factoryCode = $asFile ? "\$this->load('%s.php', false)" : '$this->%s(false)';
793793
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName));
794794
}
795795

@@ -963,7 +963,7 @@ public function __construct()
963963
964964
EOF;
965965
if (null !== $this->targetDirRegex) {
966-
$dir = $this->asFiles ? '$this->targetDirs[0] = \\dirname(__DIR__)' : '__DIR__';
966+
$dir = $this->asFiles ? '$this->targetDirs[0] = \\dirname($containerDir)' : '__DIR__';
967967
$code .= <<<EOF
968968
\$dir = {$dir};
969969
for (\$i = 1; \$i <= {$this->targetDirMaxMatches}; ++\$i) {
@@ -973,9 +973,10 @@ public function __construct()
973973
EOF;
974974
}
975975
if ($this->asFiles) {
976-
$code = str_replace('$parameters', "\$buildParameters;\n private \$parameters", $code);
977-
$code = str_replace('__construct()', '__construct(array $buildParameters = array())', $code);
976+
$code = str_replace('$parameters', "\$buildParameters;\n private \$containerDir;\n private \$parameters", $code);
977+
$code = str_replace('__construct()', '__construct(array $buildParameters = array(), $containerDir = __DIR__)', $code);
978978
$code .= " \$this->buildParameters = \$buildParameters;\n";
979+
$code .= " \$this->containerDir = \$containerDir;\n";
979980
}
980981

981982
if ($this->container->isCompiled()) {
@@ -1042,7 +1043,7 @@ public function isFrozen()
10421043
10431044
protected function load(\$file, \$lazyLoad = true)
10441045
{
1045-
return require \$file;
1046+
return require \$this->containerDir.\\DIRECTORY_SEPARATOR.\$file;
10461047
}
10471048
10481049
EOF;
@@ -1054,7 +1055,7 @@ protected function load(\$file, \$lazyLoad = true)
10541055
continue;
10551056
}
10561057
if ($this->asFiles) {
1057-
$proxyLoader = '$this->load(__DIR__."/{$class}.php")';
1058+
$proxyLoader = '$this->load("{$class}.php")';
10581059
} elseif ($this->namespace) {
10591060
$proxyLoader = 'class_alias("'.$this->namespace.'\\\\{$class}", $class, false)';
10601061
} else {
@@ -1126,7 +1127,7 @@ private function addRemovedIds()
11261127
return '';
11271128
}
11281129
if ($this->asFiles) {
1129-
$code = "require __DIR__.'/removed-ids.php'";
1130+
$code = "require \$this->containerDir.\\DIRECTORY_SEPARATOR.'removed-ids.php'";
11301131
} else {
11311132
$code = '';
11321133
$ids = array_keys($ids);
@@ -1179,7 +1180,7 @@ private function addFileMap()
11791180
ksort($definitions);
11801181
foreach ($definitions as $id => $definition) {
11811182
if (!$definition->isSynthetic() && $definition->isShared() && !$this->isHotPath($definition)) {
1182-
$code .= sprintf(" %s => __DIR__.'/%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
1183+
$code .= sprintf(" %s => '%s.php',\n", $this->doExport($id), $this->generateMethodName($id));
11831184
}
11841185
}
11851186

@@ -1901,7 +1902,7 @@ private function getServiceCall($id, Reference $reference = null)
19011902
$code = sprintf('$this->services[\'%s\'] = %s', $id, $code);
19021903
}
19031904
} elseif ($this->asFiles && $definition->isShared() && !$this->isHotPath($definition)) {
1904-
$code = sprintf("\$this->load(__DIR__.'/%s.php')", $this->generateMethodName($id));
1905+
$code = sprintf("\$this->load('%s.php')", $this->generateMethodName($id));
19051906
} else {
19061907
$code = sprintf('$this->%s()', $this->generateMethodName($id));
19071908
}
@@ -2043,7 +2044,7 @@ private function export($value)
20432044
$prefix = $matches[0][1] ? $this->doExport(substr($value, 0, $matches[0][1]), true).'.' : '';
20442045
$suffix = $matches[0][1] + strlen($matches[0][0]);
20452046
$suffix = isset($value[$suffix]) ? '.'.$this->doExport(substr($value, $suffix), true) : '';
2046-
$dirname = '__DIR__';
2047+
$dirname = $this->asFiles ? '$this->containerDir' : '__DIR__';
20472048
$offset = 1 + $this->targetDirMaxMatches - count($matches);
20482049

20492050
if ($this->asFiles || 0 < $offset) {

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_as_files.txt
+39-37Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
2424

2525
$this->services['baz'] = $instance = new \Baz();
2626

27-
$instance->setFoo(${($_ = isset($this->services['foo_with_inline']) ? $this->services['foo_with_inline'] : $this->load(__DIR__.'/getFooWithInlineService.php')) && false ?: '_'});
27+
$instance->setFoo(${($_ = isset($this->services['foo_with_inline']) ? $this->services['foo_with_inline'] : $this->load('getFooWithInlineService.php')) && false ?: '_'});
2828

2929
return $instance;
3030

@@ -38,7 +38,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
3838
$this->services['configured_service'] = $instance = new \stdClass();
3939

4040
$a = new \ConfClass();
41-
$a->setFoo(${($_ = isset($this->services['baz']) ? $this->services['baz'] : $this->load(__DIR__.'/getBazService.php')) && false ?: '_'});
41+
$a->setFoo(${($_ = isset($this->services['baz']) ? $this->services['baz'] : $this->load('getBazService.php')) && false ?: '_'});
4242

4343
$a->configureStdClass($instance);
4444

@@ -93,7 +93,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
9393
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
9494
// Returns the public 'factory_service' shared service.
9595

96-
return $this->services['factory_service'] = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'}->getInstance();
96+
return $this->services['factory_service'] = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'}->getInstance();
9797

9898
[Container%s/getFactoryServiceSimpleService.php] => <?php
9999

@@ -102,7 +102,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
102102
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
103103
// Returns the public 'factory_service_simple' shared service.
104104

105-
return $this->services['factory_service_simple'] = ${($_ = isset($this->services['factory_simple']) ? $this->services['factory_simple'] : $this->load(__DIR__.'/getFactorySimpleService.php')) && false ?: '_'}->getInstance();
105+
return $this->services['factory_service_simple'] = ${($_ = isset($this->services['factory_simple']) ? $this->services['factory_simple'] : $this->load('getFactorySimpleService.php')) && false ?: '_'}->getInstance();
106106

107107
[Container%s/getFactorySimpleService.php] => <?php
108108

@@ -122,7 +122,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
122122
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
123123
// Returns the public 'foo' shared service.
124124

125-
$a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'};
125+
$a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'};
126126

127127
$this->services['foo'] = $instance = \Bar\FooClass::getInstance('foo', $a, array('bar' => 'foo is bar', 'foobar' => 'bar'), true, $this);
128128

@@ -160,7 +160,7 @@ $this->services['foo_with_inline'] = $instance = new \Foo();
160160
$a = new \Bar();
161161

162162
$a->pub = 'pub';
163-
$a->setBaz(${($_ = isset($this->services['baz']) ? $this->services['baz'] : $this->load(__DIR__.'/getBazService.php')) && false ?: '_'});
163+
$a->setBaz(${($_ = isset($this->services['baz']) ? $this->services['baz'] : $this->load('getBazService.php')) && false ?: '_'});
164164

165165
$instance->setBar($a);
166166

@@ -174,7 +174,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
174174
// Returns the public 'lazy_context' shared service.
175175

176176
return $this->services['lazy_context'] = new \LazyContext(new RewindableGenerator(function () {
177-
yield 'k1' => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'};
177+
yield 'k1' => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'};
178178
yield 'k2' => $this;
179179
}, 2), new RewindableGenerator(function () {
180180
return new \EmptyIterator();
@@ -188,7 +188,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
188188
// Returns the public 'lazy_context_ignore_invalid_ref' shared service.
189189

190190
return $this->services['lazy_context_ignore_invalid_ref'] = new \LazyContext(new RewindableGenerator(function () {
191-
yield 0 => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'};
191+
yield 0 => ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'};
192192
}, 1), new RewindableGenerator(function () {
193193
return new \EmptyIterator();
194194
}, 0));
@@ -204,9 +204,9 @@ include_once ($this->targetDirs[0].'/Fixtures/includes/foo.php');
204204

205205
$this->services['method_call1'] = $instance = new \Bar\FooClass();
206206

207-
$instance->setBar(${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load(__DIR__.'/getFooService.php')) && false ?: '_'});
207+
$instance->setBar(${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load('getFooService.php')) && false ?: '_'});
208208
$instance->setBar(NULL);
209-
$instance->setBar((${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load(__DIR__.'/getFooService.php')) && false ?: '_'}->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
209+
$instance->setBar((${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load('getFooService.php')) && false ?: '_'}->foo() . (($this->hasParameter("foo")) ? ($this->getParameter("foo")) : ("default"))));
210210

211211
return $instance;
212212

@@ -243,7 +243,7 @@ use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
243243
// Returns the public 'tagged_iterator' shared service.
244244

245245
return $this->services['tagged_iterator'] = new \Bar(new RewindableGenerator(function () {
246-
yield 0 => ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load(__DIR__.'/getFooService.php')) && false ?: '_'};
246+
yield 0 => ${($_ = isset($this->services['foo']) ? $this->services['foo'] : $this->load('getFooService.php')) && false ?: '_'};
247247
yield 1 => ${($_ = isset($this->services['tagged_iterator_foo']) ? $this->services['tagged_iterator_foo'] : $this->services['tagged_iterator_foo'] = new \Bar()) && false ?: '_'};
248248
}, 2));
249249

@@ -277,16 +277,18 @@ use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
277277
class ProjectServiceContainer extends Container
278278
{
279279
private $buildParameters;
280+
private $containerDir;
280281
private $parameters;
281282
private $targetDirs = array();
282283

283-
public function __construct(array $buildParameters = array())
284+
public function __construct(array $buildParameters = array(), $containerDir = __DIR__)
284285
{
285-
$dir = $this->targetDirs[0] = \dirname(__DIR__);
286+
$dir = $this->targetDirs[0] = \dirname($containerDir);
286287
for ($i = 1; $i <= 5; ++$i) {
287288
$this->targetDirs[$i] = $dir = \dirname($dir);
288289
}
289290
$this->buildParameters = $buildParameters;
291+
$this->containerDir = $containerDir;
290292
$this->parameters = $this->getDefaultParameters();
291293

292294
$this->services = array();
@@ -298,25 +300,25 @@ class ProjectServiceContainer extends Container
298300
'foo_bar' => 'getFooBarService',
299301
);
300302
$this->fileMap = array(
301-
'baz' => __DIR__.'/getBazService.php',
302-
'configured_service' => __DIR__.'/getConfiguredServiceService.php',
303-
'configured_service_simple' => __DIR__.'/getConfiguredServiceSimpleService.php',
304-
'decorator_service' => __DIR__.'/getDecoratorServiceService.php',
305-
'decorator_service_with_name' => __DIR__.'/getDecoratorServiceWithNameService.php',
306-
'deprecated_service' => __DIR__.'/getDeprecatedServiceService.php',
307-
'factory_service' => __DIR__.'/getFactoryServiceService.php',
308-
'factory_service_simple' => __DIR__.'/getFactoryServiceSimpleService.php',
309-
'factory_simple' => __DIR__.'/getFactorySimpleService.php',
310-
'foo' => __DIR__.'/getFooService.php',
311-
'foo.baz' => __DIR__.'/getFoo_BazService.php',
312-
'foo_with_inline' => __DIR__.'/getFooWithInlineService.php',
313-
'lazy_context' => __DIR__.'/getLazyContextService.php',
314-
'lazy_context_ignore_invalid_ref' => __DIR__.'/getLazyContextIgnoreInvalidRefService.php',
315-
'method_call1' => __DIR__.'/getMethodCall1Service.php',
316-
'new_factory_service' => __DIR__.'/getNewFactoryServiceService.php',
317-
'service_from_static_method' => __DIR__.'/getServiceFromStaticMethodService.php',
318-
'tagged_iterator' => __DIR__.'/getTaggedIteratorService.php',
319-
'tagged_iterator_foo' => __DIR__.'/getTaggedIteratorFooService.php',
303+
'baz' => 'getBazService.php',
304+
'configured_service' => 'getConfiguredServiceService.php',
305+
'configured_service_simple' => 'getConfiguredServiceSimpleService.php',
306+
'decorator_service' => 'getDecoratorServiceService.php',
307+
'decorator_service_with_name' => 'getDecoratorServiceWithNameService.php',
308+
'deprecated_service' => 'getDeprecatedServiceService.php',
309+
'factory_service' => 'getFactoryServiceService.php',
310+
'factory_service_simple' => 'getFactoryServiceSimpleService.php',
311+
'factory_simple' => 'getFactorySimpleService.php',
312+
'foo' => 'getFooService.php',
313+
'foo.baz' => 'getFoo_BazService.php',
314+
'foo_with_inline' => 'getFooWithInlineService.php',
315+
'lazy_context' => 'getLazyContextService.php',
316+
'lazy_context_ignore_invalid_ref' => 'getLazyContextIgnoreInvalidRefService.php',
317+
'method_call1' => 'getMethodCall1Service.php',
318+
'new_factory_service' => 'getNewFactoryServiceService.php',
319+
'service_from_static_method' => 'getServiceFromStaticMethodService.php',
320+
'tagged_iterator' => 'getTaggedIteratorService.php',
321+
'tagged_iterator_foo' => 'getTaggedIteratorFooService.php',
320322
);
321323
$this->privates = array(
322324
'factory_simple' => true,
@@ -331,7 +333,7 @@ class ProjectServiceContainer extends Container
331333

332334
public function getRemovedIds()
333335
{
334-
return require __DIR__.'/removed-ids.php';
336+
return require $this->containerDir.\DIRECTORY_SEPARATOR.'removed-ids.php';
335337
}
336338

337339
public function compile()
@@ -353,7 +355,7 @@ class ProjectServiceContainer extends Container
353355

354356
protected function load($file, $lazyLoad = true)
355357
{
356-
return require $file;
358+
return require $this->containerDir.\DIRECTORY_SEPARATOR.$file;
357359
}
358360

359361
/**
@@ -363,7 +365,7 @@ class ProjectServiceContainer extends Container
363365
*/
364366
protected function getBarService()
365367
{
366-
$a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load(__DIR__.'/getFoo_BazService.php')) && false ?: '_'};
368+
$a = ${($_ = isset($this->services['foo.baz']) ? $this->services['foo.baz'] : $this->load('getFoo_BazService.php')) && false ?: '_'};
367369

368370
$this->services['bar'] = $instance = new \Bar\FooClass('foo', $a, $this->getParameter('foo_bar'));
369371

@@ -379,7 +381,7 @@ class ProjectServiceContainer extends Container
379381
*/
380382
protected function getFooBarService()
381383
{
382-
return new \Bar\FooClass(${($_ = isset($this->services['deprecated_service']) ? $this->services['deprecated_service'] : $this->load(__DIR__.'/getDeprecatedServiceService.php')) && false ?: '_'});
384+
return new \Bar\FooClass(${($_ = isset($this->services['deprecated_service']) ? $this->services['deprecated_service'] : $this->load('getDeprecatedServiceService.php')) && false ?: '_'});
383385
}
384386

385387
public function getParameter($name)
@@ -502,6 +504,6 @@ return new \Container%s\ProjectServiceContainer(array(
502504
'container.build_hash' => '%s',
503505
'container.build_id' => '%s',
504506
'container.build_time' => %d,
505-
));
507+
), __DIR__.\DIRECTORY_SEPARATOR.'Container%s');
506508

507509
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.