@@ -154,12 +154,16 @@ public function dump(array $options = array())
154
154
}
155
155
}
156
156
157
- (new AnalyzeServiceReferencesPass (false ))->process ($ this ->container );
157
+ (new AnalyzeServiceReferencesPass (false , ! $ this -> getProxyDumper () instanceof NullDumper ))->process ($ this ->container );
158
158
$ this ->circularReferences = array ();
159
159
$ checkedNodes = array ();
160
160
foreach ($ this ->container ->getCompiler ()->getServiceReferenceGraph ()->getNodes () as $ id => $ node ) {
161
+ if (!$ node ->getValue () instanceof Definition) {
162
+ continue ;
163
+ }
164
+ $ checkedNodes [$ id ] = true ;
161
165
$ currentPath = array ($ id => $ id );
162
- $ this ->analyzeCircularReferences ($ node ->getOutEdges (), $ checkedNodes , $ currentPath );
166
+ $ this ->analyzeCircularReferences ($ node ->getOutEdges (), $ checkedNodes , $ currentPath, $ id );
163
167
}
164
168
$ this ->container ->getCompiler ()->getServiceReferenceGraph ()->clear ();
165
169
@@ -297,13 +301,13 @@ private function getProxyDumper()
297
301
return $ this ->proxyDumper ;
298
302
}
299
303
300
- private function analyzeCircularReferences (array $ edges , &$ checkedNodes , &$ currentPath )
304
+ private function analyzeCircularReferences (array $ edges , &$ checkedNodes , &$ currentPath, $ sourceId )
301
305
{
302
306
foreach ($ edges as $ edge ) {
303
307
$ node = $ edge ->getDestNode ();
304
308
$ id = $ node ->getId ();
305
309
306
- if ($ node ->getValue () && ( $ edge ->isLazy () || $ edge ->isWeak () )) {
310
+ if (! $ node ->getValue () instanceof Definition || $ sourceId === $ id || $ edge ->isLazy () || $ edge ->isWeak ()) {
307
311
// no-op
308
312
} elseif (isset ($ currentPath [$ id ])) {
309
313
$ currentId = $ id ;
@@ -317,7 +321,7 @@ private function analyzeCircularReferences(array $edges, &$checkedNodes, &$curre
317
321
} elseif (!isset ($ checkedNodes [$ id ])) {
318
322
$ checkedNodes [$ id ] = true ;
319
323
$ currentPath [$ id ] = $ id ;
320
- $ this ->analyzeCircularReferences ($ node ->getOutEdges (), $ checkedNodes , $ currentPath );
324
+ $ this ->analyzeCircularReferences ($ node ->getOutEdges (), $ checkedNodes , $ currentPath, $ id );
321
325
unset($ currentPath [$ id ]);
322
326
}
323
327
}
@@ -700,8 +704,14 @@ private function addInlineVariables($id, Definition $definition, array $argument
700
704
701
705
private function addInlineReference ($ id , Definition $ definition , $ targetId , $ forConstructor )
702
706
{
707
+ list ($ callCount , $ behavior ) = $ this ->serviceCalls [$ targetId ];
708
+
709
+ while ($ this ->container ->hasAlias ($ targetId )) {
710
+ $ targetId = (string ) $ this ->container ->getAlias ($ targetId );
711
+ }
712
+
703
713
if ($ id === $ targetId ) {
704
- return $ this ->addInlineService ($ id , $ definition , $ definition, $ forConstructor );
714
+ return $ this ->addInlineService ($ id , $ definition , $ definition );
705
715
}
706
716
707
717
if ('service_container ' === $ targetId || isset ($ this ->referenceVariables [$ targetId ])) {
@@ -710,9 +720,7 @@ private function addInlineReference($id, Definition $definition, $targetId, $for
710
720
711
721
$ hasSelfRef = isset ($ this ->circularReferences [$ id ][$ targetId ]);
712
722
$ forConstructor = $ forConstructor && !isset ($ this ->definitionVariables [$ definition ]);
713
- list ($ callCount , $ behavior ) = $ this ->serviceCalls [$ targetId ];
714
-
715
- $ code = $ hasSelfRef && !$ forConstructor ? $ this ->addInlineService ($ id , $ definition , $ definition , $ forConstructor ) : '' ;
723
+ $ code = $ hasSelfRef && !$ forConstructor ? $ this ->addInlineService ($ id , $ definition , $ definition ) : '' ;
716
724
717
725
if (isset ($ this ->referenceVariables [$ targetId ]) || (2 > $ callCount && (!$ hasSelfRef || !$ forConstructor ))) {
718
726
return $ code ;
0 commit comments