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:
commit
a38318b218
@ -117,7 +117,7 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($definition->isPublic()) {
|
if ($definition->isPublic() || $definition->isLazy()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,10 +12,8 @@
|
|||||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
use Symfony\Component\DependencyInjection\Scope;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
|
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\Compiler;
|
|
||||||
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
|
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass;
|
use Symfony\Component\DependencyInjection\Compiler\InlineServiceDefinitionsPass;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
@ -126,6 +124,26 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($container->hasDefinition('a'));
|
$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)
|
protected function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));
|
$repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new InlineServiceDefinitionsPass()));
|
||||||
|
Reference in New Issue
Block a user