wearesho-team / yii2-filesystem
Yii2 integration for league/flysystem
Requires
- php: >=7.4
- horat1us/yii2-environment-config: ^1.1
- league/flysystem: ^1.1.4
- league/flysystem-aws-s3-v3: ^1.0
- yiisoft/yii2: ^2.0.40
Requires (Dev)
- horat1us/yii2-asset-free: ^1.0
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
README
Integration of league/flysystem for Yii2.
It is configured by environment variables by default. Available integration out-of-box:
- FTP - should be used in deprecated systems
- Local - should be used for development
- S3 - should be used in production
Configuring
By-default configuring available using environment variables. To choose which integration to use you need to configure FILESYSTEM_ADAPTER variable. Available values: local, ftp, s3. (or another, if you use custom bootstrap configuration)
Configuring S3 adapter
Configuring Local adapter
Configuring Ftp adapter
Configuring Replica adapter
This adapter purpose of mirroring files on few adapters (any AdapterInterface implementation)
<?php use Wearesho\Yii\Filesystem; $adapter = new Filesystem\Replica\Adapter([ 'master' => [ 'class' => Filesystem\S3\Adapter::class, ], 'slaves' => [ // so much slaves [ 'class' => Filesystem\Ftp\Adapter::class, ], ], ]);
Usage
Bootstrap
To start use this package out-of-box you need to append Bootstrap into your Yii2 application.
<?php // common/config/main.php or another configuration file use Wearesho\Yii\Filesystem; return [ 'components' => [ // ... ], 'bootstrap' => [ 'class' => Filesystem\Bootstrap::class, 'container' => true, // if you need to configure global DI container (\Yii::$container) 'id' => 'fs', // \Yii::$app component to be configured. Filesystem will be available using \Yii::$app->fs ], ];
Note: for advanced usage you may customize Bootstrap adapters and config properties
Filesystem Class
You can also use Filesystem class for yii2-way configuration:
<?php use Wearesho\Yii\Filesystem\Filesystem; use Wearesho\Yii\Filesystem\AdapterInterface; $fs = new Filesystem([ 'adapter' => [ 'class' => AdapterInterface::class, // or another implementation, if container not configured ], ]);
TODO
- Tests