Gittern\Entity\Index::createTree PHP Method

createTree() public method

public createTree ( )
    public function createTree()
    {
        $tree = new Tree();
        foreach ($this->entries as $name => $entry) {
            $explosion = explode("/", $name);
            $blob_name = array_pop($explosion);
            $current_tree = $tree;
            foreach ($explosion as $subtree_name) {
                if (!$current_tree->hasNodeNamed($subtree_name)) {
                    $subtree = new Tree();
                    $subtree_node = new TreeNode();
                    $subtree_node->setTree($subtree);
                    $subtree_node->setName($subtree_name);
                    $current_tree->addNode($subtree_node);
                }
                $node = $current_tree->getNodeNamed($subtree_name);
                if (!$node instanceof TreeNode) {
                    throw new InvalidTypeException("Blob path {$name} specifies another blob as parent tree, which is impossible");
                }
                $current_tree = $node->getTree();
            }
            $blob_node = $entry->createBlobNode();
            $blob_node->setName($blob_name);
            $current_tree->addNode($blob_node);
        }
        return $tree;
    }