Skip to content

Commit fb95bdc

Browse files
committed
[DIC] Fix service autowiring inheritance
Update Changelog
1 parent 609ee2d commit fb95bdc

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
136136
$def->setFile($parentDef->getFile());
137137
$def->setPublic($parentDef->isPublic());
138138
$def->setLazy($parentDef->isLazy());
139+
$def->setAutowired($parentDef->isAutowired());
139140

140141
// overwrite with values specified in the decorator
141142
$changes = $definition->getChanges();
@@ -169,6 +170,9 @@ private function resolveDefinition(ContainerBuilder $container, DefinitionDecora
169170
if (isset($changes['deprecated'])) {
170171
$def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
171172
}
173+
if (isset($changes['autowire'])) {
174+
$def->setAutowired($definition->isAutowired());
175+
}
172176
if (isset($changes['decorated_service'])) {
173177
$decoratedService = $definition->getDecoratedService();
174178
if (null === $decoratedService) {

src/Symfony/Component/DependencyInjection/DefinitionDecorator.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ public function setDeprecated($boolean = true, $template = null)
164164
return parent::setDeprecated($boolean, $template);
165165
}
166166

167+
/**
168+
* {@inheritdoc}
169+
*/
170+
public function setAutowired($autowired)
171+
{
172+
$this->changes['autowire'] = true;
173+
174+
return parent::setAutowired($autowired);
175+
}
176+
167177
/**
168178
* Gets an argument to pass to the service constructor/factory method.
169179
*

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,36 @@ public function testSetLazyOnServiceIsParent()
233233
$this->assertTrue($container->getDefinition('child1')->isLazy());
234234
}
235235

236+
public function testSetAutowiredOnServiceHasParent()
237+
{
238+
$container = new ContainerBuilder();
239+
240+
$container->register('parent', 'stdClass');
241+
242+
$container->setDefinition('child1', new DefinitionDecorator('parent'))
243+
->setAutowired(true)
244+
;
245+
246+
$this->process($container);
247+
248+
$this->assertTrue($container->getDefinition('child1')->isAutowired());
249+
}
250+
251+
public function testSetAutowiredOnServiceIsParent()
252+
{
253+
$container = new ContainerBuilder();
254+
255+
$container->register('parent', 'stdClass')
256+
->setAutowired(true)
257+
;
258+
259+
$container->setDefinition('child1', new DefinitionDecorator('parent'));
260+
261+
$this->process($container);
262+
263+
$this->assertTrue($container->getDefinition('child1')->isAutowired());
264+
}
265+
236266
public function testDeepDefinitionsResolving()
237267
{
238268
$container = new ContainerBuilder();

src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ public function testSetLazy()
9595
$this->assertEquals(array('lazy' => true), $def->getChanges());
9696
}
9797

98+
public function testSetAutowired()
99+
{
100+
$def = new DefinitionDecorator('foo');
101+
102+
$this->assertFalse($def->isAutowired());
103+
$this->assertSame($def, $def->setAutowired(false));
104+
$this->assertFalse($def->isAutowired());
105+
$this->assertEquals(array('autowire' => true), $def->getChanges());
106+
}
107+
98108
public function testSetArgument()
99109
{
100110
$def = new DefinitionDecorator('foo');

0 commit comments

Comments
 (0)