[DependencyInjection] fixed PhpDumper when an inlined service definition has some properties
This commit is contained in:
parent
e939a4236c
commit
cd153901ea
@ -415,16 +415,14 @@ class PhpDumper extends Dumper
|
|||||||
}
|
}
|
||||||
$processed->offsetSet($iDefinition);
|
$processed->offsetSet($iDefinition);
|
||||||
|
|
||||||
if (!$this->hasReference($id, $iDefinition->getMethodCalls())) {
|
if (!$this->hasReference($id, $iDefinition->getMethodCalls()) && !$this->hasReference($id, $iDefinition->getProperties())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($iDefinition->getMethodCalls()) {
|
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
|
||||||
$code .= $this->addServiceMethodCalls(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
|
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
|
||||||
}
|
$code .= $this->addServiceProperties(null, $iDefinition, $name);
|
||||||
if ($iDefinition->getConfigurator()) {
|
$code .= $this->addServiceConfigurator(null, $iDefinition, $name);
|
||||||
$code .= $this->addServiceConfigurator(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('' !== $code) {
|
if ('' !== $code) {
|
||||||
|
@ -57,4 +57,15 @@ $container->
|
|||||||
setFactoryMethod('getInstance')
|
setFactoryMethod('getInstance')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
$container
|
||||||
|
->register('foo_with_inline', 'Foo')
|
||||||
|
->addMethodCall('setBar', array(new Reference('inlined')))
|
||||||
|
;
|
||||||
|
$container
|
||||||
|
->register('inlined', 'Bar')
|
||||||
|
->setProperty('pub', 'pub')
|
||||||
|
->addMethodCall('setFoo', array(new Reference('foo_with_inline')))
|
||||||
|
->setPublic(false)
|
||||||
|
;
|
||||||
|
|
||||||
return $container;
|
return $container;
|
||||||
|
@ -9,6 +9,8 @@ digraph sc {
|
|||||||
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"];
|
node_foo_bar [label="foo_bar\nFooClass\n", shape=record, fillcolor="#eeeeee", style="dotted"];
|
||||||
node_method_call1 [label="method_call1\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
node_method_call1 [label="method_call1\nFooClass\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
node_factory_service [label="factory_service\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
|
node_foo_with_inline [label="foo_with_inline\nFoo\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
|
node_inlined [label="inlined\nBar\n", shape=record, fillcolor="#eeeeee", style="filled"];
|
||||||
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
node_service_container [label="service_container\nSymfony\\Component\\DependencyInjection\\ContainerBuilder\n", shape=record, fillcolor="#9999ff", style="filled"];
|
||||||
node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
|
node_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
|
||||||
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];
|
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];
|
||||||
@ -22,4 +24,6 @@ digraph sc {
|
|||||||
node_method_call1 -> node_foo2 [label="setBar()" style="dashed"];
|
node_method_call1 -> node_foo2 [label="setBar()" style="dashed"];
|
||||||
node_method_call1 -> node_foo3 [label="setBar()" style="dashed"];
|
node_method_call1 -> node_foo3 [label="setBar()" style="dashed"];
|
||||||
node_method_call1 -> node_foobaz [label="setBar()" style="dashed"];
|
node_method_call1 -> node_foobaz [label="setBar()" style="dashed"];
|
||||||
|
node_foo_with_inline -> node_inlined [label="setBar()" style="dashed"];
|
||||||
|
node_inlined -> node_foo_with_inline [label="setFoo()" style="dashed"];
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,23 @@ class ProjectServiceContainer extends Container
|
|||||||
return new $class();
|
return new $class();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the 'foo_with_inline' service.
|
||||||
|
*
|
||||||
|
* This service is shared.
|
||||||
|
* This method always returns the same instance of the service.
|
||||||
|
*
|
||||||
|
* @return Foo A Foo instance.
|
||||||
|
*/
|
||||||
|
protected function getFooWithInlineService()
|
||||||
|
{
|
||||||
|
$this->services['foo_with_inline'] = $instance = new \Foo();
|
||||||
|
|
||||||
|
$instance->setBar($this->get('inlined'));
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the 'method_call1' service.
|
* Gets the 'method_call1' service.
|
||||||
*
|
*
|
||||||
@ -140,6 +157,28 @@ class ProjectServiceContainer extends Container
|
|||||||
return $this->get('foo');
|
return $this->get('foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the 'inlined' service.
|
||||||
|
*
|
||||||
|
* This service is shared.
|
||||||
|
* This method always returns the same instance of the service.
|
||||||
|
*
|
||||||
|
* This service is private.
|
||||||
|
* If you want to be able to request this service from the container directly,
|
||||||
|
* make it public, otherwise you might end up with broken code.
|
||||||
|
*
|
||||||
|
* @return Bar A Bar instance.
|
||||||
|
*/
|
||||||
|
protected function getInlinedService()
|
||||||
|
{
|
||||||
|
$this->services['inlined'] = $instance = new \Bar();
|
||||||
|
|
||||||
|
$instance->setFoo($this->get('foo_with_inline'));
|
||||||
|
$instance->pub = 'pub';
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the default parameters.
|
* Gets the default parameters.
|
||||||
*
|
*
|
||||||
|
@ -112,6 +112,28 @@ class ProjectServiceContainer extends Container
|
|||||||
return new \FooClass();
|
return new \FooClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the 'foo_with_inline' service.
|
||||||
|
*
|
||||||
|
* This service is shared.
|
||||||
|
* This method always returns the same instance of the service.
|
||||||
|
*
|
||||||
|
* @return Foo A Foo instance.
|
||||||
|
*/
|
||||||
|
protected function getFooWithInlineService()
|
||||||
|
{
|
||||||
|
$a = new \Bar();
|
||||||
|
|
||||||
|
$this->services['foo_with_inline'] = $instance = new \Foo();
|
||||||
|
|
||||||
|
$a->setFoo($instance);
|
||||||
|
$a->pub = 'pub';
|
||||||
|
|
||||||
|
$instance->setBar($a);
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the 'method_call1' service.
|
* Gets the 'method_call1' service.
|
||||||
*
|
*
|
||||||
|
@ -51,6 +51,17 @@
|
|||||||
</call>
|
</call>
|
||||||
</service>
|
</service>
|
||||||
<service id="factory_service" class="Bar" factory-method="getInstance" factory-service="foo.baz"/>
|
<service id="factory_service" class="Bar" factory-method="getInstance" factory-service="foo.baz"/>
|
||||||
|
<service id="foo_with_inline" class="Foo">
|
||||||
|
<call method="setBar">
|
||||||
|
<argument type="service" id="inlined"/>
|
||||||
|
</call>
|
||||||
|
</service>
|
||||||
|
<service id="inlined" class="Bar" public="false">
|
||||||
|
<property name="pub">pub</property>
|
||||||
|
<call method="setFoo">
|
||||||
|
<argument type="service" id="foo_with_inline"/>
|
||||||
|
</call>
|
||||||
|
</service>
|
||||||
<service id="alias_for_foo" alias="foo"/>
|
<service id="alias_for_foo" alias="foo"/>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -41,4 +41,15 @@ services:
|
|||||||
class: Bar
|
class: Bar
|
||||||
factory_method: getInstance
|
factory_method: getInstance
|
||||||
factory_service: foo.baz
|
factory_service: foo.baz
|
||||||
|
foo_with_inline:
|
||||||
|
class: Foo
|
||||||
|
calls:
|
||||||
|
- [setBar, ['@inlined']]
|
||||||
|
|
||||||
|
inlined:
|
||||||
|
class: Bar
|
||||||
|
properties: { pub: pub }
|
||||||
|
calls:
|
||||||
|
- [setFoo, ['@foo_with_inline']]
|
||||||
|
|
||||||
alias_for_foo: @foo
|
alias_for_foo: @foo
|
||||||
|
Reference in New Issue
Block a user