예제 #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]]);
     }
 }
예제 #2
0
$t->is((string) $p, $s, 'constructor removes trailing slashes');
$p = new GitPath('abc//def//ghi//');
$t->is((string) $p, $s, 'constructor removes empty parts');
$p = new GitPath('abc  // def//   ghi // ');
$t->is((string) $p, $s, 'constructor removes extra spaces');
$p = new GitPath('ab c  // d ef//   g h i // ');
$t->is((string) $p, 'ab c/d ef/g h i/', 'constructor leaves inner spaces');
$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');