bug#9153 [DependencyInjection] Prevented inlining of lazy loaded private service definitions (jakzal)

This PR was merged into the 2.3 branch.

Discussion
----------

[DependencyInjection] Prevented inlining of lazy loaded private service definitions

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #9136
| License       | MIT
| Doc PR       |

Commits
-------

bb0125b [DependencyInjection] Prevented inlining of lazy loaded private service definitions.
This commit is contained in:
Fabien Potencier 2013-09-27 21:46:26 +02:00
commit a38318b218
2 changed files with 21 additions and 3 deletions

View File

@ -117,7 +117,7 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
return true;
}
if ($definition->isPublic()) {
if ($definition->isPublic() || $definition->isLazy()) {
return false;
}

View File

@ -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;
@ -126,6 +124,26 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
$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()));