Skip to content

Commit 7409731

Browse files
committed
bug #36548 [DI] fix lazy factory code generation (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [DI] fix lazy factory code generation | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | #36547 | License | MIT | Doc PR | - Commits ------- 7d55151ff4 [DI] fix lazy factory code generation
2 parents 635b10d + 5c33752 commit 7409731

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Dumper/PhpDumper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,8 @@ protected function {$methodName}($lazyInitialization)
851851

852852
if ($this->getProxyDumper()->isProxyCandidate($definition)) {
853853
$factoryCode = $asFile ? "\$this->load('%s', false)" : '$this->%s(false)';
854-
$code .= $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName));
854+
$factoryCode = $this->getProxyDumper()->getProxyFactoryCode($definition, $id, sprintf($factoryCode, $methodName));
855+
$code .= $asFile ? preg_replace('/function \(([^)]*+)\) {/', 'function (\1) use ($container) {', $factoryCode) : $factoryCode;
855856
}
856857

857858
$code .= $this->addServiceInclude($id, $definition);

0 commit comments

Comments
 (0)