8000 [DependencyInjection] Fixing autowiring bug when some args are set by weaverryan · Pull Request #17876 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Fixing autowiring bug when some args are set #17876

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 3 commits into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[#17724] Fixing autowiring bug where if some args are set, new ones a…
…re put in the wrong spot
  • Loading branch information
weaverryan committed Feb 29, 2016
commit cf692a6bd863af25b0cabdf6e4bd8e8544ad0ed5
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ private function completeDefinition($id, Definition $definition)
$value = $parameter->getDefaultValue();
}

if ($argumentExists) {
$definition->replaceArgument($index, $value);
} else {
$definition->addArgument($value);
}
$arguments[$index] = $value;
}

// it's possible index 1 was set, then index 0, then 2, etc
// make sure that we re-order so they're injected as expected
ksort($arguments);
$definition->setArguments($arguments);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,36 @@ public function testDontUseAbstractServices()
$arguments = $container->getDefinition('bar')->getArguments();
$this->assertSame('foo', (string) $arguments[0]);
}

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

$container->register('foo', __NAMESPACE__.'\Foo');
$container->register('a', __NAMESPACE__.'\A');
$container->register('dunglas', __NAMESPACE__.'\Dunglas');
$container->register('multiple', __NAMESPACE__.'\MultipleArguments')
->setAutowired(true)
// set the 2nd (index 1) argument only: autowire the first and third
// args are: A, Foo, Dunglas
->setArguments(array(
1 => new Reference('foo'),
));

$pass = new AutowirePass();
$pass->process($container);

$definition = $container->getDefinition('multiple');
// takes advantage of Reference's __toString
$this->assertEquals(
array(
new Reference('a'),
new Reference('foo'),
new Reference('dunglas'),
),
$definition->getArguments()
);
}
}

class Foo
Expand Down Expand Up @@ -406,3 +436,9 @@ public function __construct(A $k)
{
}
}
class MultipleArguments
{
public function __construct(A $k, $foo, Dunglas $dunglas)
{
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line

0