PHPackages                             slivka-b/selectel-cloud-storage - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. slivka-b/selectel-cloud-storage

ActiveLibrary[File &amp; Storage](/categories/file-storage)

slivka-b/selectel-cloud-storage
===============================

Selectel Cloud Storage API

1.2.2(4y ago)01.6k1MITPHPPHP &gt;=5.6

Since Jan 11Pushed 4y agoCompare

[ Source](https://github.com/SviatoslavBereznitskyi/selectel-cloud-storage)[ Packagist](https://packagist.org/packages/slivka-b/selectel-cloud-storage)[ Docs](https://github.com/argentcrusade/selectel-cloud-storage)[ RSS](/packages/slivka-b-selectel-cloud-storage/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (3)Versions (8)Used By (1)

argentcrusade/selectel-cloud-storage
====================================

[](#argentcrusadeselectel-cloud-storage)

[![Build Status](https://camo.githubusercontent.com/683bfab7dc59c2c93ce13bdc8d2add26e3e41c8d8983501ac3573596727014cb/68747470733a2f2f6170692e7472617669732d63692e6f72672f417267656e74437275736164652f73656c656374656c2d636c6f75642d73746f726167652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ArgentCrusade/selectel-cloud-storage)[![StyleCI](https://camo.githubusercontent.com/3420f1aca5f6320b6ec31bb57a6172531a16b68c76ab10240bc0695316bd8371/68747470733a2f2f7374796c6563692e696f2f7265706f732f37383637343438362f736869656c643f6272616e63683d6d6173746572267374796c653d666c6174)](https://styleci.io/repos/78674486)[![ScrutinizerCI](https://camo.githubusercontent.com/a083cf3e5b329e673080cbdb9246bbb1e8bc7c8a203ca36abfba72058eab80b3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f417267656e74437275736164652f73656c656374656c2d636c6f75642d73746f726167652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/ArgentCrusade/selectel-cloud-storage/)[![Latest Version on Packagist](https://camo.githubusercontent.com/a4e47462297f47d476808f823eb4d38fc65f2ff6cd4f38da7650d28e5b6d3753/68747470733a2f2f706f7365722e707567782e6f72672f617267656e74637275736164652f73656c656374656c2d636c6f75642d73746f726167652f76657273696f6e3f666f726d61743d666c6174)](https://packagist.org/packages/argentcrusade/selectel-cloud-storage)[![Software License](https://camo.githubusercontent.com/5dffe633a91cc1b9b4d2c04c3dbbffa18d537a0c42c3db8f7ebbe9cbb7856b5c/68747470733a2f2f706f7365722e707567782e6f72672f617267656e74637275736164652f73656c656374656c2d636c6f75642d73746f726167652f6c6963656e73653f666f726d61743d666c6174)](LICENSE.md)

Unofficial PHP SDK for [Selectel Cloud Storage](https://selectel.com/services/cloud-storage/) API.

Requirements
------------

[](#requirements)

This package requires PHP 5.6 or higher.

Installation
------------

[](#installation)

You can install the package via composer:

```
$ composer require argentcrusade/selectel-cloud-storage
```

Usage
-----

[](#usage)

### Initialize Storage

[](#initialize-storage)

```
use ArgentCrusade\Selectel\CloudStorage\Api\ApiClient;
use ArgentCrusade\Selectel\CloudStorage\CloudStorage;

$apiClient = new ApiClient('username', 'password');
$storage = new CloudStorage($apiClient);
```

### CloudStorage

[](#cloudstorage)

`ArgentCrusade\Selectel\CloudStorage\CloudStorage` class allows you to access and create containers.

```
// Retrieve single container.
$container = $storage->getContainer('my-container');

// Create new container.
$type = 'public'; // Can be 'public', 'private' or 'gallery'.
$newContainer = $storage->createContainer('new-container-name', $type);

// Retrieve containers list.
$containers = $storage->containers();
```

### Containers Collection

[](#containers-collection)

`CloudStorage::containers` method returns instance of `ArgentCrusade\Selectel\CloudStorage\Collections\Collection` class with retrieved containers objects. This collection object implements `ArrayAccess`, `Countable`, `Iterator` and `JsonSerializable` interfaces, what makes you able to do these things:

```
$containers = $storage->containers();

// Check if container exists.
if ($containers->has('my-container')) {
	// Container exists.
}

// Get containers count.
$containersCount = count($containers); // Or $containers->count();

// Access specific container.
$container = $containers['my-container']; // Or $containers->get('my-container');

// Iterate through containers.
foreach ($containers as $container) {
	echo 'Container "'.$container->name().'" has size of '.$container->size().' bytes';
}

// Send JSON representation of collection.
header('Content-Type: application/json;charset=utf-8');
echo json_encode($containers);
```

### Container Instance

[](#container-instance)

Container that you've retrieved from Containers Collection is an `ArgentCrusade\Selectel\CloudStorage\Container` instance object which implements `Countable` and `JsonSerializable` interfaces.

```
$container = $containers->get('my-container');

// Get container attributes.
$name = $container->name(); // 'container-name'.
$type = $container->type(); // 'private', 'public' or 'gallery'.
$filesCount = $container->filesCount(); // or count($container); // or $container->count();
$sizeInBytes = $container->size();
$uploadedBytes = $container->uploadedBytes(); // Total number of bytes uploaded to container (rx_bytes).
$downloadedBytes = $container->downloadedBytes(); // Total number of bytes downloaded from container (tx_bytes).
$json = json_encode($container); // JSON representation of container.

// Change container type.
$container->setType('private'); // Set container visiblity to 'public', 'private' or 'gallery'.

// Check if file exists in container.
$fileExists = $container->files()->exists('/path/to/file.txt'); // true or false.

// Get single file instance.
$file = $container->files()->find('/path/to/file.txt');

// Delete container.
// Note: container must be empty!
$container->delete();
```

### Fluent Files Loader

[](#fluent-files-loader)

You can use instance of `ArgentCrusade\Selectel\CloudStorage\FluentFilesLoader` class to retrieve files from container. Fluent loader returns `Collection` of file arrays or `Collection` of `File` objects.

This instance is accesible from `$container->files()` method and allows you to do following things:

```
// All files (first 10000 by default).
$files = $container->files()->get(); // or $container->files()->all();

// Files from specific directory.
$filesFromDirectory = $container->files()->fromDirectory('/directory')->get();

// Files that satisfies given prefix.
// Useful for retrieving files with same name pattern:
// image-001.jpg, image-002.jpg, image-003.jpg, etc.
$filesWithPrefix = $container->files()->withPrefix('image-')->get();

// You can also combine fromDirectory() and withPrefix() methods to load prefixed files
// from a specific directory:
$filesFromDirectoryWithPrefix = $container->files()->fromDirectory('/directory')->withPrefix('image-')->get();

// You can apply limit/marker values to any results set (before calling get() method).
// Marker file is a filename of last file from previous request (pagination).
// If you have 100 files with names like 'image-001.jpg', 'image-002.jpg', ... , 'image-100.jpg'
// and you need to load 50 files from 'image-051.jpg', you can do this:
$files = $container->files()
    ->fromDirectory('photos')
    ->withPrefix('image-')
    ->limit(50, 'image-050.jpg')
    ->get();

// Note: if you're working inside a directory (fromDirectory('photos')), then you can omit
// its path when using withPrefix() or marker file. If you're not in a directory, then
// full path to prefixed files and/or marker file is required.
$container->files()->fromDirectory('photos')->withPrefix('image-')->get(); // Full path is not required in withPrefix() method
$container->files()->withPrefix('photos/image-')->get(); // Full path is required.

// Use asFileObjects() method in chain to return Collection of File objects:
$files = $container->files()->fromDirectory('photos')->asFileObjects()->get();
$files[0]->name(); // First file's name.

// Warning: converting a lot of files to `File` instances may result in performance loss.
```

If you need to create `FluentFilesLoader` instance without `Container` instance, use following code:

```
use ArgentCrusade\Selectel\CloudStorage\Api\ApiClient;
use ArgentCrusade\Selectel\CloudStorage\FluentFilesLoader;

$api = new ApiClient('username', 'password');
$filesLoader = new FluentFilesLoader($api, 'container-name', '/container-name');
$files = $filesLoader->fromDirectory('photos')->limit(10)->asFileObjects()->get();
```

### File Uploads

[](#file-uploads)

`Container` class provides `uploadFromString` method to upload file contents and `uploadFromStream` method to upload file from stream.

```
// Upload file from string contents.
$contents = file_get_contents('test.txt');
$etag = $container->uploadFromString('/path/to/file.txt', $contents);

// Upload file from stream.
$stream = fopen('test.txt', 'r');
$etag = $container->uploadFromStream('/path/to/file.txt', $stream);
```

Both methods accepts `array $params` as third optional argument.

```
$params = [
	'contentType' => 'application/json',
    'contentDisposition' => 'attachment; filename="filename.json"',
    'deleteAfter' => $seconds, // File will be deleted in X seconds after upload.
    'deleteAt' => strtotime('next monday'), // File will be deleted at given UNIX timestamp.
];
```

Also, `uploadFromString` method accepts 4th argument `bool $verifyChecksum`. If true, Selectel will perform MD5 checksum comparison and if something went wrong during upload process, it won't accept file and exception will be thrown. This option is enabled by default for `uploadFromString` method.

### File Instance

[](#file-instance)

When you retrieve collection of files via `Contrainer::files` method you get `Collection` of file arrays:

```
$files = $container->files()->get();
$firstFile = $files->get(0);
/*
$firstFile will be something like this:

[
	'bytes' => 31,
    'content_type' => 'text/html',
    'hash' => 'b302ffc3b75770453e96c1348e30eb93',
    'last_modified': "2013-05-27T14:42:04.669760",
    'name': 'path/to/my_index.html',
    'filename': 'my_index.html'
]
*/
```

But when you're using `Container::files()->find` method, you receive instance of `ArgentCrusade\Selectel\CloudStorage\File` class that implements `JsonSerializable` interface. With this object you can perform operations such as renaming, copying and deleting file.

```
$file = $container->files()->find('/path/to/file.txt');

// Get file attributes.
$containerName = $file->container(); // 'my-container'
$path = $file->path(); // Full path to file (from container root): '/path/to/file.txt'
$directory = $file->directory(); // Full path to directory (from container root) without filename: '/path/to'
$name = $file->name(); // Filename 'file.txt'
$sizeInBytes = $file->size(); // File size in bytes.
$contentType = $file->contentType(); // 'text/plain'
$lastModifiedAt = $file->lastModifiedAt(); // '2013-05-27T14:42:04.669760'
$etag = $file->etag(); // md5 hash of file contents.
$isDeleted = $file->isDeleted(); // Becomes true only after deletion operation.
$json = json_encode($file); // JSON representation of file.

// Read file.
$contents = $file->read(); // Read file and return string.
$resource = $file->readStream(); // Read file and return stream resource.

// If you need PSR-7's StreamInterface instead of resource, provide $psr7Stream = true argument to File::readStream method:
$psr7Stream = $file->readStream(true); // Instance of \Psr\Http\Message\StreamInterface

// Rename file.
$file->rename('new-name.txt'); // File will be placed in the same directory.

// Copy file.
$file->copy('/path/to/new/file.txt'); // Provide full path to destination file (from container root).

// Copy file to another container.
$file->copy('/path/to/file.txt', 'my-second-container');

// Delete file.
// Note: after file deletion you won't be able to perform
// any of operations listed above (except $file->isDeleted() one).
$file->delete();
```

If you need to transform file from array to `File` instance you can use `Container::getFileFromArray` method:

```
$files = $container->files()->get();
$file = $container->getFileFromArray($files[0]);
```

Also, you can use `Container::getFilesCollectionFromArrays` method to convert files `Collection` or array of file arrays to `Collection` of `File` instances:

```
$files = $container->files()->get();

$filesCollection = $container->getFilesCollectionFromArrays($files);
$filesCollection[0]->name(); // Returns first file's name.
// Same as:
$filesCollection = $container->getFilesCollectionFromArrays([
	$files[0], $files[1],
]);
$filesCollection[0]->name(); // Returns first file's name.
```

Fluent loader (`FluentFilesLoader`) can also return `Collection` of file objects by calling `asFileObjects` method before `get` method (see [Fluent Files Loader section](#fluent-files-loader)).

***Warning***: converting a lot of files to `File` instances may result in performance loss.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
$ vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 71% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 92% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~279 days

Recently: every ~419 days

Total

7

Last Release

1677d ago

Major Versions

0.2.0 → 1.0.02017-01-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/593a292c66ea42e04d10ede2b2706869fea2df13f7ac3dc766c83e26a7699fec?d=identicon)[SviatoslavBereznitskyi](/maintainers/SviatoslavBereznitskyi)

---

Top Contributors

[![tzurbaev](https://avatars.githubusercontent.com/u/7444747?v=4)](https://github.com/tzurbaev "tzurbaev (23 commits)")[![SviatoslavBereznitskyi](https://avatars.githubusercontent.com/u/37864596?v=4)](https://github.com/SviatoslavBereznitskyi "SviatoslavBereznitskyi (2 commits)")

---

Tags

selectel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/slivka-b-selectel-cloud-storage/health.svg)

```
[![Health](https://phpackages.com/badges/slivka-b-selectel-cloud-storage/health.svg)](https://phpackages.com/packages/slivka-b-selectel-cloud-storage)
```

###  Alternatives

[uploadcare/uploadcare-php

Uploadcare PHP integration handles uploads and further operations with files by wrapping Upload and REST APIs.

1052.4M5](/packages/uploadcare-uploadcare-php)[argentcrusade/flysystem-selectel

Flysystem adapter for Selectel Cloud Storage

13127.5k2](/packages/argentcrusade-flysystem-selectel)[shitware-ltd/flysystem-msgraph

A Flysystem 3.0 adapter for Sharepoint 365 / OneDrive using Microsoft Graph API with support for uploading large files

19327.7k2](/packages/shitware-ltd-flysystem-msgraph)[jacekbarecki/flysystem-onedrive

OneDrive adapter for the flysystem filesystem abstraction library

2529.4k](/packages/jacekbarecki-flysystem-onedrive)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
