Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c49f056

Browse filesBrowse files
committed
[DIC] Fix service autowiring inheritance
Update Changelog
1 parent 609ee2d commit c49f056
Copy full SHA for c49f056

File tree

5 files changed

+59
-0
lines changed
Filter options

5 files changed

+59
-0
lines changed

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
2.8.9
5+
-----
6+
7+
* fixed inheritance of the `autowire` flag
8+
49
2.8.0
510
-----
611

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
+4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/DefinitionDecorator.php
+10Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php
+30Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php
+10Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.