@@ -28,6 +28,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface
28
28
{
29
29
private $ currentId ;
30
30
private $ currentPath ;
31
+ private $ checkedNodes ;
31
32
32
33
/**
33
34
* Checks the ContainerBuilder object for circular references.
@@ -38,6 +39,7 @@ public function process(ContainerBuilder $container)
38
39
{
39
40
$ graph = $ container ->getCompiler ()->getServiceReferenceGraph ();
40
41
42
+ $ this ->checkedNodes = array ();
41
43
foreach ($ graph ->getNodes () as $ id => $ node ) {
42
44
$ this ->currentId = $ id ;
43
45
$ this ->currentPath = array ($ id );
@@ -58,15 +60,20 @@ private function checkOutEdges(array $edges)
58
60
foreach ($ edges as $ edge ) {
59
61
$ node = $ edge ->getDestNode ();
60
62
$ id = $ node ->getId ();
61
- $ searchKey = array_search ($ id , $ this ->currentPath );
62
- $ this ->currentPath [] = $ id ;
63
63
64
- if (false !== $ searchKey ) {
65
- throw new ServiceCircularReferenceException ($ id , array_slice ( $ this ->currentPath , $ searchKey ) );
66
- }
64
+ if (empty ( $ this -> checkedNodes [ $ id ]) ) {
65
+ $ searchKey = array_search ($ id , $ this ->currentPath );
66
+ $ this -> currentPath [] = $ id ;
67
67
68
- $ this ->checkOutEdges ($ node ->getOutEdges ());
69
- array_pop ($ this ->currentPath );
68
+ if (false !== $ searchKey ) {
69
+ throw new ServiceCircularReferenceException ($ id , array_slice ($ this ->currentPath , $ searchKey ));
70
+ }
71
+
72
+ $ this ->checkOutEdges ($ node ->getOutEdges ());
73
+
74
+ $ this ->checkedNodes [$ id ] = true ;
75
+ array_pop ($ this ->currentPath );
76
+ }
70
77
}
71
78
}
72
79
}
0 commit comments