|
|
@ -198,6 +198,50 @@ class Node implements \ArrayAccess, \Iterator |
|
|
|
return $current; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Set a child of this node by a dot-separate path. |
|
|
|
* |
|
|
|
* Each element of the path can either be a node name or a numeric |
|
|
|
* index representing the offset into an array |
|
|
|
* |
|
|
|
* @todo will explode if you try to write using a numeric index to an array |
|
|
|
* element that doesn't exist |
|
|
|
* @param string $path |
|
|
|
* @param Node $node |
|
|
|
*/ |
|
|
|
public function addChildUnderPath(string $path, Node $node): void |
|
|
|
{ |
|
|
|
$path = explode('.', $path); |
|
|
|
$current = $this; |
|
|
|
|
|
|
|
while (sizeof($path)) |
|
|
|
{ |
|
|
|
$next = array_shift($path); |
|
|
|
if (is_numeric($next)) |
|
|
|
{ |
|
|
|
$current = $current[$next]; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
$next_node = $current->getChildByName($next); |
|
|
|
|
|
|
|
if (!isset($next_node)) |
|
|
|
{ |
|
|
|
$next_node = new Node($current, $next); |
|
|
|
$current->addChild($next_node); |
|
|
|
$current = $next_node; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!isset($current)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$current->addChild($node); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Add a node to this node's children. |
|
|
|
* |
|
|
|