Author: Magnus Nordlander
Inheritance: extends BaseNode
Example #1
0
 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;
 }
Example #2
0
 public function hydrate(RawObject $raw_object)
 {
     $tree = new Tree();
     $tree->setSha($raw_object->getSha());
     $reader = new StringReader($raw_object->getData());
     while ($reader->available()) {
         $mode = intval($this->readModeString($reader), 8);
         $name = $this->readName($reader);
         $sha = $reader->readHHex(20);
         $is_tree = (bool) ($mode & 040000);
         if ($is_tree) {
             $node = new Node\TreeNode();
             $node->setTree(new TreeProxy($this->repo, $sha));
         } else {
             $node = new Node\BlobNode();
             $node->setBlob(new BlobProxy($this->repo, $sha));
         }
         $node->setIntegerMode($mode);
         $node->setName($name);
         $tree->addNode($node);
     }
     return $tree;
 }