Newscoop\Storage::copyItem PHP Метод

copyItem() публичный Метод

Copy item
public copyItem ( string $src, string $dest ) : boolean
$src string
$dest string
Результат boolean
    public function copyItem($src, $dest)
    {
        $srcPath = $this->getPath($src, TRUE);
        if (!$srcPath) {
            throw new \InvalidArgumentException($src, self::ERROR_NOT_FOUND);
        }
        if (is_dir($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);
        }
        return copy($srcPath, $destPath);
    }

Usage Example

Пример #1
0
 /**
  * Copy item
  *
  * @param string $src
  * @param string $dest
  * @return void
  * @throws InvalidArgumentException
  */
 public function copyItem($src, $dest)
 {
     try {
         $this->storage->copyItem($src, $dest);
     } catch (\InvalidArgumentException $e) {
         throw new \InvalidArgumentException(sprintf('The template %s could not be created.', "<strong>{$dest}</strong>"), $e->getCode(), $e);
     }
 }