function SessionStreamWrapper::rename
Same name in other branches
- 8.x-1.x stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php \Drupal\stream_wrapper_example\StreamWrapper\SessionStreamWrapper::rename()
- 4.0.x modules/stream_wrapper_example/src/StreamWrapper/SessionStreamWrapper.php \Drupal\stream_wrapper_example\StreamWrapper\SessionStreamWrapper::rename()
Support for rename().
Parameters
string $from_uri: The uri to the file to rename.
string $to_uri: The new uri for file.
Return value
bool TRUE if file was successfully renamed.
Overrides PhpStreamWrapperInterface::rename
See also
http://php.net/manual/en/streamwrapper.rename.php
File
-
modules/
stream_wrapper_example/ src/ StreamWrapper/ SessionStreamWrapper.php, line 627
Class
- SessionStreamWrapper
- Example stream wrapper class to handle session:// streams.
Namespace
Drupal\stream_wrapper_example\StreamWrapperCode
public function rename($from_uri, $to_uri) {
// We get the old key contents, write it
// to a new key, erase the old key.
$from_path = $this->getLocalPath($from_uri);
$to_path = $this->getLocalPath($to_uri);
if (!$this->sessionHelper
->checkPath($from_path)) {
return FALSE;
}
$from_key = $this->sessionHelper
->getPath($from_path);
$path_info = $this->sessionHelper
->getParentPath($to_path);
$parent_path = $path_info['dirname'];
// We will only allow writing to a non-existent file
// in an existing directory.
if ($this->sessionHelper
->checkPath($parent_path) && !$this->sessionHelper
->checkPath($to_path)) {
$this->sessionHelper
->setPath($to_path, $from_key);
$this->sessionHelper
->clearPath($from_path);
return TRUE;
}
return FALSE;
}