Skip to content

Commit

Permalink
[DependencyInjection] Prevented inlining of lazy loaded private servi…
Browse files Browse the repository at this point in the history
…ce definitions.
  • Loading branch information
jakzal committed Sep 26, 2013
1 parent 9a65ce3 commit bb0125b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Expand Up @@ -117,7 +117,7 @@ private function isInlineableDefinition(ContainerBuilder $container, $id, Defini
return true;
}

if ($definition->isPublic()) {
if ($definition->isPublic() || $definition->isLazy()) {
return false;
}

Expand Down
Expand Up @@ -12,10 +12,8 @@
namespace Symfony\Component\DependencyInjection\Tests\Compiler;

use Symfony\Component\DependencyInjection\Scope;

use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\Compiler;
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -126,6 +124,26 @@ public function testProcessInlinesOnlyIfSameScope()
$this->assertTrue($container->hasDefinition('a'));
}

public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy()
{
$container = new ContainerBuilder();
$container
->register('foo')
->setPublic(false)
->setLazy(true)
;

$container
->register('service')
->setArguments(array($ref = new Reference('foo')))
;

$this->process($container);

$arguments = $container->getDefinition('service')->getArguments();
$this->assertSame($ref, $arguments[0]);
}

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

0 comments on commit bb0125b

Please sign in to comment.