airani/yii2-flysystem

Yii2 Flysystem Component

Installs: 184

Dependents: 0

Suggesters: 0

Security: 0

Stars: 7

Watchers: 2

Forks: 1

Open Issues: 1

Type:yii2-extension

v1.0 2017-08-18 21:48 UTC

This package is auto-updated.

Last update: 2024-04-08 22:13:56 UTC


README

The Flysystem component for Yii2 PHP framework with more flexibility than similar components and integrated with Flysystem MountManager and returns Flysystem objects as Yii2 component that helps to work with other libraries integrated with Flysystem like Glide .

Installation

The preferred way to install this extension is through composer .

Either run

composer require airani/yii2-flysystem

or add

"airani/yii2-flysystem": "~1.0"

to the require section of your composer.json file.

Configuring

Configure application components for any of filesystem adapter as follows

return [
    // ...
    'componenets' => [
        // ...
        'flysystem' => [
            'class' => 'airani\flysystem\MountManager',
            'localFs' => [ // https://flysystem.thephpleague.com/adapter/local/
                'class' => 'League\Flysystem\Adapter\Local',
                'root' => __DIR__.'/path/to/too',
            ],
            'ftpFs' => [ // https://flysystem.thephpleague.com/adapter/ftp/
                'class' => 'League\Flysystem\Adapter\Ftp',
                'config' => [
                    'host' => 'ftp.example.com',
                    'username' => 'username',
                    'password' => 'password',

                    // optional config settings
                    'port' => 21,
                    'root' => '/path/to/root',
                    'passive' => true,
                    'ssl' => true,
                    'timeout' => 30,
                ],
            ],
            // and config other filesystem adapters
            // read adapters section of flysystem guide https://flysystem.thephpleague.com
        ],
    ],
];

Usage

To work with MountManager :

// Read from FTP
$contents = Yii::$app->flysystem->read('ftp://some/file.txt');

// And write to local
Yii::$app->flysystem->write('local://put/it/here.txt', $contents);

Or simple usage:

Yii::$app->filesystem->localFs->write('path/to/file.txt', 'contents');

for how to work with flysystem read this api documentation .