Skip to content

airani/yii2-flysystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 Flysystem Component

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 .

About

Flysystem MountManager as Yii2 Component

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages