本文整理汇总了PHP中League\Flysystem\Filesystem::rename方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::rename方法的具体用法?PHP Filesystem::rename怎么用?PHP Filesystem::rename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Filesystem
的用法示例。
在下文中一共展示了Filesystem::rename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWrite
/**
* @dataProvider filesystemProvider
*/
public function testWrite(Filesystem $filesystem, $adapter, $cache)
{
$this->assertTrue($filesystem->write('some_file.txt', 'some content'));
$this->assertTrue($filesystem->has('some_file.txt'));
$this->assertTrue($cache->has('some_file.txt'));
$this->assertTrue($adapter->has('some_file.txt'));
$this->assertCount(1, $filesystem->listContents());
$this->assertCount(1, $cache->listContents('', false));
$this->assertCount(1, $adapter->listContents('', false));
$filesystem->rename('some_file.txt', 'other_name.txt');
$this->assertFalse($filesystem->has('some_file.txt'));
$this->assertFalse($cache->has('some_file.txt'));
$this->assertFalse($adapter->has('some_file.txt'));
$this->assertTrue($filesystem->has('other_name.txt'));
$this->assertTrue($cache->has('other_name.txt'));
$this->assertTrue($adapter->has('other_name.txt'));
$this->assertCount(1, $filesystem->listContents());
$this->assertCount(1, $cache->listContents('', false));
$this->assertCount(1, $adapter->listContents('', false));
$filesystem->delete('other_name.txt');
$this->assertFalse($filesystem->has('other_name.txt'));
$this->assertFalse($cache->has('other_name.txt'));
$this->assertFalse($adapter->has('other_name.txt'));
$this->assertCount(0, $filesystem->listContents());
$this->assertCount(0, $cache->listContents('', false));
$this->assertCount(0, $adapter->listContents('', false));
}
示例2: rename
/**
* {@inheritdoc}
*/
public function rename($source, $target)
{
if ($this->file_exists($target)) {
$this->unlink($target);
}
return $this->flysystem->rename($this->buildPath($source), $this->buildPath($target));
}
示例3: _move
/**
* @inheritdoc
*/
protected function _move($source, $target, $name)
{
$path = $this->_joinPath($target, $name);
if ($this->fs->rename($source, $path)) {
return $path;
}
return false;
}
示例4: moveToRepo
/**
* @param $sourceFile
* @param $repoFile
*
* @return bool
*
*/
public function moveToRepo($sourceFile, $repoFile)
{
$filesystem = new Filesystem(new Adapter('/'));
if ($filesystem->has($repoFile)) {
$filesystem->delete($repoFile);
}
$result = $filesystem->rename($sourceFile, $repoFile);
unset($filesystem);
return $result;
}
示例5: testRename
public function testRename()
{
$old = 'old.txt';
$new = 'new.txt';
$this->prophecy->has($old)->willReturn(true);
$this->prophecy->has($new)->willReturn(false);
$this->prophecy->rename($old, $new)->willReturn(true);
$response = $this->filesystem->rename($old, $new);
$this->assertTrue($response);
}
示例6: rename
/**
* @inheritdoc
*/
public function rename($path, $newPath)
{
$innerPath = $this->getInnerPath($path);
$newInnerPath = $this->getInnerPath($newPath);
try {
$return = $this->fileSystem->rename($innerPath, $newInnerPath);
} catch (FileNotFoundException $e) {
throw $this->exceptionWrapper($e, $path);
} catch (FileExistsException $e) {
throw $this->exceptionWrapper($e, $path);
}
if ($return !== false) {
$this->invokePlugin("addPathToIndex", [$newPath, $newInnerPath], $this);
$this->invokePlugin("removePathFromIndex", [$path, $innerPath], $this);
}
return $return;
}
示例7: renameLessonsWithRightPadding
/**
* Rename lessons, adding 0 padding to the number.
*/
public function renameLessonsWithRightPadding()
{
$list = $this->system->listContents(LESSONS_FOLDER);
foreach ($list as $entry) {
if ($entry['type'] != 'file') {
continue;
}
$originalName = $entry['basename'];
$oldNumber = substr($originalName, 0, strpos($originalName, '-'));
if (strlen($oldNumber) == 4) {
continue;
}
// already correct
$newNumber = sprintf("%04d", $oldNumber);
$nameWithoutNumber = substr($originalName, strpos($originalName, '-') + 1);
$newName = $newNumber . '-' . $nameWithoutNumber;
$this->system->rename(LESSONS_FOLDER . '/' . $originalName, LESSONS_FOLDER . '/' . $newName);
}
}
示例8: save
/**
* @param File[] $files
*
* @throws CanNotSavedException
*
* @return File[]
*/
public function save($files)
{
$fileSystemAdapter = $this->getAdapter();
$fileSystem = new Filesystem($fileSystemAdapter);
$savedFiles = [];
$i = 0;
foreach ($files as $file) {
$i++;
$filePath = $this->fileNameResolver->resolve(new \DateTime('now', new \DateTimeZone('UTC')), 'database', $file->getExtension());
$newBackupLocation = $this->backupFolder . '/' . $filePath;
$currBackupLocation = $file->getPath();
if ($fileSystem->has($newBackupLocation)) {
$fileSystem->delete($newBackupLocation);
}
if (!$fileSystem->rename($currBackupLocation, $newBackupLocation)) {
throw new CanNotSavedException();
}
$savedFiles[] = new File($fileSystemAdapter->applyPathPrefix($newBackupLocation));
}
return $savedFiles;
}
示例9: assembleChunks
public function assembleChunks($chunks, $removeChunk, $renameChunk)
{
// the index is only added to be in sync with the filesystem storage
$path = $this->prefix . '/' . $this->unhandledChunk['uuid'] . '/';
$filename = $this->unhandledChunk['index'] . '_' . $this->unhandledChunk['original'];
if (empty($chunks)) {
$target = $filename;
} else {
sort($chunks, SORT_STRING | SORT_FLAG_CASE);
$target = pathinfo($chunks[0], PATHINFO_BASENAME);
}
if ($this->unhandledChunk['index'] === 0) {
// if it's the first chunk overwrite the already existing part
// to avoid appending to earlier failed uploads
$handle = fopen($path . '/' . $target, 'w');
} else {
$handle = fopen($path . '/' . $target, 'a');
}
$this->filesystem->putStream($path . $target, $handle);
if ($renameChunk) {
$name = preg_replace('/^(\\d+)_/', '', $target);
/* The name can only match if the same user in the same session is
* trying to upload a file under the same name AND the previous upload failed,
* somewhere between this function, and the cleanup call. If that happened
* the previous file is unaccessible by the user, but if it is not removed
* it will block the user from trying to re-upload it.
*/
if ($this->filesystem->has($path . $name)) {
$this->filesystem->delete($path . $name);
}
$this->filesystem->rename($path . $target, $path . $name);
$target = $name;
}
$uploaded = $this->filesystem->get($path . $target);
if (!$renameChunk) {
return $uploaded;
}
return new FlysystemFile($uploaded, $this->filesystem, $this->streamWrapperPrefix);
}
示例10: rename
/**
* Renames the object for a given path.
*
* @param string $path
* @param string $newpath
*
* @return bool `true` on success, `false` on failure.
*/
public function rename($path, $newpath)
{
$baseAdapter = $this->getBaseAdapter();
if ($baseAdapter instanceof EmulateRenameDirectoryInterface && $this->hasDirectory($path)) {
return $baseAdapter->renameDirectory($path, $newpath);
}
return parent::rename($path, $newpath);
}
示例11: move
/**
* Move a file to a new location.
*
* @param string $from
* @param string $to
* @return bool
*/
public function move($from, $to)
{
return parent::rename($from, $to);
}
示例12: rename
/**
* @param string $path
* @param string $newPath
*
* @return bool
*/
public function rename($path, $newPath)
{
return $this->filesystem->rename($path, $newPath);
}
示例13: testRename
/**
* 3.txt
* 2.txt.
*/
public function testRename()
{
$this->assertTrue($this->filesystem->rename('1.txt', '3.txt'));
$this->assertFalse($this->filesystem->has('1.txt'));
$this->assertTrue($this->filesystem->has('3.txt'));
}
示例14: rename
/**
* @param Payload $payload
* @param Messenger $messenger
* @return PromiseInterface
*/
public function rename(Payload $payload, Messenger $messenger)
{
return \React\Promise\resolve(['renamed' => $this->flysystem->rename($payload['from'], $payload['to'])]);
}
示例15: rename
/**
* @inheritdoc
*/
public function rename($path, $newpath)
{
try {
return parent::rename($path, $newpath);
} catch (\Exception $e) {
$this->errors[] = $e->getMessage();
}
return false;
}