Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit30638f0

Browse files
[DependencyInjection] Skip deep reference check for 'service_container'
Deep checks on whether a service references another service need toexclude the 'service_container' service as it doesn't exist. Without thisdumping the container will fail if a service definition references aninlined service which has a direct or indirect dependency to theservice_container.
1 parentc59a3da commit30638f0

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
returntrue;
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 =newPhpDumper($container);
227227
$dumper->dump();
228228
}
229+
230+
publicfunctiontestInlinedDefinitionReferencingServiceContainer() {
231+
$container =newContainerBuilder();
232+
$container->register('foo','stdClass')->addMethodCall('add', [newReference('service_container')])->setPublic(false);
233+
$container->register('bar','stdClass')->addArgument(newReference('foo'));
234+
$container->compile();
235+
236+
$dumper =newPhpDumper($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+
useSymfony\Component\DependencyInjection\ContainerInterface;
4+
useSymfony\Component\DependencyInjection\Container;
5+
useSymfony\Component\DependencyInjection\Exception\InactiveScopeException;
6+
useSymfony\Component\DependencyInjection\Exception\InvalidArgumentException;
7+
useSymfony\Component\DependencyInjection\Exception\LogicException;
8+
useSymfony\Component\DependencyInjection\Exception\RuntimeException;
9+
useSymfony\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 ProjectServiceContainerextends Container
18+
{
19+
private$parameters;
20+
private$targetDirs =array();
21+
22+
/**
23+
* Constructor.
24+
*/
25+
publicfunction__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+
protectedfunctiongetBarService()
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)

[8]ページ先頭

©2009-2025 Movatter.jp