public function rename(string $path_from, string $path_to): bool
    {
        $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);

        /** @var vfsStreamDirectory|null $dstParentContent */
        $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;
    }
public function rename(string $path_from, string $path_to): bool
    {
        $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);

        /** @var vfsStreamDirectory|null $dstParentContent */
        $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;
    }
public function rename ( string $ path_from , string $ path_to ) : bool { $ 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 ) ; /** @var vfsStreamDirectory|null $dstParentContent */ $ 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 ; }
rename from one path to another

@param   string  $path_from
@param   string  $path_to
@return  bool
@author  Benoit Aubuchon
rename from one path to another