Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. vfsStreamWrapper.php

function vfsStreamWrapper::rename

rename from one path to another

@author Benoit Aubuchon

Parameters

string $path_from:

string $path_to:

Return value

bool

File

vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/vfsStreamWrapper.php, line 793

Class

vfsStreamWrapper
Stream wrapper to mock file system requests.

Namespace

org\bovigo\vfs

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal