Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DI] Fix method autowiring in ResolveDefinitionTemplatesPass #21072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Symfony/Component/DependencyInjection/ChildDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ public function setDeprecated($boolean = true, $template = null)
/**
* {@inheritdoc}
*/
public function setAutowired($autowired)
public function setAutowiredMethods(array $autowiredMethods)
{
$this->changes['autowire'] = true;
$this->changes['autowired_methods'] = true;

return parent::setAutowired($autowired);
return parent::setAutowiredMethods($autowiredMethods);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function doResolveDefinition(ContainerBuilder $container, ChildDefinitio
$def->setFile($parentDef->getFile());
$def->setPublic($parentDef->isPublic());
$def->setLazy($parentDef->isLazy());
$def->setAutowired($parentDef->isAutowired());
$def->setAutowiredMethods($parentDef->getAutowiredMethods());

// overwrite with values specified in the decorator
$changes = $definition->getChanges();
Expand All @@ -166,8 +166,8 @@ private function doResolveDefinition(ContainerBuilder $container, ChildDefinitio
if (isset($changes['deprecated'])) {
$def->setDeprecated($definition->isDeprecated(), $definition->getDeprecationMessage('%service_id%'));
}
if (isset($changes['autowire'])) {
$def->setAutowired($definition->isAutowired());
if (isset($changes['autowired_methods'])) {
$def->setAutowiredMethods($definition->getAutowiredMethods());
}
if (isset($changes['decorated_service'])) {
$decoratedService = $definition->getDecoratedService();
Expand Down Expand Up @@ -199,7 +199,7 @@ private function doResolveDefinition(ContainerBuilder $container, ChildDefinitio
}

// append method calls
if (count($calls = $definition->getMethodCalls()) > 0) {
if ($calls = $definition->getMethodCalls()) {
$def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public function testSetLazy()
$this->assertSame(array('lazy' => true), $def->getChanges());
}

public function testSetAutowired()
public function testSetAutowiredMethods()
{
$def = new ChildDefinition('foo');

$this->assertFalse($def->isAutowired());
$this->assertSame($def, $def->setAutowired(false));
$this->assertFalse($def->isAutowired());
$this->assertSame(array('autowire' => true), $def->getChanges());
$this->assertSame($def, $def->setAutowiredMethods(array('foo', 'bar')));
$this->assertEquals(array('foo', 'bar'), $def->getAutowiredMethods());
$this->assertSame(array('autowired_methods' => true), $def->getChanges());
}

public function testSetArgument()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,30 +214,31 @@ public function testSetAutowiredOnServiceHasParent()
{
$container = new ContainerBuilder();

$container->register('parent', 'stdClass');
$container->register('parent', 'stdClass')
->setAutowiredMethods(array('foo', 'bar'));

$container->setDefinition('child1', new ChildDefinition('parent'))
->setAutowired(true)
->setAutowiredMethods(array('baz'))
;

$this->process($container);

$this->assertTrue($container->getDefinition('child1')->isAutowired());
$this->assertEquals(array('baz'), $container->getDefinition('child1')->getAutowiredMethods());
}

public function testSetAutowiredOnServiceIsParent()
{
$container = new ContainerBuilder();

$container->register('parent', 'stdClass')
->setAutowired(true)
->setAutowiredMethods(array('__construct', 'set*'))
;

$container->setDefinition('child1', new ChildDefinition('parent'));

$this->process($container);

$this->assertTrue($container->getDefinition('child1')->isAutowired());
$this->assertEquals(array('__construct', 'set*'), $container->getDefinition('child1')->getAutowiredMethods());
}

public function testDeepDefinitionsResolving()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ public function testSetLazy()
$this->assertEquals(array('lazy' => true), $def->getChanges());
}

public function testSetAutowired()
public function testSetAutowiredMethods()
{
$def = new DefinitionDecorator('foo');

$this->assertFalse($def->isAutowired());
$this->assertSame($def, $def->setAutowired(false));
$this->assertFalse($def->isAutowired());
$this->assertEquals(array('autowire' => true), $def->getChanges());
$this->assertSame($def, $def->setAutowiredMethods(array('foo', 'bar')));
$this->assertEquals(array('foo', 'bar'), $def->getAutowiredMethods());
$this->assertEquals(array('autowired_methods' => true), $def->getChanges());
}

public function testSetArgument()
Expand Down