Beispiel #1
0
 /**
  * Returns the INode object for the requested path
  *
  * @param string $path
  * @return Sabre_DAV_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) = Sabre_DAV_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 Sabre_DAV_ICollection) {
             throw new Sabre_DAV_Exception_NotFound('Could not find node at path: ' . $path);
         }
         $node = $parent->getChild($baseName);
     }
     $this->cache[$path] = $node;
     return $node;
 }
Beispiel #2
0
 /**
  * copyNode 
  * 
  * @param Sabre_DAV_INode $source 
  * @param Sabre_DAV_ICollection $destination 
  * @return void
  */
 protected function copyNode(Sabre_DAV_INode $source, Sabre_DAV_ICollection $destinationParent, $destinationName = null)
 {
     if (!$destinationName) {
         $destinationName = $source->getName();
     }
     if ($source instanceof Sabre_DAV_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 Sabre_DAV_ICollection) {
         $destinationParent->createDirectory($destinationName);
         $destination = $destinationParent->getChild($destinationName);
         foreach ($source->getChildren() as $child) {
             $this->copyNode($child, $destination);
         }
     }
     if ($source instanceof Sabre_DAV_IProperties && $destination instanceof Sabre_DAV_IProperties) {
         $props = $source->getProperties(array());
         $destination->updateProperties($props);
     }
 }