optimized circular reference checker
This commit is contained in:
parent
0009deb055
commit
96bb731b28
@ -28,6 +28,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface
|
||||
{
|
||||
private $currentId;
|
||||
private $currentPath;
|
||||
private $checkedNodes;
|
||||
|
||||
/**
|
||||
* Checks the ContainerBuilder object for circular references.
|
||||
@ -38,6 +39,7 @@ class CheckCircularReferencesPass implements CompilerPassInterface
|
||||
{
|
||||
$graph = $container->getCompiler()->getServiceReferenceGraph();
|
||||
|
||||
$this->checkedNodes = array();
|
||||
foreach ($graph->getNodes() as $id => $node) {
|
||||
$this->currentId = $id;
|
||||
$this->currentPath = array($id);
|
||||
@ -58,6 +60,8 @@ class CheckCircularReferencesPass implements CompilerPassInterface
|
||||
foreach ($edges as $edge) {
|
||||
$node = $edge->getDestNode();
|
||||
$id = $node->getId();
|
||||
|
||||
if (empty($this->checkedNodes[$id])) {
|
||||
$searchKey = array_search($id, $this->currentPath);
|
||||
$this->currentPath[] = $id;
|
||||
|
||||
@ -66,7 +70,10 @@ class CheckCircularReferencesPass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
$this->checkOutEdges($node->getOutEdges());
|
||||
|
||||
$this->checkedNodes[$id] = true;
|
||||
array_pop($this->currentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user