mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-07-06 13:01:33 -07:00
Added a file move method
This commit is contained in:
parent
bdd06aa0b7
commit
6b438e0b9a
3 changed files with 49 additions and 0 deletions
|
@ -224,6 +224,19 @@ class File
|
||||||
return new self($this->space, $newFilename);
|
return new self($this->space, $newFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $newFilename
|
||||||
|
*
|
||||||
|
* @return \SpacesAPI\File
|
||||||
|
*/
|
||||||
|
public function move(string $newFilename): File
|
||||||
|
{
|
||||||
|
$newFile = $this->copy($newFilename, $this->isPublic());
|
||||||
|
$this->delete();
|
||||||
|
|
||||||
|
return $newFile;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the public URL
|
* Get the public URL
|
||||||
* This URL will not work if the file is private
|
* This URL will not work if the file is private
|
||||||
|
|
25
docs/File.md
25
docs/File.md
|
@ -30,6 +30,7 @@ Rather obtain an instance from `\SpacesAPI\Space::list()`, `\SpacesAPI\Spaces::f
|
||||||
|[isPublic](#fileispublic)|Is this file publicly accessible|
|
|[isPublic](#fileispublic)|Is this file publicly accessible|
|
||||||
|[makePrivate](#filemakeprivate)|Make file non-publicly accessible|
|
|[makePrivate](#filemakeprivate)|Make file non-publicly accessible|
|
||||||
|[makePublic](#filemakepublic)|Make file publicly accessible|
|
|[makePublic](#filemakepublic)|Make file publicly accessible|
|
||||||
|
|[move](#filemove)|Move and/or rename file|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -288,4 +289,28 @@ Make file publicly accessible
|
||||||
`void`
|
`void`
|
||||||
|
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
|
||||||
|
### File::move
|
||||||
|
|
||||||
|
**Description**
|
||||||
|
|
||||||
|
```php
|
||||||
|
public move (string $newFilename)
|
||||||
|
```
|
||||||
|
|
||||||
|
Move or rename a file
|
||||||
|
The `File` instance on which you call `move` will become invalid and calling methods on it will result in a `FileDoesntExistException`
|
||||||
|
|
||||||
|
|
||||||
|
**Parameters**
|
||||||
|
|
||||||
|
* `(string) $newFilename`
|
||||||
|
|
||||||
|
**Return Values**
|
||||||
|
|
||||||
|
`\SpacesAPI\File` : An instance for the new file
|
||||||
|
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
|
@ -62,6 +62,17 @@ class FileTest extends TestCase
|
||||||
self::$space->file('lorem-ipsum-2.txt');
|
self::$space->file('lorem-ipsum-2.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanMoveRenameFile()
|
||||||
|
{
|
||||||
|
$file = self::$file->copy('test.txt');
|
||||||
|
$file->move('renamed-file.txt');
|
||||||
|
|
||||||
|
$this->assertEquals("Lorem ipsum", self::$space->file('renamed-file.txt')->getContents());
|
||||||
|
|
||||||
|
$this->expectException(FileDoesntExistException::class);
|
||||||
|
self::$space->file('test.txt');
|
||||||
|
}
|
||||||
|
|
||||||
public function testCanGetURL()
|
public function testCanGetURL()
|
||||||
{
|
{
|
||||||
$this->assertStringContainsString('lorem-ipsum.txt', self::$file->getURL());
|
$this->assertStringContainsString('lorem-ipsum.txt', self::$file->getURL());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue