BpConfig: allow access to a fake unbound base node

fixes #100
This commit is contained in:
Thomas Gelf 2017-02-20 14:19:52 +01:00
parent a9db4f9120
commit 2f3e5fb419
2 changed files with 25 additions and 19 deletions

View file

@ -483,6 +483,11 @@ class BpConfig
*/
public function getNode($name)
{
if ($name === '__unbound__') {
return $this->getUnboundBaseNode();
}
if (array_key_exists($name, $this->nodes)) {
return $this->nodes[$name];
}
@ -506,6 +511,25 @@ class BpConfig
);
}
/**
* @return BpNode
*/
public function getUnboundBaseNode()
{
// Hint: state is useless here, but triggers parent/child "calculation"
// This is an ugly workaround and should be made obsolete
$this->calculateAllStates();
$names = array_keys($this->getUnboundNodes());
$bp = new BpNode($this, (object) array(
'name' => '__unbound__',
'operator' => '&',
'child_names' => $names
));
$bp->setAlias($this->translate('Unbound nodes'));
return $bp;
}
/**
* @param $name
* @return BpNode

View file

@ -309,25 +309,7 @@ abstract class Renderer extends Html
protected function createUnboundParent(BpConfig $bp)
{
// Hint: state is useless here, but triggers parent/child "calculation"
// This is an ugly workaround and should be made obsolete
foreach ($bp->getBpNodes() as $p) {
$p->getState();
}
$unbound = $bp->getUnboundNodes();
$parent = new BpNode($bp, (object) array(
'name' => '__unbound__',
'operator' => '|',
'child_names' => array_keys($unbound)
));
$parent->getState();
$parent->setMissing()
->setDowntime(false)
->setAck(false)
->setAlias('Unbound nodes');
return $parent;
return $bp->getNode('__unbound__');
}
/**