本文整理匯總了PHP中Finder::depth方法的典型用法代碼示例。如果您正苦於以下問題:PHP Finder::depth方法的具體用法?PHP Finder::depth怎麽用?PHP Finder::depth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Finder
的用法示例。
在下文中一共展示了Finder::depth方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: move
/**
* 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;
}