diff --git a/README.md b/README.md index e53c7f8..588a067 100644 --- a/README.md +++ b/README.md @@ -15,16 +15,24 @@ Obtain API keys from the [Digital Ocean Applications & API dashboard](https://cl ```php use SpacesAPI\Spaces; +// Connect to a space $spaces = new Spaces('api-key', 'api-secret'); $space = $spaces->space('space-name'); +// Download a file $file = $space->file('remote-file-1.txt'); $file->download('local/file/path/file.txt'); +// Upload text to a file $file2 = $space->uploadText("Lorem ipsum","remote-file-2.txt"); + +// Get a signed public link, valid for 2 hours $file2url = $file2->getSignedURL("2 hours"); +// Make a copy $file3 = $file2->copy('remote-file-3.txt'); + +// Make a file public and get the URL $file3->makePublic(); $file3url = $file3->getURL(); ``` @@ -32,7 +40,7 @@ $file3url = $file3->getURL(); See more examples in [docs/Examples.md](docs/Examples.md) ## Upgrading? -Version 3 has many changes over verison 2, so we have written a [migration guide](docs/Upgrade2-3.md) +Version 3 has many changes over version 2, so we have written a [migration guide](docs/Upgrade2-3.md) ## API reference * [\SpacesAPI\Spaces](docs/Spaces.md) diff --git a/SpacesAPI/File.php b/SpacesAPI/File.php index 82719d2..f824b8a 100644 --- a/SpacesAPI/File.php +++ b/SpacesAPI/File.php @@ -10,6 +10,7 @@ use SpacesAPI\Exceptions\FileDoesntExistException; * You wouldn't normally instantiate this class directly, * Rather obtain an instance from `\SpacesAPI\Space::list()`, `\SpacesAPI\Spaces::file()`, `\SpacesAPI\Spaces::uploadText()` or `\SpacesAPI\Spaces::uploadFile()` * + * @property string $filename * @property string $expiration * @property string $e_tag * @property int $last_modified diff --git a/SpacesAPI/Space.php b/SpacesAPI/Space.php index 1ac856f..0b55f8a 100644 --- a/SpacesAPI/Space.php +++ b/SpacesAPI/Space.php @@ -252,16 +252,16 @@ class Space ]) ); - if (!isset($data['Contents'])) { - return ['files' => []]; - } - $files = [ - 'files' => $data['Contents'], + 'files' => [], ]; - foreach ($files['files'] as $index => $fileInfo) { - $files['files'][$index] = new File($this, $fileInfo['Key'], $fileInfo); + if (!isset($data['Contents'])) { + return $files; + } + + foreach ($data['Contents'] as $fileInfo) { + $files['files'][$fileInfo['Key']] = new File($this, $fileInfo['Key'], $fileInfo); } if (isset($data["NextContinuationToken"]) && $data["NextContinuationToken"] != "") { diff --git a/SpacesAPI/Spaces.php b/SpacesAPI/Spaces.php index 928ee2d..3f90470 100644 --- a/SpacesAPI/Spaces.php +++ b/SpacesAPI/Spaces.php @@ -61,7 +61,7 @@ class Spaces $spaces = []; foreach (Result::parse($this->s3->listBuckets()['Buckets']) as $bucket) { - $spaces[] = new Space($this->s3, $bucket['Name']); + $spaces[$bucket['Name']] = new Space($this->s3, $bucket['Name']); } return $spaces; diff --git a/composer.json b/composer.json index 087a7ba..715d5ff 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "sociallydev/spaces-api", "description": "Library for accessing Digital Ocean spaces", - "version":"3.0.0", + "version":"3.1.0", "type": "library", "license": "MIT", "authors": [ diff --git a/composer.lock b/composer.lock index 3c21eb8..f42afa8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c76b703f4b3b49f8421bcb693ece4aa8", + "content-hash": "77328f11e2ce84c590e531213fe931c6", "packages": [ { "name": "aws/aws-sdk-php", - "version": "3.187.2", + "version": "3.190.2", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "0ec4ae120cfae758efa3c283dc56eb20602f094c" + "reference": "8ca6a5f9834de3eb3fb84b28fc12c9088bc01293" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/0ec4ae120cfae758efa3c283dc56eb20602f094c", - "reference": "0ec4ae120cfae758efa3c283dc56eb20602f094c", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/8ca6a5f9834de3eb3fb84b28fc12c9088bc01293", + "reference": "8ca6a5f9834de3eb3fb84b28fc12c9088bc01293", "shasum": "" }, "require": { @@ -92,9 +92,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.187.2" + "source": "https://github.com/aws/aws-sdk-php/tree/3.190.2" }, - "time": "2021-08-04T18:12:21+00:00" + "time": "2021-08-13T18:12:28+00:00" }, { "name": "guzzlehttp/guzzle", diff --git a/docs/Space.md b/docs/Space.md index 9d4e6fe..ef23140 100644 --- a/docs/Space.md +++ b/docs/Space.md @@ -332,6 +332,7 @@ List all files in the space (recursively) `array` +> An array of `\SpacesAPI\File` instances indexed by the file name