Ejemplo n.º 1
0
 /**
  * Moves the source file or directory to the destination
  * @param   string     $src    The source path(s)
  * @param   string     $dest   The destination path
  * @return  $this
  * @throws
  */
 public function move($src, $dest)
 {
     $src = (string) $src;
     $dest = (string) $dest;
     if (is_dir($src)) {
         $f = new Finder($src);
         $f->depth(1);
         foreach ($f as $path) {
             $this->move($path->getPathname(), $dest . DIRECTORY_SEPARATOR . $this->getRelativePath($path->getPathname(), $src));
         }
         return $this;
     }
     if (file_exists($src)) {
         //if the destination is a folder then we'll create a new file with the same name as the source file
         if (is_dir($dest)) {
             $dest .= DIRECTORY_SEPARATOR . basename($src);
         }
         //check the parent folder exists
         $parent = dirname($dest);
         if (!is_dir($parent)) {
             throw new \Exception("Parent folder {$parent} does not exist");
         }
         if (!rename($src, $dest)) {
             throw new \RuntimeException("Unable to move file \"{$src}\" to \"{$dest}\".");
         }
         return $this;
     } else {
         throw new \InvalidArgumentException("Path \"{$src}\" does not exist.");
     }
     return $this;
 }