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

Skip to content

Commit 56f5d83

Browse files
bug #27593 [ProxyManagerBridge] Fixed support of private services (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [ProxyManagerBridge] Fixed support of private services | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #... | License | MIT | Doc PR | <!-- Write a short README entry for your feature/bugfix here (replace this comment block.) This will help people understand your PR and can be used as a start of the Doc PR. Additionally: - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. --> Fixed lazy loading of private services, that was broken since Symfony 4.0 release because of renaming addObjectResource https://github.com/symfony/symfony/blame/fa022f05be75aacc8afcdc11b63333685c719e13/src/Symfony/Component/DependencyInjection/CHANGELOG.md#L114 Commits ------- 198bee0 [ProxyManagerBridge] Fixed support of private services
2 parents eeb53ee + 198bee0 commit 56f5d83

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
@@ -57,7 +57,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $factoryCode =
5757
$instantiation = 'return';
5858

5959
if ($definition->isShared()) {
60-
$instantiation .= " \$this->services['$id'] =";
60+
$instantiation .= sprintf(' $this->%s[\'%s\'] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', $id);
6161
}
6262

6363
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
@@ -83,6 +83,34 @@ public function testGetProxyFactoryCode()
8383
);
8484
}
8585

86+
/**
87+
* @dataProvider getPrivatePublicDefinitions
88+
*/
89+
public function testCorrectAssigning(Definition $definition, $access)
90+
{
91+
$definition->setLazy(true);
92+
93+
$code = $this->dumper->getProxyFactoryCode($definition, 'foo', '$this->getFoo2Service(false)');
94+
95+
$this->assertStringMatchesFormat('%A$this->'.$access.'[\'foo\'] = %A', $code);
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+
86114
/**
87115
* @group legacy
88116
*/

0 commit comments

Comments
 (0)