anton-am / selectel-cloud-api
A simple API wrapper for Selectel object storage
Requires
- php: >=7.3.0
- ext-fileinfo: *
- ext-json: *
- ext-simplexml: *
- aws/aws-sdk-php: 3.288.1
Requires (Dev)
- codeception/codeception: ^4.1.1
- codeception/module-asserts: ^1.1.1
- codeception/module-filesystem: ^1.0.2
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A simple API wrapper for Selectel object storage.
Installation
- Using Composer:
composer require anton-am/selectel-cloud-api
Connecting
require_once('vendor/autoload.php'); use AntonAm\Selectel\Cloud\Manager; $key = 'ACCOUNT_ID_USER'; $secret = 'USER_PASSWORD'; $containerName = 'CONTAINER_NAME'; $client = new Manager($key, $secret, $containerName);
All available options:
Manager(REQUIRED KEY, REQUIRED SECRET, OPTIONAL CONTAINER NAME, OPTIONAL REGION, OPTIONAL HOST, OPTIONAL CLIENT OPTIONS);
Timeouts and retries
By default the client uses short timeouts and a single retry, so that an unavailable storage endpoint fails fast instead of hanging for minutes:
| Option | Default |
|---|---|
http.connect_timeout |
3 s |
http.timeout |
10 s |
retries |
1 |
Any extra AWS SDK client options
can be passed as the last constructor argument (or via setClient()). They are merged
recursively over the defaults, so only the values you need have to be overridden.
$client = new Manager($key, $secret, $containerName, 'ru-1', 'https://s3.storage.selcloud.ru', [ 'http' => [ 'connect_timeout' => 5, 'timeout' => 30, ], 'retries' => 2, ]);
Uploading/Downloading Files
$pathToFileInContainer = 'image.png'; $pathToFile = '/app/image.png'; $client->file($pathToFileInContainer)->setFileData($pathToFile)->create(); $downloadFile = 'image.png'; $saveAs = '/app/folder/downloaded-image.png'; $client->file($downloadFile)->download($saveAs);
Deleting Files/Folders
$pathToFileInContainer = 'image.png'; // fast, default: DeleteObject is idempotent, so no extra requests are made $client->file($pathToFileInContainer)->delete();
delete() accepts an optional $wait flag. When enabled, the client polls the storage
with HeadObject until the object (bucket) is really gone. It is disabled by default
because deletion is applied synchronously and every extra poll costs time and requests.
// wait until the object is really gone (up to 5 HEAD requests, 1 second apart) $client->file('image.png')->delete(true); // the flag is passed down to every file of the directory $client->directory('photos')->delete(true); $client->bucket()->delete(true);