Skip to content

[DI] Do not set values of lazy arguments after inlining them #21312

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
Jan 18, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function inlineArguments(ContainerBuilder $container, array $arguments,
if (is_array($argument)) {
$arguments[$k] = $this->inlineArguments($container, $argument);
} elseif ($argument instanceof ArgumentInterface) {
$argument->setValues($this->inlineArguments($container, $argument->getValues()));
$this->inlineArguments($container, $argument->getValues());
Copy link
Member

Choose a reason for hiding this comment

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

by removing this, we miss the opportunity to inline inside lazy arguments.
only the call to setValue should be removed in fact

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't dare to ask you about that. Updated

Copy link
Member

Choose a reason for hiding this comment

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

Is there any case where this could break? For example, if someone uses their own implementation of ArgumentInterface for whatever reason?

Copy link
Member

Choose a reason for hiding this comment

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

To answer my own question: the ArgumentInterface wasn't part of any release yet.

} elseif ($argument instanceof Reference) {
if (!$container->hasDefinition($id = (string) $argument)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Argument\ClosureProxyArgument;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;

class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -222,6 +224,33 @@ public function testProcessDoesNotInlineWhenServiceReferencesItself()
$this->assertSame($ref, $calls[0][1][0]);
}

public function testProcessDoesNotSetLazyArgumentValuesAfterInlining()
{
$container = new ContainerBuilder();
$container
->register('inline')
->setShared(false)
;
$container
->register('closure-proxy')
->setArguments(array(new ClosureProxyArgument('inline', 'method')))
;
$container
->register('iterator')
->setArguments(array(new IteratorArgument(array(new Reference('inline')))))
;

$this->process($container);

$values = $container->getDefinition('closure-proxy')->getArgument(0)->getValues();
$this->assertInstanceOf(Reference::class, $values[0]);
$this->assertSame('inline', (string) $values[0]);

$values = $container->getDefinition('iterator')->getArgument(0)->getValues();
$this->assertInstanceOf(Reference::class, $values[0]);
$this->assertSame('inline', (string) $values[0]);
}

protected function process(ContainerBuilder $container)
{
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));
Expand Down