Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4ba66f

Browse files
author
Pavel Agaletskiy
committed
[DI] Fixed support of private services since Symfony 4.0
1 parent 5c338cc commit a4ba66f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Symfony/Bridge/ProxyManager/LazyProxy/PhpDumper/ProxyDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $factoryCode =
5454
$instantiation = 'return';
5555

5656
if ($definition->isShared()) {
57-
$instantiation .= sprintf(' $this->%s[\'%s\'] =', $definition->isPublic() || !method_exists(ContainerBuilder::class, 'addClassResource') ? 'services' : 'privates', $id);
57+
$instantiation .= sprintf(' $this->%s[\'%s\'] =', $definition->isPublic() || !method_exists(ContainerBuilder::class, 'addObjectResource') ? 'services' : 'privates', $id);
5858
}
5959

6060
if (null === $factoryCode) {

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,34 @@ public function testGetProxyFactoryCode()
8080
);
8181
}
8282

83+
/**
84+
* @dataProvider getPrivatePublicDefinitions
85+
*/
86+
public function testCorrectAssigning(Definition $definition, string $access)
87+
{
88+
$definition->setLazy(true);
89+
90+
$code = $this->dumper->getProxyFactoryCode($definition, 'foo', '$this->getFoo2Service(false)');
91+
92+
$this->assertStringMatchesFormat('%A$this->'.$access.'[\'foo\'] = %A', $code);
93+
}
94+
95+
public function getPrivatePublicDefinitions()
96+
{
97+
return array(
98+
array(
99+
(new Definition(__CLASS__))
100+
->setPublic(false),
101+
'privates',
102+
),
103+
array(
104+
(new Definition(__CLASS__))
105+
->setPublic(true),
106+
'services',
107+
),
108+
);
109+
}
110+
83111
/**
84112
* @expectedException \InvalidArgumentException
85113
* @expectedExceptionMessage Missing factory code to construct the service "foo".

0 commit comments

Comments
 (0)