8000 [DependencyInjection] Skip deep reference check for 'service_container' · symfony/symfony@d8e4a94 · GitHub
[go: up one dir, main page]

Skip to content

Commit d8e4a94

Browse files
[DependencyInjection] Skip deep reference check for 'service_container'
Deep checks on whether a service references another service need to exclude the 'service_container' service as it doesn't exist. Without this dumping the container will fail if a service definition references an inlined service which has a direct or indirect dependency to the service_container.
1 parent c59a3da commit d8e4a94

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ private function hasReference($id, array $arguments, $deep = false, &$visited =
11731173
return true;
11741174
}
11751175

1176-
if ($deep && !isset($visited[(string) $argument])) {
1176+
if ($deep && !isset($visited[(string) $argument]) && 'service_container' !== (string) $argument) {
11771177
$visited[(string) $argument] = true;
11781178

11791179
$service = $this->container->getDefinition((string) $argument);

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,14 @@ public function testCircularReference()
226226
$dumper = new PhpDumper($container);
227227
$dumper->dump();
228228
}
229+
230+
public function testInlinedDefinitionReferencingServiceContainer() {
231+
$container = new ContainerBuilder();
232+
$container->register('foo', 'stdClass')->addMethodCall('add', array(new Reference('service_container')))->setPublic(false);
233+
$container->register('bar', 'stdClass')->addArgument(new Reference('foo'));
234+
$container->compile();
235+
236+
$dumper = new PhpDumper($container);
237+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
238+
}
229239
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
use Symfony\Component\DependencyInjection\ContainerInterface;
4+
use Symfony\Component\DependencyInjection\Container;
5+
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
6+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
7+
use Symfony\Component\DependencyInjection\Exception\LogicException;
8+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
10+
11+
/**
12+
* ProjectServiceContainer.
13+
*
14+
* This class has been auto-generated
15+
* by the Symfony Dependency Injection Component.
16+
*/
17+
class ProjectServiceContainer extends Container
18+
{
19+
private $parameters;
20+
private $targetDirs = array();
21+
22+
/**
23+
* Constructor.
24+
*/
25+
public function __construct()
26+
{
27+
$this->services =
28+
$this->scopedServices =
29+
$this->scopeStacks = array();
30+
$this->scopes = array();
31+
$this->scopeChildren = array();
32+
$this->methodMap = array(
33+
'bar' => 'getBarService',
34+
);
35+
36+
$this->aliases = array();
37+
}
38+
39+
/**
40+
* Gets the 'bar' service.
41+
*
42+
* This service is shared.
43+
* This method always returns the same instance of the service.
44+
*
45+
* @return \stdClass A stdClass instance.
46+
*/
47+
protected function getBarService()
48+
{
49+
$a = new \stdClass();
50+
$a->add($this);
51+
52+
return $this->services['bar'] = new \stdClass($a);
53+
}
54+
}

0 commit comments

Comments
 (0)
0