[DependencyInjection] fixed #8570
This commit is contained in:
parent
2e2a36ca24
commit
970ce2c413
|
@ -87,6 +87,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
|
|||
$def->setConfigurator($parentDef->getConfigurator());
|
||||
$def->setFile($parentDef->getFile());
|
||||
$def->setPublic($parentDef->isPublic());
|
||||
$def->setLazy($parentDef->isLazy());
|
||||
|
||||
// overwrite with values specified in the decorator
|
||||
$changes = $definition->getChanges();
|
||||
|
@ -111,6 +112,9 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
|
|||
if (isset($changes['public'])) {
|
||||
$def->setPublic($definition->isPublic());
|
||||
}
|
||||
if (isset($changes['lazy'])){
|
||||
$def->setLazy($definition->isLazy());
|
||||
}
|
||||
|
||||
// merge arguments
|
||||
foreach ($definition->getArguments() as $k => $v) {
|
||||
|
|
|
@ -149,6 +149,18 @@ class DefinitionDecorator extends Definition
|
|||
return parent::setPublic($boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setLazy($boolean)
|
||||
{
|
||||
$this->changes['lazy'] = true;
|
||||
|
||||
return parent::setLazy($boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an argument to pass to the service constructor/factory method.
|
||||
*
|
||||
|
|
|
@ -143,6 +143,36 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals('foo', $def->getClass());
|
||||
}
|
||||
|
||||
public function testSetLazyOnServiceHasParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent','stdClass');
|
||||
|
||||
$container->setDefinition('child1',new DefinitionDecorator('parent'))
|
||||
->setLazy(true)
|
||||
;
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('child1')->isLazy());
|
||||
}
|
||||
|
||||
public function testSetLazyOnServiceIsParent()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('parent','stdClass')
|
||||
->setLazy(true)
|
||||
;
|
||||
|
||||
$container->setDefinition('child1',new DefinitionDecorator('parent'));
|
||||
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->getDefinition('child1')->isLazy());
|
||||
}
|
||||
|
||||
protected function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ResolveDefinitionTemplatesPass();
|
||||
|
|
|
@ -61,6 +61,16 @@ class DefinitionDecoratorTest extends \PHPUnit_Framework_TestCase
|
|||
$this->assertEquals(array('public' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetLazy()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
||||
$this->assertFalse($def->isLazy());
|
||||
$this->assertSame($def, $def->setLazy(false));
|
||||
$this->assertFalse($def->isLazy());
|
||||
$this->assertEquals(array('lazy' => true), $def->getChanges());
|
||||
}
|
||||
|
||||
public function testSetArgument()
|
||||
{
|
||||
$def = new DefinitionDecorator('foo');
|
||||
|
|
Reference in New Issue