Example #1
0
 /**
  * Returns the node associated with the supplied path (implements the ArrayAccess interface).
  *
  * @param  string $index  The path of the object to get
  *
  * @return GitBlob, GitTree
  */
 public function offsetGet($path)
 {
     $path = new GitPath($path);
     $object = array_key_exists((string) $path, $this->stash) ? new GitBlob($this->git, null, null, $this->stash[(string) $path]) : $this->getTip()->offsetGet($path);
     if (is_null($object) || $object instanceof GitTree) {
         //make sure it's a cleaned reference, and that it's referencing a path
         $path = new GitPath($path . '/');
         foreach (array_keys($this->stash) as $key) {
             $file = new GitPath($key);
             if ($file->hasAncestor($path)) {
                 //remove $path part of the stash item
                 $file->splice(0, count($path));
                 if (is_null($object)) {
                     $object = new GitTree($this->git);
                 } elseif ($object->isReadOnly()) {
                     $object = clone $object;
                 }
                 if (is_null($this->stash[$key])) {
                     unset($object[$file]);
                 } else {
                     $object[$file] = new GitBlob($this->git, null, null, $this->stash[$key]);
                 }
             }
         }
     }
     return $object;
 }