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 1cdb2bc

Browse filesBrowse files
committed
[DI] Prevent an ininite loop when using env vars in service names
1 parent fe07c25 commit 1cdb2bc
Copy full SHA for 1cdb2bc

File tree

Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-1
lines changed

‎src/Symfony/Component/DependencyInjection/Container.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Container.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,9 @@ protected function getEnv($name)
469469
return $this->envCache[$name];
470470
}
471471
if (!$this->has($id = 'container.env_var_processors_locator')) {
472-
$this->set($id, new ServiceLocator(array()));
472+
// We don't call set() to prevent an infinite loop:
473+
// set() calls getRemovedIds(), getRemovedIds() calls getEnv() in some cases
474+
$this->services[$id] = new ServiceLocator(array());
473475
}
474476
if (!$this->getEnv) {
475477
$this->getEnv = new \ReflectionMethod($this, __FUNCTION__);

‎src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/ContainerTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,23 @@ public function testReplacingAPreDefinedServiceIsDeprecated()
538538

539539
$this->assertSame($bar, $c->get('bar'), '->set() replaces a pre-defined service');
540540
}
541+
542+
public function testNoInfiniteLoopInGetEnv()
543+
{
544+
$_ENV['bar'] = 'hello';
545+
$this->assertCount(1, (new RemovedIdsCallGetEnvContainer())->getRemovedIds());
546+
unset($_ENV['bar']);
547+
}
548+
}
549+
550+
class RemovedIdsCallGetEnvContainer extends Container
551+
{
552+
public function getRemovedIds()
553+
{
554+
return array(
555+
'foo.'.$this->getEnv('bar') => true,
556+
);
557+
}
541558
}
542559

543560
class ProjectServiceContainer extends Container

0 commit comments

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