Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 364ccd1

Browse filesBrowse files
committed
merged branch bronze1man/PR-setLazy-parent-2.3 (PR #8573)
This PR was merged into the 2.3 branch. Discussion ---------- [DependencyInjection] setLazy not work on DefinitionDecorator | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #8570 | License | MIT | Doc PR | n/a Commits ------- 970ce2c [DependencyInjection] fixed #8570
2 parents 7dc211a + 970ce2c commit 364ccd1
Copy full SHA for 364ccd1

File tree

Expand file treeCollapse file tree

4 files changed

+56
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+56
-0
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ private function resolveDefinition($id, DefinitionDecorator $definition)
8787
$def->setConfigurator($parentDef->getConfigurator());
8888
$def->setFile($parentDef->getFile());
8989
$def->setPublic($parentDef->isPublic());
90+
$def->setLazy($parentDef->isLazy());
9091

9192
// overwrite with values specified in the decorator
9293
$changes = $definition->getChanges();
@@ -111,6 +112,9 @@ private function resolveDefinition($id, DefinitionDecorator $definition)
111112
if (isset($changes['public'])) {
112113
$def->setPublic($definition->isPublic());
113114
}
115+
if (isset($changes['lazy'])){
116+
$def->setLazy($definition->isLazy());
117+
}
114118

115119
// merge arguments
116120
foreach ($definition->getArguments() as $k => $v) {

‎src/Symfony/Component/DependencyInjection/DefinitionDecorator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/DefinitionDecorator.php
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ public function setPublic($boolean)
149149
return parent::setPublic($boolean);
150150
}
151151

152+
/**
153+
* {@inheritDoc}
154+
*
155+
* @api
156+
*/
157+
public function setLazy($boolean)
158+
{
159+
$this->changes['lazy'] = true;
160+
161+
return parent::setLazy($boolean);
162+
}
163+
152164
/**
153165
* Gets an argument to pass to the service constructor/factory method.
154166
*

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,36 @@ public function testProcessHandlesMultipleInheritance()
143143
$this->assertEquals('foo', $def->getClass());
144144
}
145145

146+
public function testSetLazyOnServiceHasParent()
147+
{
148+
$container = new ContainerBuilder();
149+
150+
$container->register('parent','stdClass');
151+
152+
$container->setDefinition('child1',new DefinitionDecorator('parent'))
153+
->setLazy(true)
154+
;
155+
156+
$this->process($container);
157+
158+
$this->assertTrue($container->getDefinition('child1')->isLazy());
159+
}
160+
161+
public function testSetLazyOnServiceIsParent()
162+
{
163+
$container = new ContainerBuilder();
164+
165+
$container->register('parent','stdClass')
166+
->setLazy(true)
167+
;
168+
169+
$container->setDefinition('child1',new DefinitionDecorator('parent'));
170+
171+
$this->process($container);
172+
173+
$this->assertTrue($container->getDefinition('child1')->isLazy());
174+
}
175+
146176
protected function process(ContainerBuilder $container)
147177
{
148178
$pass = new ResolveDefinitionTemplatesPass();

‎src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/DefinitionDecoratorTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ public function testSetPublic()
6161
$this->assertEquals(array('public' => true), $def->getChanges());
6262
}
6363

64+
public function testSetLazy()
65+
{
66+
$def = new DefinitionDecorator('foo');
67+
68+
$this->assertFalse($def->isLazy());
69+
$this->assertSame($def, $def->setLazy(false));
70+
$this->assertFalse($def->isLazy());
71+
$this->assertEquals(array('lazy' => true), $def->getChanges());
72+
}
73+
6474
public function testSetArgument()
6575
{
6676
$def = new DefinitionDecorator('foo');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.