8000 [DependencyInjection] fixed PhpDumper when an inlined service definit… · klend/symfony@cd15390 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd15390

Browse files
committed
[DependencyInjection] fixed PhpDumper when an inlined service definition has some properties
1 parent e939a42 commit cd15390

File tree

7 files changed

+103
-7
lines changed

7 files changed

+103
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,16 +415,14 @@ private function addServiceInlinedDefinitionsSetup($id, $definition)
415415
}
416416
$processed->offsetSet($iDefinition);
417417

418-
if (!$this->hasReference($id, $iDefinition->getMethodCalls())) {
418+
if (!$this->hasReference($id, $iDefinition->getMethodCalls()) && !$this->hasReference($id, $iDefinition->getProperties())) {
419419
continue;
420420
}
421421

422-
if ($iDefinition->getMethodCalls()) {
423-
$code .= $this->addServiceMethodCalls(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
424-
}
425-
if ($iDefinition->getConfigurator()) {
426-
$code .= $this->addServiceConfigurator(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
427-
}
422+
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
423+
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
424+
$code .= $this->addServiceProperties(null, $iDefinition, $name);
425+
$code .= $this->addServiceConfigurator(null, $iDefinition, $name);
428426
}
429427

430428
if ('' !== $code) {

tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,15 @@
5757
setFactoryMethod('getInstance')
5858
;
5959

60+
$container
61+
->register('foo_with_inline', 'Foo')
62+
->addMethodCall('setBar', array(new Reference('inlined')))
63+
;
64+
$container
65+
->register('inlined', 'Bar')
66+
->setProperty('pub', 'pub')
67+
->addMethodCall('setFoo', array(new Reference('foo_with_inline')))
68+
->setPublic(false)
69+
;
70+
6071
return $container;

tests/Symfony/Tests/Component/DependencyInjection/Fixtures/graphviz/services9.dot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ digraph sc {
99
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"];
1010
node_method_call1 [label="method_call1\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
1111
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
12+
node_foo_with_inline [label="foo_with_inline\nFoo\n", shape=record, fillcolor="#eeeeee", style="filled"];
13+
node_inlined [label="inlined\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
1214
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
1315
node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
1416
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];
@@ -22,4 +24,6 @@ digraph sc {
2224
node_method_call1 -> node_foo2 [label="setBar()" style="dashed"];
2325
node_method_call1 -> node_foo3 [label="setBar()" style="dashed"];
2426
node_method_call1 -> node_foobaz [label="setBar()" style="dashed"];
27+
node_foo_with_inline -> node_inlined [label="setBar()" style="dashed"];
28+
node_inlined -> node_foo_with_inline [label="setFoo()" style="dashed"];
2529
}

tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ protected function getFooBarService()
104104
return new $class();
105105
}
106106

107+
/**
108+
* Gets the 'foo_with_inline' service.
109+
*
110+
* This service is shared.
111+
* This method always returns the same instance of the service.
112+
*
113+
* @return Foo A Foo instance.
114+
*/
115+
protected function getFooWithInlineService()
116+
{
117+
$this->services['foo_with_inline'] = $instance = new \Foo();
118+
119+
$instance->setBar($this->get('inlined'));
120+
121+
return $instance;
122+
}
123+
107124
/**
108125
* Gets the 'method_call1' service.
109126
*
@@ -140,6 +157,28 @@ protected function getAliasForFooService()
140157
return $this->get('foo');
141158
}
142159

160+
/**
161+
* Gets the 'inlined' service.
162+
*
163+
* This service is shared.
164+
* This method always returns the same instance of the service.
165+
*
166+
* This service is private.
167+
* If you want to be able to request this service from the container directly,
168+
* make it public, otherwise you might end up with broken code.
169+
*
170+
* @return Bar A Bar instance.
171+
*/
172+
protected function getInlinedService()
173+
{
174+
$this->services['inlined'] = $instance = new \Bar();
175+
176+
$instance->setFoo($this->get('foo_with_inline'));
177+
$instance->pub = 'pub';
178+
179+
return $instance;
180+
}
181+
143182
/**
144183
* Gets the default parameters.
145184
*

tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9_compiled.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ protected function getFooBarService()
112112
return new \FooClass();
113113
}
114114

115+
/**
116+
* Gets the 'foo_with_inline' service.
117+
*
118+
* This service is shared.
119+
* This method always returns the same instance of the service.
120+
*
121+
* @return Foo A Foo instance.
122+
*/
123+
protected function getFooWithInlineService()
124+
{
125+
$a = new \Bar();
126+
127+
$this->services['foo_with_inline'] = $instance = new \Foo();
128+
129+
$a->setFoo($instance);
130+
$a->pub = 'pub';
131+
132+
$instance->setBar($a);
133+
134+
return $instance;
135+
}
136+
115137
/**
116138
* Gets the 'method_call1' service.
117139
*

tests/Symfony/Tests/Component/DependencyInjection/Fixtures/xml/services9.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@
5151
</call>
5252
</service>
5353
<service id="factory_service" class="Bar" factory-method="getInstance" factory-service="foo.baz"/>
54+
<service id="foo_with_inline" class="Foo">
55+
<call method="setBar">
56+
<argument type="service" id="inlined"/>
57+
</call>
58+
</service>
59+
<service id="inlined" class="Bar" public="false">
60+
<property name="pub">pub</property>
61+
<call method="setFoo">
62+
<argument type="service" id="foo_with_inline"/>
63+
</call>
64+
</service>
5465
<service id="alias_for_foo" alias="foo"/>
5566
</services>
5667
</container>

tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services9.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,15 @@ services:
4141
class: Bar
4242
factory_method: getInstance
4343
factory_service: foo.baz
44+
foo_with_inline:
45+
class: Foo
46+
calls:
47+
- [setBar, ['@inlined']]
48+
49+
inlined:
50+
class: Bar
51+
properties: { pub: pub }
52+
calls:
53+
- [setFoo, ['@foo_with_inline']]
54+
4455
alias_for_foo: @foo

0 commit comments

Comments
 (0)
0