Skip to content

Commit 57d6053

Browse files
bug #18893 [DependencyInjection] Skip deep reference check for 'service_container' (RobertMe)
This PR was merged into the 2.3 branch. Discussion ---------- [DependencyInjection] Skip deep reference check for 'service_container' | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | The "hasReference" check when dumping the container fails in the case where a service has a method call which includes a reference to a private/inlined service when either that service, or a dependency of it, references the service_container. This because service_container isn't defined while it still tries to check the references of it. So the service_container must be skipped in this case, this shouldn't break anything as the service_container doesn't reference any services, and thus can't reference the service which it is checking for. Commits ------- 6f36733 [DependencyInjection] Skip deep reference check for 'service_container'
2 parents b3cd267 + 6f36733 commit 57d6053

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,15 @@ public function testCircularReference()
226226
$dumper = new PhpDumper($container);
227227
$dumper->dump();
228228
}
229+
230+
public function testInlinedDefinitionReferencingServiceContainer()
231+
{
232+
$container = new ContainerBuilder();
233+
$container->register('foo', 'stdClass')->addMethodCall('add', array(new Reference('service_container')))->setPublic(false);
234+
$container->register('bar', 'stdClass')->addArgument(new Reference('foo'));
235+
$container->compile();
236+
237+
$dumper = new PhpDumper($container);
238+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services13.php', $dumper->dump(), '->dump() dumps inline definitions which reference service_container');
239+
}
229240
}
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy