PHPackages                             nurielmeni/yii2-digitalocean-spaces - 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. nurielmeni/yii2-digitalocean-spaces

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

nurielmeni/yii2-digitalocean-spaces
===================================

DigitalOcean Spaces component for Yii2

1.0.2(4y ago)07MITPHPPHP &gt;=7.0.0

Since Jan 19Pushed 4y ago1 watchersCompare

[ Source](https://github.com/nurielmeni/yii2-digitalocean-spaces)[ Packagist](https://packagist.org/packages/nurielmeni/yii2-digitalocean-spaces)[ Docs](https://github.com/nurielmeni/yii2-digitalocean-spaces)[ RSS](/packages/nurielmeni-yii2-digitalocean-spaces/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Yii2 DigitalOcean Spaces
========================

[](#yii2-digitalocean-spaces)

DigitalOcean Spaces component for Yii2. Based on [frostealth/yii2-aws-s3](https://github.com/frostealth/yii2-aws-s3/).

[![License](https://camo.githubusercontent.com/3f52fe81074b177b311e4575a1ad1dea22fe350d13d191a109b8babdbb4ad772/68747470733a2f2f706f7365722e707567782e6f72672f66726f737465616c74682f796969322d6177732d73332f6c6963656e7365)](https://github.com/frostealth/yii2-aws-s3/blob/2.x/LICENSE)

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

[](#installation)

1. Run the [Composer](http://getcomposer.org/download/) command to install the latest version:

    ```
    composer require nurielmeni/yii2-digitalocean-spaces
    ```
2. Add the component to config:

    ```
    'components' => [
        // ...
        'storage' => [
            'class' => 'nurielmeni\spaces\Service',
            'credentials' => [
                'key' => 'my-key',
                'secret' => 'my-secret',
            ],
            'region' => 'nyc3', // currently available: nyc3, ams3, sgp1, sfo2
            'defaultSpace' => 'my-space',
            'defaultAcl' => 'public-read',
        ],
        // ...
    ],
    ```

Basic usage
-----------

[](#basic-usage)

### Usage of the command factory and additional params

[](#usage-of-the-command-factory-and-additional-params)

```
/** @var \nurielmeni\spaces\Service $storage */
$storage = Yii::$app->get('storage');

/** @var \Aws\ResultInterface $result */
$result = $storage->commands()->get('filename.ext')->saveAs('/path/to/local/file.ext')->execute();

$result = $storage->commands()->put('filename.ext', 'body')->withContentType('text/plain')->execute();

$result = $storage->commands()->delete('filename.ext')->execute();

$result = $storage->commands()->upload('filename.ext', '/path/to/local/file.ext')->withAcl('private')->execute();

$result = $storage->commands()->restore('filename.ext', $days = 7)->execute();

$result = $storage->commands()->list('path/')->execute();

/** @var bool $exist */
$exist = $storage->commands()->exist('filename.ext')->execute();

/** @var string $url */
$url = $storage->commands()->getUrl('filename.ext')->execute();

/** @var string $signedUrl */
$signedUrl = $storage->commands()->getPresignedUrl('filename.ext', '+2 days')->execute();
```

### Short syntax

[](#short-syntax)

```
/** @var \nurielmeni\spaces\Service $storage */
$storage = Yii::$app->get('storage');

/** @var \Aws\ResultInterface $result */
$result = $storage->get('filename.ext');

$result = $storage->put('filename.ext', 'body');

$result = $storage->delete('filename.ext');

$result = $storage->upload('filename.ext', '/path/to/local/file.ext');

$result = $storage->restore('filename.ext', $days = 7);

$result = $storage->list('path/');

/** @var bool $exist */
$exist = $storage->exist('filename.ext');

/** @var string $url */
$url = $storage->getUrl('filename.ext');

/** @var string $signedUrl */
$signedUrl = $storage->getPresignedUrl('filename.ext', '+2 days');
```

### Asynchronous execution

[](#asynchronous-execution)

```
/** @var \nurielmeni\spaces\Service $storage */
$storage = Yii::$app->get('storage');

/** @var \GuzzleHttp\Promise\PromiseInterface $promise */
$promise = $storage->commands()->get('filename.ext')->async()->execute();

$promise = $storage->commands()->put('filename.ext', 'body')->async()->execute();

$promise = $storage->commands()->delete('filename.ext')->async()->execute();

$promise = $storage->commands()->upload('filename.ext', 'source')->async()->execute();

$promise = $storage->commands()->list('path/')->async()->execute();
```

Advanced usage
--------------

[](#advanced-usage)

```
/** @var \nurielmeni\spaces\interfaces\Service $storage */
$storage = Yii::$app->get('storage');

/** @var \frostealth\yii2\aws\s3\commands\GetCommand $command */
$command = $storage->create(GetCommand::class);
$command->inSpace('my-another-space')->byFilename('filename.ext')->saveAs('/path/to/local/file.ext');

/** @var \Aws\ResultInterface $result */
$result = $storage->execute($command);

// or async
/** @var \GuzzleHttp\Promise\PromiseInterface $promise */
$promise = $storage->execute($command->async());
```

### Custom commands

[](#custom-commands)

Commands have two types: plain commands that's handled by the `PlainCommandHandler` and commands with their own handlers. The plain commands wrap the native AWS S3 commands.

The plain commands must implement the `PlainCommand` interface and the rest must implement the `Command` interface. If the command doesn't implement the `PlainCommand` interface, it must have its own handler.

Every handler must extend the `Handler` class or implement the `Handler` interface. Handlers gets the `S3Client` instance into its constructor.

The implementation of the `HasSpace` and `HasAcl` interfaces allows the command builder to set the values of space and acl by default.

To make the plain commands asynchronously, you have to implement the `Asynchronous` interface. Also, you can use the `Async` trait to implement this interface.

Consider the following command:

```
