bug #37953 [DI] fix dumping lazy non-shared services (nicolas-grekas)

This PR was merged into the 5.1 branch.

Discussion
----------

[DI] fix dumping lazy non-shared services

| Q             | A
| ------------- | ---
| Branch?       | 5.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #37665
| License       | MIT
| Doc PR        | -

Commits
-------

a4f4ca74a7 [DI] fix dumping lazy non-shared services
This commit is contained in:
Fabien Potencier 2020-08-26 11:10:33 +02:00
commit 885390fbaf
2 changed files with 2 additions and 1 deletions

View File

@ -886,6 +886,7 @@ EOF;
if ($asFile) {
$code = str_replace('$this', '$container', $code);
$code = str_replace('function () {', 'function () use ($container) {', $code);
$code = str_replace('function ($lazyLoad = true) {', 'function ($lazyLoad = true) use ($container) {', $code);
}
$code .= " }\n";

View File

@ -30,7 +30,7 @@ class getNonSharedFooService extends ProjectServiceContainer
{
include_once $container->targetDir.''.'/Fixtures/includes/foo_lazy.php';
$container->factories['non_shared_foo'] = function ($lazyLoad = true) {
$container->factories['non_shared_foo'] = function ($lazyLoad = true) use ($container) {
return new \Bar\FooLazyClass();
};