Skip to content

Commit

Permalink
[DependencyInjection] fixed PhpDumper when an inlined service definit…
Browse files Browse the repository at this point in the history
…ion has some properties
  • Loading branch information
fabpot committed Jan 5, 2013
1 parent e939a42 commit cd15390
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php
Expand Up @@ -415,16 +415,14 @@ private function addServiceInlinedDefinitionsSetup($id, $definition)
}
$processed->offsetSet($iDefinition);

if (!$this->hasReference($id, $iDefinition->getMethodCalls())) {
if (!$this->hasReference($id, $iDefinition->getMethodCalls()) && !$this->hasReference($id, $iDefinition->getProperties())) {
continue;
}

if ($iDefinition->getMethodCalls()) {
$code .= $this->addServiceMethodCalls(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
}
if ($iDefinition->getConfigurator()) {
$code .= $this->addServiceConfigurator(null, $iDefinition, (string) $this->definitionVariables->offsetGet($iDefinition));
}
$name = (string) $this->definitionVariables->offsetGet($iDefinition);
$code .= $this->addServiceMethodCalls(null, $iDefinition, $name);
$code .= $this->addServiceProperties(null, $iDefinition, $name);
$code .= $this->addServiceConfigurator(null, $iDefinition, $name);
}

if ('' !== $code) {
Expand Down
Expand Up @@ -57,4 +57,15 @@
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;
Expand Up @@ -9,6 +9,8 @@ digraph sc {
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_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_foo2 [label="foo2\n\n", shape=record, fillcolor="#ff9999", style="filled"];
node_foo3 [label="foo3\n\n", shape=record, fillcolor="#ff9999", style="filled"];
Expand All @@ -22,4 +24,6 @@ digraph sc {
node_method_call1 -> node_foo2 [label="setBar()" style="dashed"];
node_method_call1 -> node_foo3 [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"];
}
Expand Up @@ -104,6 +104,23 @@ protected function getFooBarService()
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.
*
Expand Down Expand Up @@ -140,6 +157,28 @@ protected function getAliasForFooService()
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.
*
Expand Down
Expand Up @@ -112,6 +112,28 @@ protected function getFooBarService()
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.
*
Expand Down
Expand Up @@ -51,6 +51,17 @@
</call>
</service>
<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"/>
</services>
</container>
Expand Up @@ -41,4 +41,15 @@ services:
class: Bar
factory_method: getInstance
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

0 comments on commit cd15390

Please sign in to comment.