Exemplo n.º 1
0
 /**
  * Removes the node from the path recursively
  *
  * @param string $path
  */
 public function offsetUnset($path)
 {
     $path = new GitPath($path);
     if ($this->isReadOnly()) {
         throw new Exception('Can not write to locked object');
     }
     if (!$path->isSingle() && isset($this->nodes[$path[0]])) {
         $sub = $this->nodes[$path[0]];
         if (!$sub instanceof GitTree) {
             throw new Exception('Invalid path');
         }
         if ($sub->isReadOnly()) {
             $sub = clone $sub;
             $this->data['nodes'][$path[0]] = $sub;
         }
         $sub->offsetUnset($path->getShifted());
     }
     if ($path->isRoot()) {
         throw new Exception('Can not unset self');
     }
     if ($path->isSingle() || count($this->data['nodes'][$path[0]]) == 0) {
         unset($this->data['nodes'][$path[0]]);
     }
 }
Exemplo n.º 2
0
$t->comment('isSingle testing');
$p = new GitPath("/");
$t->ok($p->isSingle(), 'root is a single reference');
$p = new GitPath("test/");
$t->ok($p->isSingle(), 'one directory is a single reference');
$p = new GitPath("test/file");
$t->ok(!$p->isSingle(), 'a file in a directory is not single');
$p = new GitPath("/test");
$t->ok($p->isSingle(), 'one file is a single reference');
$t->comment('isRoot testing');
$p = new GitPath("/");
$t->ok($p->isRoot(), 'root is a root');
$p = new GitPath("");
$t->ok($p->isRoot(), 'empty is a root');
$p = new GitPath("test");
$t->ok(!$p->isRoot(), 'a file is not a root');
$t->comment('Testing differences for Tree and Blob paths');
$p = new GitPath("abc/def/ghi");
$t->ok($p->refBlob(), 'no trailing slash references a blob object');
$p = new GitPath("abc/def/ghi/");
$t->ok($p->refTree(), 'a trailing slash references a tree object');
$t->comment('Testing array access');
$p = new GitPath("abc/def/ghi");
$t->is($p[0], 'abc', 'allows array access');
$t->is($p[-1], 'ghi', 'allows negative index array access');
$t->is(count($p), 3, 'count returns number of elements');
$t->comment('Testing iterator');
$p = new GitPath("abc/def");
foreach ($p as $index => $part) {
    switch ($index) {
        case 0: