public function rename($path_from, $path_to)
{
$srcRealPath = $this->resolvePath(vfsStream::path($path_from));
$dstRealPath = $this->resolvePath(vfsStream::path($path_to));
$srcContent = $this->getContent($srcRealPath);
if (null == $srcContent) {
trigger_error(' No such file or directory', E_USER_WARNING);
return false;
}
$dstNames = $this->splitPath($dstRealPath);
$dstParentContent = $this->getContent($dstNames['dirname']);
if (null == $dstParentContent) {
trigger_error('No such file or directory', E_USER_WARNING);
return false;
}
if (!$dstParentContent->isWritable(vfsStream::getCurrentUser(), vfsStream::getCurrentGroup())) {
trigger_error('Permission denied', E_USER_WARNING);
return false;
}
if ($dstParentContent->getType() !== vfsStreamContent::TYPE_DIR) {
trigger_error('Target is not a directory', E_USER_WARNING);
return false;
}
// remove old source first, so we can rename later
// (renaming first would lead to not being able to remove the old path)
if (!$this->doUnlink($srcRealPath)) {
return false;
}
$dstContent = $srcContent;
// Renaming the filename
$dstContent->rename($dstNames['basename']);
// Copying to the destination
$dstParentContent->addChild($dstContent);
return true;
}