Skip to content

Commit

Permalink
bug #27593 [ProxyManagerBridge] Fixed support of private services (ni…
Browse files Browse the repository at this point in the history
…colas-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
  • Loading branch information
nicolas-grekas committed Jun 15, 2018
2 parents eeb53ee + 198bee0 commit 56f5d83
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Expand Up @@ -57,7 +57,7 @@ public function getProxyFactoryCode(Definition $definition, $id, $factoryCode =
$instantiation = 'return';

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

if (null === $factoryCode) {
Expand Down
Expand Up @@ -83,6 +83,34 @@ public function testGetProxyFactoryCode()
);
}

/**
* @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
*/
Expand Down

0 comments on commit 56f5d83

Please sign in to comment.