File tree Expand file tree Collapse file tree 8 files changed +32
-22
lines changed
src/Symfony/Component/DependencyInjection Expand file tree Collapse file tree 8 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,7 @@ public function __construct()
63
63
new RemoveUnusedDefinitionsPass (),
64
64
)),
65
65
new CheckExceptionOnInvalidReferenceBehaviorPass (),
66
+ new CheckCircularReferencesPass (),
66
67
);
67
68
}
68
69
Original file line number Diff line number Diff line change @@ -113,4 +113,30 @@ public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDe
113
113
$ this ->assertFalse ($ container ->hasDefinition ('b ' ));
114
114
$ this ->assertFalse ($ container ->hasDefinition ('c ' ), 'Service C was not inlined. ' );
115
115
}
116
+
117
+ /**
118
+ * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException
119
+ */
120
+ public function testCircularReferencesCausedByMethodCallsAreDetectedDuringCompilation ()
121
+ {
122
+ $ container = new ContainerBuilder ();
123
+ $ container ->setResourceTracking (false );
124
+
125
+ $ container
126
+ ->register ('foobar ' , '\stdClass ' )
127
+ ->addArgument (new Reference ('foo ' ))
128
+ ;
129
+
130
+ $ container
131
+ ->register ('foo ' , '\stdClass ' )
132
+ ->addArgument (new Reference ('bar ' ))
133
+ ;
134
+
135
+ $ container
136
+ ->register ('bar ' , '\stdClass ' )
137
+ ->addMethodCall ('addFoobar ' , array (new Reference ('foobar ' )))
138
+ ;
139
+
140
+ $ container ->compile ();
141
+ }
116
142
}
Original file line number Diff line number Diff line change 64
64
;
65
65
$ container
66
66
->register ('baz ' , 'Baz ' )
67
- ->addMethodCall ('setFoo ' , array (new Reference ('foo_with_inline ' )))
68
67
;
69
68
$ container
70
69
->register ('request ' , 'Request ' )
Original file line number Diff line number Diff line change @@ -36,6 +36,5 @@ digraph sc {
36
36
node_method_call1 -> node_foobaz [label =" setBar()" style =" dashed" ];
37
37
node_foo_with_inline -> node_inlined [label =" setBar()" style =" dashed" ];
38
38
node_inlined -> node_baz [label =" setBaz()" style =" dashed" ];
39
- node_baz -> node_foo_with_inline [label =" setFoo()" style =" dashed" ];
40
39
node_configurator_service -> node_baz [label =" setFoo()" style =" dashed" ];
41
40
}
Original file line number Diff line number Diff line change @@ -80,11 +80,7 @@ protected function getBarService()
80
80
*/
81
81
protected function getBazService ()
82
82
{
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 ();
88
84
}
89
85
90
86
/**
Original file line number Diff line number Diff line change @@ -99,11 +99,7 @@ protected function getBarService()
99
99
*/
100
100
protected function getBazService ()
101
101
{
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 ();
107
103
}
108
104
109
105
/**
@@ -227,12 +223,11 @@ protected function getFooBarService()
227
223
protected function getFooWithInlineService ()
228
224
{
229
225
$ a = new \Bar ();
230
-
231
- $ this ->services ['foo_with_inline ' ] = $ instance = new \Foo ();
232
-
233
226
$ a ->pub = 'pub ' ;
234
227
$ a ->setBaz ($ this ->get ('baz ' ));
235
228
229
+ $ this ->services ['foo_with_inline ' ] = $ instance = new \Foo ();
230
+
236
231
$ instance ->setBar ($ a );
237
232
238
233
return $ instance ;
Original file line number Diff line number Diff line change 70
70
<argument type =" service" id =" baz" />
71
71
</call >
72
72
</service >
73
- <service id =" baz" class =" Baz" >
74
- <call method =" setFoo" >
75
- <argument type =" service" id =" foo_with_inline" />
76
- </call >
77
- </service >
73
+ <service id =" baz" class =" Baz" />
78
74
<service id =" request" class =" Request" synthetic =" true" />
79
75
<service id =" configurator_service" class =" ConfClass" public =" false" >
80
76
<call method =" setFoo" >
Original file line number Diff line number Diff line change @@ -52,8 +52,6 @@ services:
52
52
53
53
baz :
54
54
class : Baz
55
- calls :
56
- - [setFoo, ['@foo_with_inline']]
57
55
58
56
request :
59
57
class : Request
You can’t perform that action at this time.
0 commit comments