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

Skip to content

Commit c016761

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

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-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: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,37 @@ public function testGetProxyFactoryCode()
8080
);
8181
}
8282

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

0 commit comments

Comments
 (0)