mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-23 22:55:33 -07:00
Compare commits
No commits in common. "master" and "3.3.0" have entirely different histories.
12 changed files with 378 additions and 634 deletions
3
.github/ISSUE_TEMPLATE/BUG.yml
vendored
3
.github/ISSUE_TEMPLATE/BUG.yml
vendored
|
@ -18,9 +18,6 @@ body:
|
||||||
label: Version
|
label: Version
|
||||||
description: What version of Spaces-API is this occuring on? Versions below 3 will not be fixed. Please upgrade.
|
description: What version of Spaces-API is this occuring on? Versions below 3 will not be fixed. Please upgrade.
|
||||||
options:
|
options:
|
||||||
- 3.5.0
|
|
||||||
- 3.4.0
|
|
||||||
- 3.3.0
|
|
||||||
- 3.2.0
|
- 3.2.0
|
||||||
- 3.1.0
|
- 3.1.0
|
||||||
- 3.0.0
|
- 3.0.0
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
# This library is deprecated
|

|
||||||
We recommend using the [official SDK](https://github.com/DigitalOceanPHP/Client) or the [Laravel package](https://github.com/GrahamCampbell/Laravel-DigitalOcean)
|
|
||||||
|
|
||||||
All issues will be closed and new PRs will not be accepted
|
PHP library for accessing Digital Ocean spaces
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
Install via composer
|
Install via composer
|
||||||
|
@ -33,9 +32,6 @@ $file2url = $file2->getSignedURL("2 hours");
|
||||||
// Make a copy
|
// Make a copy
|
||||||
$file3 = $file2->copy('remote-file-3.txt');
|
$file3 = $file2->copy('remote-file-3.txt');
|
||||||
|
|
||||||
// Move or rename a file
|
|
||||||
$file2->move('new-filename.txt')
|
|
||||||
|
|
||||||
// Make a file public and get the URL
|
// Make a file public and get the URL
|
||||||
$file3->makePublic();
|
$file3->makePublic();
|
||||||
$file3url = $file3->getURL();
|
$file3url = $file3->getURL();
|
||||||
|
|
|
@ -4,8 +4,6 @@ namespace SpacesAPI;
|
||||||
|
|
||||||
use SpacesAPI\Exceptions\FileDoesntExistException;
|
use SpacesAPI\Exceptions\FileDoesntExistException;
|
||||||
|
|
||||||
use function PHPUnit\Framework\isNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a single file
|
* Represents a single file
|
||||||
*
|
*
|
||||||
|
@ -213,34 +211,19 @@ class File
|
||||||
*
|
*
|
||||||
* @return \SpacesAPI\File
|
* @return \SpacesAPI\File
|
||||||
*/
|
*/
|
||||||
public function copy(string $newFilename): File
|
public function copy(string $newFilename, bool $public = false): File
|
||||||
{
|
{
|
||||||
$this->s3->copy(
|
$this->s3->copy(
|
||||||
$this->space_name,
|
$this->space_name,
|
||||||
$this->_filename,
|
$this->_filename,
|
||||||
$this->space_name,
|
$this->space_name,
|
||||||
$newFilename,
|
$newFilename,
|
||||||
($this->isPublic()) ? 'public-read' : 'private'
|
($public) ? 'public-read' : 'private'
|
||||||
);
|
);
|
||||||
|
|
||||||
return new self($this->space, $newFilename);
|
return new self($this->space, $newFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $newFilename
|
|
||||||
*
|
|
||||||
* @return \SpacesAPI\File
|
|
||||||
*/
|
|
||||||
public function move(string $newFilename): File
|
|
||||||
{
|
|
||||||
$this->copy($newFilename);
|
|
||||||
$this->delete();
|
|
||||||
$this->_filename = $newFilename;
|
|
||||||
$this->fetchFileInfo();
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
|
|
|
@ -303,19 +303,15 @@ class Space
|
||||||
*
|
*
|
||||||
* @param string $filepath The path to the file, including the filename. Relative and absolute paths are accepted.
|
* @param string $filepath The path to the file, including the filename. Relative and absolute paths are accepted.
|
||||||
* @param string|null $filename The remote filename. If `null`, the local filename will be used.
|
* @param string|null $filename The remote filename. If `null`, the local filename will be used.
|
||||||
* @param string|null $mimeType The file mime type to pass as ContentType for the file (e.g. 'image/jpeg').
|
|
||||||
* @param bool $private True for the file to be private, false to allow public access.
|
|
||||||
*
|
*
|
||||||
* @return \SpacesAPI\File
|
* @return \SpacesAPI\File
|
||||||
*/
|
*/
|
||||||
public function uploadFile(string $filepath, ?string $filename = null, ?string $mimeType = null, bool $private = true): File
|
public function uploadFile(string $filepath, ?string $filename = null): File
|
||||||
{
|
{
|
||||||
$this->s3->putObject([
|
$this->s3->putObject([
|
||||||
'Bucket' => $this->name,
|
'Bucket' => $this->name,
|
||||||
'Key' => ($filename) ?: basename($filepath),
|
'Key' => ($filename) ?: basename($filepath),
|
||||||
'SourceFile' => $filepath,
|
'SourceFile' => $filepath,
|
||||||
'ContentType' => $mimeType,
|
|
||||||
'ACL' => ($private) ? 'private' : 'public-read'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return new File($this, ($filename) ?: basename($filepath), [], false);
|
return new File($this, ($filename) ?: basename($filepath), [], false);
|
||||||
|
@ -325,14 +321,13 @@ class Space
|
||||||
* Get an instance of \SpacesAPI\File for a given filename
|
* Get an instance of \SpacesAPI\File for a given filename
|
||||||
*
|
*
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @package bool $validate
|
|
||||||
*
|
*
|
||||||
* @return \SpacesAPI\File
|
* @return \SpacesAPI\File
|
||||||
* @throws \SpacesAPI\Exceptions\FileDoesntExistException Thrown if the file doesn't exist
|
* @throws \SpacesAPI\Exceptions\FileDoesntExistException Thrown if the file doesn't exist
|
||||||
*/
|
*/
|
||||||
public function file(string $filename, bool $validate = true): File
|
public function file(string $filename): File
|
||||||
{
|
{
|
||||||
return new File($this, $filename, [], $validate);
|
return new File($this, $filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -36,7 +36,7 @@ class Spaces
|
||||||
{
|
{
|
||||||
$this->s3 = new S3Client([
|
$this->s3 = new S3Client([
|
||||||
"version" => "latest",
|
"version" => "latest",
|
||||||
"region" => $region,
|
"region" => "us-east-1",
|
||||||
"endpoint" => "https://$region.$host",
|
"endpoint" => "https://$region.$host",
|
||||||
"credentials" => ["key" => $accessKey, "secret" => $secretKey],
|
"credentials" => ["key" => $accessKey, "secret" => $secretKey],
|
||||||
"ua_append" => "SociallyDev-Spaces-API/2",
|
"ua_append" => "SociallyDev-Spaces-API/2",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "sociallydev/spaces-api",
|
"name": "sociallydev/spaces-api",
|
||||||
"description": "Library for accessing Digital Ocean spaces",
|
"description": "Library for accessing Digital Ocean spaces",
|
||||||
"version":"3.6.1",
|
"version":"3.3.0",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"clean/phpdoc-md": "^0.19.1",
|
"clean/phpdoc-md": "^0.19.1",
|
||||||
"phpunit/phpunit": "^9.5.13",
|
"phpunit/phpunit": "^9.5",
|
||||||
"vlucas/phpdotenv": "^v5.4.1"
|
"vlucas/phpdotenv": "^5.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
874
composer.lock
generated
874
composer.lock
generated
File diff suppressed because it is too large
Load diff
24
docs/File.md
24
docs/File.md
|
@ -30,7 +30,6 @@ 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|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -289,27 +288,4 @@ Make file publicly accessible
|
||||||
`void`
|
`void`
|
||||||
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
|
|
||||||
|
|
||||||
### File::move
|
|
||||||
|
|
||||||
**Description**
|
|
||||||
|
|
||||||
```php
|
|
||||||
public move (string $newFilename)
|
|
||||||
```
|
|
||||||
|
|
||||||
Move or rename a file
|
|
||||||
The instance of `File` is now the moved object
|
|
||||||
|
|
||||||
**Parameters**
|
|
||||||
|
|
||||||
* `(string) $newFilename`
|
|
||||||
|
|
||||||
**Return Values**
|
|
||||||
|
|
||||||
`\SpacesAPI\File` : An instance for the new file
|
|
||||||
|
|
||||||
|
|
||||||
<hr />
|
<hr />
|
||||||
|
|
|
@ -180,7 +180,7 @@ Recursively download an entire directory.
|
||||||
**Description**
|
**Description**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public file (string $filename, bool $validate = true)
|
public file (string $filename)
|
||||||
```
|
```
|
||||||
|
|
||||||
Get an instance of \SpacesAPI\File for a given filename
|
Get an instance of \SpacesAPI\File for a given filename
|
||||||
|
@ -190,8 +190,6 @@ Get an instance of \SpacesAPI\File for a given filename
|
||||||
**Parameters**
|
**Parameters**
|
||||||
|
|
||||||
* `(string) $filename`
|
* `(string) $filename`
|
||||||
* `(bool) $validate`
|
|
||||||
: Whether to validate the file exits. Defaults to `true`
|
|
||||||
|
|
||||||
**Return Values**
|
**Return Values**
|
||||||
|
|
||||||
|
@ -465,7 +463,7 @@ Recursively upload an entire directory
|
||||||
**Description**
|
**Description**
|
||||||
|
|
||||||
```php
|
```php
|
||||||
public uploadFile (string $filepath, string|null $filename = null, string|null $mimeType = null, bool $private = true)
|
public uploadFile (string $filepath, string|null $filename = null)
|
||||||
```
|
```
|
||||||
|
|
||||||
Upload a file
|
Upload a file
|
||||||
|
@ -478,10 +476,6 @@ Upload a file
|
||||||
: The path to the file, including the filename. Relative and absolute paths are accepted.
|
: The path to the file, including the filename. Relative and absolute paths are accepted.
|
||||||
* `(string|null) $filename`
|
* `(string|null) $filename`
|
||||||
: The remote filename. If `null`, the local filename will be used. Default `null`
|
: The remote filename. If `null`, the local filename will be used. Default `null`
|
||||||
* `(string|null) $mimeType`
|
|
||||||
: The files mimeType. If `null` the mimeType is inferred from the file by DigitalOcean Spaces. Default `null`
|
|
||||||
* `(bool)` $private
|
|
||||||
: If `true` then the file is private, if `false` the file is publicly available. Default `true`
|
|
||||||
|
|
||||||
**Return Values**
|
**Return Values**
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ use SpacesAPI\Spaces;
|
||||||
|
|
||||||
class FileTest extends TestCase
|
class FileTest extends TestCase
|
||||||
{
|
{
|
||||||
private static $tempSpaceName;
|
|
||||||
private static $space;
|
private static $space;
|
||||||
private static $file;
|
private static $file;
|
||||||
|
|
||||||
|
@ -20,15 +19,18 @@ class FileTest extends TestCase
|
||||||
|
|
||||||
$spaces = new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']);
|
$spaces = new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']);
|
||||||
|
|
||||||
self::$tempSpaceName = md5(time());
|
try {
|
||||||
|
$spaces->space('spaces-api-test')->destroy();
|
||||||
|
} catch (SpaceDoesntExistException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
self::$space = $spaces->create(self::$tempSpaceName);
|
self::$space = $spaces->create('spaces-api-test');
|
||||||
self::$file = self::$space->uploadText('Lorem ipsum', 'lorem-ipsum.txt');
|
self::$file = self::$space->uploadText('Lorem ipsum', 'lorem-ipsum.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass(): void
|
public static function tearDownAfterClass(): void
|
||||||
{
|
{
|
||||||
self::$space->destroy();
|
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanUpdatePrivacy()
|
public function testCanUpdatePrivacy()
|
||||||
|
@ -62,17 +64,6 @@ 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("renamed-file.txt", $file->filename);
|
|
||||||
|
|
||||||
$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());
|
||||||
|
|
|
@ -9,7 +9,6 @@ use SpacesAPI\Spaces;
|
||||||
|
|
||||||
class SpaceTest extends TestCase
|
class SpaceTest extends TestCase
|
||||||
{
|
{
|
||||||
private static $tempSpaceName;
|
|
||||||
private static $space;
|
private static $space;
|
||||||
|
|
||||||
public static function setUpBeforeClass(): void
|
public static function setUpBeforeClass(): void
|
||||||
|
@ -20,14 +19,17 @@ class SpaceTest extends TestCase
|
||||||
|
|
||||||
$spaces = new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']);
|
$spaces = new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']);
|
||||||
|
|
||||||
self::$tempSpaceName = md5(time());
|
try {
|
||||||
|
$spaces->space('spaces-api-test')->destroy();
|
||||||
|
} catch (SpaceDoesntExistException $e) {
|
||||||
|
}
|
||||||
|
|
||||||
self::$space = $spaces->create(self::$tempSpaceName);
|
self::$space = $spaces->create('spaces-api-test');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass(): void
|
public static function tearDownAfterClass(): void
|
||||||
{
|
{
|
||||||
self::$space->destroy();
|
// (new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanUpdateSpacePrivacy()
|
public function testCanUpdateSpacePrivacy()
|
||||||
|
@ -86,14 +88,6 @@ class SpaceTest extends TestCase
|
||||||
$this->assertInstanceOf(File::class, $file);
|
$this->assertInstanceOf(File::class, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanUploadFileWithMimeType()
|
|
||||||
{
|
|
||||||
$tmpFile = tempnam(sys_get_temp_dir(), 'spaces-test');
|
|
||||||
$file = self::$space->uploadFile($tmpFile, 'upload-test.txt', 'text/plain');
|
|
||||||
$this->assertInstanceOf(File::class, $file);
|
|
||||||
$this->assertEquals('text/plain', $file->content_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @depends testCanUploadText
|
* @depends testCanUploadText
|
||||||
* @depends testCanUploadFile
|
* @depends testCanUploadFile
|
||||||
|
|
|
@ -10,21 +10,21 @@ use SpacesAPI\Spaces;
|
||||||
|
|
||||||
class SpacesTest extends TestCase
|
class SpacesTest extends TestCase
|
||||||
{
|
{
|
||||||
private static $tempSpaceName;
|
|
||||||
|
|
||||||
public static function setUpBeforeClass(): void
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
$dotenv = Dotenv::createImmutable(__DIR__ . "/..");
|
$dotenv = Dotenv::createImmutable(__DIR__ . "/..");
|
||||||
$dotenv->load();
|
$dotenv->load();
|
||||||
$dotenv->required(['SPACES_KEY', 'SPACES_SECRET']);
|
$dotenv->required(['SPACES_KEY', 'SPACES_SECRET']);
|
||||||
|
|
||||||
// This should hopefully always be unique amongst all DO spaces
|
try {
|
||||||
self::$tempSpaceName = md5(time());
|
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroy();
|
||||||
|
} catch (SpaceDoesntExistException $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function tearDownAfterClass(): void
|
public static function tearDownAfterClass(): void
|
||||||
{
|
{
|
||||||
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space(self::$tempSpaceName)->destroy();
|
(new Spaces($_ENV['SPACES_KEY'], $_ENV['SPACES_SECRET']))->space('spaces-api-test')->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAuthenticationCanFail()
|
public function testAuthenticationCanFail()
|
||||||
|
@ -53,7 +53,7 @@ class SpacesTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testCanCreateSpace(Spaces $spaces)
|
public function testCanCreateSpace(Spaces $spaces)
|
||||||
{
|
{
|
||||||
$space = $spaces->create(self::$tempSpaceName);
|
$space = $spaces->create('spaces-api-test');
|
||||||
$this->assertInstanceOf(Space::class, $space);
|
$this->assertInstanceOf(Space::class, $space);
|
||||||
|
|
||||||
return $space;
|
return $space;
|
||||||
|
@ -69,7 +69,7 @@ class SpacesTest extends TestCase
|
||||||
|
|
||||||
$spaceFound = false;
|
$spaceFound = false;
|
||||||
foreach ($list as $name => $space) {
|
foreach ($list as $name => $space) {
|
||||||
if ($name == self::$tempSpaceName && $space->getName() == self::$tempSpaceName) {
|
if ($name == 'spaces-api-test' && $space->getName() == 'spaces-api-test') {
|
||||||
$spaceFound = true;
|
$spaceFound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue