Example #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]]);
     }
 }
Example #2
0
<?php

require_once dirname(__FILE__) . '/../bootstrap/unit.php';
$t = new lime_test(34, new lime_output_color());
$t->comment('Testing output');
$a = array('abc', 'def', 'ghi');
$p = new GitPath($a);
$t->is((string) $p, 'abc/def/ghi', '__tostring returns string');
$t->is((string) $p->getTreePart(), 'abc/def/', 'getTreePart() returns string');
$t->is((string) $p->getBlobPart(), 'ghi', 'getBlobPart() returns string');
$t->ok($p->getShifted() instanceof GitPath, 'getShifted() returns GitPath');
$t->is((string) $p->getShifted(), 'def/ghi', 'getShifted() returns all items after first part');
$t->comment('Constructor testing');
$s = 'abc/def/ghi';
$p = new GitPath("/" . $s);
$t->is((string) $p, $s, 'constructor removes leading slashes');
$p = new GitPath("/////" . $s);
$t->is((string) $p, $s, 'constructor removes leading slashes');
$p = new GitPath("");
$t->is((string) $p, "/", 'constructor makes empty string into root reference');
$p = new GitPath("/");
$t->is((string) $p, "/", 'constructor accepts / as root reference');
$s .= '/';
$p = new GitPath($s);
$t->is((string) $p, $s, 'constructor accepts refTree paths');
$p = new GitPath($s . '/');
$t->is((string) $p, $s, 'constructor removes trailing slashes');
$p = new GitPath($s . '/////');
$t->is((string) $p, $s, 'constructor removes trailing slashes');
$p = new GitPath('abc//def//ghi//');
$t->is((string) $p, $s, 'constructor removes empty parts');