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
fa022f05be/src/Symfony/Component/DependencyInjection/CHANGELOG.md (L114)

Commits
-------

198bee0916 [ProxyManagerBridge] Fixed support of private services
This commit is contained in:
Nicolas Grekas 2018-06-15 09:10:17 +02:00
commit 56f5d83f82
2 changed files with 29 additions and 1 deletions

View File

@ -57,7 +57,7 @@ class ProxyDumper implements DumperInterface
$instantiation = 'return';
if ($definition->isShared()) {
$instantiation .= " \$this->services['$id'] =";
$instantiation .= sprintf(' $this->%s[\'%s\'] =', $definition->isPublic() && !$definition->isPrivate() ? 'services' : 'privates', $id);
}
if (null === $factoryCode) {

View File

@ -83,6 +83,34 @@ class ProxyDumperTest extends TestCase
);
}
/**
* @dataProvider getPrivatePublicDefinitions
*/
public function testCorrectAssigning(Definition $definition, $access)
{
$definition->setLazy(true);
$code = $this->dumper->getProxyFactoryCode($definition, 'foo', '$this->getFoo2Service(false)');
$this->assertStringMatchesFormat('%A$this->'.$access.'[\'foo\'] = %A', $code);
}
public function getPrivatePublicDefinitions()
{
return array(
array(
(new Definition(__CLASS__))
->setPublic(false),
'privates',
),
array(
(new Definition(__CLASS__))
->setPublic(true),
'services',
),
);
}
/**
* @group legacy
*/