32
32
use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
33
33
use Symfony \Component \DependencyInjection \Exception \ServiceCircularReferenceException ;
34
34
use Symfony \Component \DependencyInjection \ExpressionLanguage ;
35
- use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \DumperInterface as ProxyDumper ;
35
+ use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \DumperInterface ;
36
36
use Symfony \Component \DependencyInjection \LazyProxy \PhpDumper \NullDumper ;
37
37
use Symfony \Component \DependencyInjection \Loader \FileLoader ;
38
38
use Symfony \Component \DependencyInjection \Parameter ;
@@ -95,9 +95,10 @@ class PhpDumper extends Dumper
95
95
private $ baseClass ;
96
96
97
97
/**
98
- * @var ProxyDumper
98
+ * @var DumperInterface
99
99
*/
100
100
private $ proxyDumper ;
101
+ private $ hasProxyDumper = false ;
101
102
102
103
/**
103
104
* {@inheritdoc}
@@ -114,9 +115,10 @@ public function __construct(ContainerBuilder $container)
114
115
/**
115
116
* Sets the dumper to be used when dumping proxies in the generated container.
116
117
*/
117
- public function setProxyDumper (ProxyDumper $ proxyDumper )
118
+ public function setProxyDumper (DumperInterface $ proxyDumper )
118
119
{
119
120
$ this ->proxyDumper = $ proxyDumper ;
121
+ $ this ->hasProxyDumper = !$ proxyDumper instanceof NullDumper;
120
122
}
121
123
122
124
/**
@@ -174,7 +176,7 @@ public function dump(array $options = [])
174
176
175
177
$ this ->initializeMethodNamesMap ('Container ' === $ baseClass ? Container::class : $ baseClass );
176
178
177
- if ($ this ->getProxyDumper () instanceof NullDumper ) {
179
+ if (! $ this ->hasProxyDumper ) {
178
180
(new AnalyzeServiceReferencesPass (true , false ))->process ($ this ->container );
179
181
try {
180
182
(new CheckCircularReferencesPass ())->process ($ this ->container );
@@ -407,7 +409,7 @@ class %s extends {$options['class']}
407
409
/**
408
410
* Retrieves the currently set proxy dumper or instantiates one.
409
411
*/
410
- private function getProxyDumper (): ProxyDumper
412
+ private function getProxyDumper (): DumperInterface
411
413
{
412
414
if (!$ this ->proxyDumper ) {
413
415
$ this ->proxyDumper = new NullDumper ();
@@ -418,7 +420,7 @@ private function getProxyDumper(): ProxyDumper
418
420
419
421
private function analyzeReferences ()
420
422
{
421
- (new AnalyzeServiceReferencesPass (false , ! $ this ->getProxyDumper () instanceof NullDumper ))->process ($ this ->container );
423
+ (new AnalyzeServiceReferencesPass (false , $ this ->hasProxyDumper ))->process ($ this ->container );
422
424
$ checkedNodes = [];
423
425
$ this ->circularReferences = [];
424
426
$ this ->singleUsePrivateIds = [];
@@ -445,13 +447,13 @@ private function collectCircularReferences(string $sourceId, array $edges, array
445
447
foreach ($ edges as $ edge ) {
446
448
$ node = $ edge ->getDestNode ();
447
449
$ id = $ node ->getId ();
448
- if ($ sourceId === $ id || !$ node ->getValue () instanceof Definition || $ edge ->isLazy () || $ edge -> isWeak ()) {
450
+ if ($ sourceId === $ id || !$ node ->getValue () instanceof Definition || $ edge ->isWeak ()) {
449
451
continue ;
450
452
}
451
453
452
454
if (isset ($ path [$ id ])) {
453
455
$ loop = null ;
454
- $ loopByConstructor = $ edge ->isReferencedByConstructor ();
456
+ $ loopByConstructor = $ edge ->isReferencedByConstructor () && ! $ edge -> isLazy () ;
455
457
$ pathInLoop = [$ id , []];
456
458
foreach ($ path as $ k => $ pathByConstructor ) {
457
459
if (null !== $ loop ) {
@@ -465,7 +467,7 @@ private function collectCircularReferences(string $sourceId, array $edges, array
465
467
}
466
468
$ this ->addCircularReferences ($ id , $ loop , $ loopByConstructor );
467
469
} elseif (!isset ($ checkedNodes [$ id ])) {
468
- $ this ->collectCircularReferences ($ id , $ node ->getOutEdges (), $ checkedNodes , $ loops , $ path , $ edge ->isReferencedByConstructor ());
470
+ $ this ->collectCircularReferences ($ id , $ node ->getOutEdges (), $ checkedNodes , $ loops , $ path , $ edge ->isReferencedByConstructor () && ! $ edge -> isLazy () );
469
471
} elseif (isset ($ loops [$ id ])) {
470
472
// we already had detected loops for this edge
471
473
// let's check if we have a common ancestor in one of the detected loops
@@ -486,7 +488,7 @@ private function collectCircularReferences(string $sourceId, array $edges, array
486
488
487
489
// we can now build the loop
488
490
$ loop = null ;
489
- $ loopByConstructor = $ edge ->isReferencedByConstructor ();
491
+ $ loopByConstructor = $ edge ->isReferencedByConstructor () && ! $ edge -> isLazy () ;
490
492
foreach ($ fillPath as $ k => $ pathByConstructor ) {
491
493
if (null !== $ loop ) {
492
494
$ loop [] = $ k ;
@@ -988,7 +990,7 @@ private function addInlineReference(string $id, Definition $definition, string $
988
990
return '' ;
989
991
}
990
992
991
- $ hasSelfRef = isset ($ this ->circularReferences [$ id ][$ targetId ]) && !isset ($ this ->definitionVariables [$ definition ]);
993
+ $ hasSelfRef = isset ($ this ->circularReferences [$ id ][$ targetId ]) && !isset ($ this ->definitionVariables [$ definition ]) && !( $ this -> hasProxyDumper && $ definition -> isLazy ()) ;
992
994
993
995
if ($ hasSelfRef && !$ forConstructor && !$ forConstructor = !$ this ->circularReferences [$ id ][$ targetId ]) {
994
996
$ code = $ this ->addInlineService ($ id , $ definition , $ definition );
@@ -1031,7 +1033,7 @@ private function addInlineService(string $id, Definition $definition, Definition
1031
1033
1032
1034
if ($ isSimpleInstance = $ isRootInstance = null === $ inlineDef ) {
1033
1035
foreach ($ this ->serviceCalls as $ targetId => [$ callCount , $ behavior , $ byConstructor ]) {
1034
- if ($ byConstructor && isset ($ this ->circularReferences [$ id ][$ targetId ]) && !$ this ->circularReferences [$ id ][$ targetId ]) {
1036
+ if ($ byConstructor && isset ($ this ->circularReferences [$ id ][$ targetId ]) && !$ this ->circularReferences [$ id ][$ targetId ] && !( $ this -> hasProxyDumper && $ definition -> isLazy ()) ) {
1035
1037
$ code .= $ this ->addInlineReference ($ id , $ definition , $ targetId , $ forConstructor );
1036
1038
}
1037
1039
}
0 commit comments