Newscoop\Storage::renameItem PHP Method

renameItem() public method

Rename item
public renameItem ( string $src, string $dest ) : void
$src string
$dest string
return void
    public function renameItem($src, $dest)
    {
        $srcPath = $this->getPath($src, TRUE);
        if (!$srcPath) {
            throw new \InvalidArgumentException($src, self::ERROR_NOT_FOUND);
        }
        if (!is_file($srcPath)) {
            throw new \InvalidArgumentException($src, self::ERROR_NOT_FILE);
        }
        $dir = dirname($srcPath);
        $destPath = "{$dir}/" . basename($dest);
        if (realpath($destPath)) {
            throw new \InvalidArgumentException($dest, self::ERROR_CONFLICT);
        }
        rename($srcPath, $destPath);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Rename item
  *
  * @param string $src
  * @param string $dest
  * @return void
  * @throws InvalidArgumentException
  */
 public function renameItem($src, $dest)
 {
     try {
         $name = basename($dest);
         $dest = ltrim(dirname($src) . $name, './');
         $this->storage->renameItem($src, $name);
         $this->repository->updateKey($src, $dest);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf('The template object %s could not be renamed.', basename($src)), $e->getCode(), $e);
     }
 }