protected function copyNodesRelationsAndReplace(INode $source, INode $destination) { foreach ($source->getChildren() as $index => $child) { /* @var $child INode */ $destination->addChild($child, $index); } $parent = $source->getParent(); if ($parent instanceof INode && $parent !== $source) { $parent->addChild($destination, $parent->getChildIndex($source)); } }
/** * Sorts INode's children by key. * * * @param INode $node the root node * @return void */ protected function sortChildren(INode $node) { if ($this->sorting !== NULL) { $children = $node->getChildren(); $node->removeChildren(); $sortedNodes = call_user_func($this->sorting, $children); foreach ($sortedNodes as $index => $child) { $this->sortChildren($child); // recursion $node->addChild($child, $index); } } return $this; }