|
|
@ -176,37 +176,26 @@ class Node implements \ArrayAccess, \Iterator |
|
|
|
public function getChildByPath(string $path): ?Node |
|
|
|
{ |
|
|
|
$path = explode('.', $path); |
|
|
|
return $this->findChild($path, $this); |
|
|
|
} |
|
|
|
$current = $this; |
|
|
|
|
|
|
|
/** |
|
|
|
* Recursively walk nodes to find a node based on a path. |
|
|
|
* |
|
|
|
* @param string[] $path |
|
|
|
* @param Node $current |
|
|
|
* @return ?Node |
|
|
|
*/ |
|
|
|
protected function findChild(array $path, Node $current): ?Node |
|
|
|
{ |
|
|
|
$next = array_shift($path); |
|
|
|
if (is_numeric($next)) |
|
|
|
{ |
|
|
|
$next = $current[$next]; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
$next = $current->getChildByName($next); |
|
|
|
} |
|
|
|
if (empty($path)) |
|
|
|
while (sizeof($path)) |
|
|
|
{ |
|
|
|
return $next; |
|
|
|
} |
|
|
|
if (!isset($next)) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
$next = array_shift($path); |
|
|
|
if (is_numeric($next)) |
|
|
|
{ |
|
|
|
$current = $current[$next]; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
$current = $current->getChildByName($next); |
|
|
|
} |
|
|
|
|
|
|
|
return $this->findChild($path, $next); |
|
|
|
if (!isset($current)) |
|
|
|
{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
return $current; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|