/** * recursive way to build tree structure * * @param array $keyParts * @param TreeNode $rootNode * * @return TreeNode */ protected function createTree(&$keyParts, TreeNode $rootNode) : TreeNode { if (!count($keyParts)) { return $rootNode; } $newKey = array_shift($keyParts); $newNode = new self($rootNode, $newKey, null, $rootNode->getKeyDelimiter()); $rootNode->addChild($newNode); return $this->createTree($keyParts, $newNode); }