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

Commitab1ba1d

Browse files
committed
check for circular refs caused by method calls
1 parent68d6415 commitab1ba1d

File tree

8 files changed

+32
-22
lines changed

8 files changed

+32
-22
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function __construct()
6363
newRemoveUnusedDefinitionsPass(),
6464
)),
6565
newCheckExceptionOnInvalidReferenceBehaviorPass(),
66+
newCheckCircularReferencesPass(),
6667
);
6768
}
6869

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,30 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe
113113
$this->assertFalse($container->hasDefinition('b'));
114114
$this->assertFalse($container->hasDefinition('c'),'Service C was not inlined.');
115115
}
116+
117+
/**
118+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
119+
*/
120+
publicfunctiontestCircularReferencesCausedByMethodCallsAreDetectedDuringCompilation()
121+
{
122+
$container =newContainerBuilder();
123+
$container->setResourceTracking(false);
124+
125+
$container
126+
->register('foobar','\stdClass')
127+
->addArgument(newReference('foo'))
128+
;
129+
130+
$container
131+
->register('foo','\stdClass')
132+
->addArgument(newReference('bar'))
133+
;
134+
135+
$container
136+
->register('bar','\stdClass')
137+
->addMethodCall('addFoobar',array(newReference('foobar')))
138+
;
139+
140+
$container->compile();
141+
}
116142
}

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
;
6565
$container
6666
->register('baz','Baz')
67-
->addMethodCall('setFoo',array(newReference('foo_with_inline')))
6867
;
6968
$container
7069
->register('request','Request')

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/graphviz/services9.dot‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@ digraph sc {
3636
node_method_call1-> node_foobaz [label="setBar()"style="dashed"];
3737
node_foo_with_inline-> node_inlined [label="setBar()"style="dashed"];
3838
node_inlined-> node_baz [label="setBaz()"style="dashed"];
39-
node_baz-> node_foo_with_inline [label="setFoo()"style="dashed"];
4039
node_configurator_service-> node_baz [label="setFoo()"style="dashed"];
4140
}

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,7 @@ protected function getBarService()
8080
*/
8181
protectedfunctiongetBazService()
8282
{
83-
$this->services['baz'] =$instance =new \Baz();
84-
85-
$instance->setFoo($this->get('foo_with_inline'));
86-
87-
return$instance;
83+
return$this->services['baz'] =new \Baz();
8884
}
8985

9086
/**

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9_compiled.php‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ protected function getBarService()
9999
*/
100100
protectedfunctiongetBazService()
101101
{
102-
$this->services['baz'] =$instance =new \Baz();
103-
104-
$instance->setFoo($this->get('foo_with_inline'));
105-
106-
return$instance;
102+
return$this->services['baz'] =new \Baz();
107103
}
108104

109105
/**
@@ -227,12 +223,11 @@ protected function getFooBarService()
227223
protectedfunctiongetFooWithInlineService()
228224
{
229225
$a =new \Bar();
230-
231-
$this->services['foo_with_inline'] =$instance =new \Foo();
232-
233226
$a->pub ='pub';
234227
$a->setBaz($this->get('baz'));
235228

229+
$this->services['foo_with_inline'] =$instance =new \Foo();
230+
236231
$instance->setBar($a);
237232

238233
return$instance;

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@
7070
<argumenttype="service"id="baz"/>
7171
</call>
7272
</service>
73-
<serviceid="baz"class="Baz">
74-
<callmethod="setFoo">
75-
<argumenttype="service"id="foo_with_inline"/>
76-
</call>
77-
</service>
73+
<serviceid="baz"class="Baz"/>
7874
<serviceid="request"class="Request"synthetic="true"/>
7975
<serviceid="configurator_service"class="ConfClass"public="false">
8076
<callmethod="setFoo">

‎src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ services:
5252

5353
baz:
5454
class:Baz
55-
calls:
56-
-[setFoo, ['@foo_with_inline']]
5755

5856
request:
5957
class:Request

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp