Example #1
0
 /**
  * Returns the INode object for the requested path
  *
  * @param string $path
  * @return INode
  */
 public function getNodeForPath($path)
 {
     $path = trim($path, '/');
     if (isset($this->cache[$path])) {
         return $this->cache[$path];
     }
     // Is it the root node?
     if (!strlen($path)) {
         return $this->rootNode;
     }
     // Attempting to fetch its parent
     list($parentName, $baseName) = URLUtil::splitPath($path);
     // If there was no parent, we must simply ask it from the root node.
     if ($parentName === "") {
         $node = $this->rootNode->getChild($baseName);
     } else {
         // Otherwise, we recursively grab the parent and ask him/her.
         $parent = $this->getNodeForPath($parentName);
         if (!$parent instanceof ICollection) {
             throw new Exception\NotFound('Could not find node at path: ' . $path);
         }
         $node = $parent->getChild($baseName);
     }
     $this->cache[$path] = $node;
     return $node;
 }
Example #2
0
 /**
  * copyNode
  *
  * @param INode $source
  * @param ICollection $destinationParent
  * @param string $destinationName
  * @return void
  */
 protected function copyNode(INode $source, ICollection $destinationParent, $destinationName = null)
 {
     if (!$destinationName) {
         $destinationName = $source->getName();
     }
     if ($source instanceof IFile) {
         $data = $source->get();
         // If the body was a string, we need to convert it to a stream
         if (is_string($data)) {
             $stream = fopen('php://temp', 'r+');
             fwrite($stream, $data);
             rewind($stream);
             $data = $stream;
         }
         $destinationParent->createFile($destinationName, $data);
         $destination = $destinationParent->getChild($destinationName);
     } elseif ($source instanceof ICollection) {
         $destinationParent->createDirectory($destinationName);
         $destination = $destinationParent->getChild($destinationName);
         foreach ($source->getChildren() as $child) {
             $this->copyNode($child, $destination);
         }
     }
     if ($source instanceof IProperties && $destination instanceof IProperties) {
         $props = $source->getProperties(array());
         $destination->updateProperties($props);
     }
 }
Example #3
0
 protected function validCollection(ICollection $coll)
 {
     $arr = array();
     $coll->copyTo($arr);
     return $this->validArray($arr);
 }
 public function removeAll(ICollection $collection)
 {
     $rv = true;
     $iterator = $collection->getIterator();
     while ($iterator->hasNext()) {
         if (!$this->remove($iterator->next())) {
             $rv = false;
             break;
         }
     }
     return $rv;
 }
Example #5
0
 /** @see IIterator::hasNext() */
 public function hasNext()
 {
     return $this->collection->size() > $this->idx;
 }