2amigos / yii2-flysystem-component
League Flysystem 对 Yii 框架的集成
Requires
- league/flysystem: ^1.0
- yiisoft/yii2: *
Requires (Dev)
- cedricziel/flysystem-gcs: ^1.1
- friendsofphp/php-cs-fixer: ^2.0
- league/flysystem-aws-s3-v3: ^1.0
- league/flysystem-azure: ^1.0
- league/flysystem-cached-adapter: ^1.0
- league/flysystem-gridfs: ^1.0
- league/flysystem-memory: ^1.0
- league/flysystem-rackspace: ^1.0
- league/flysystem-replicate-adapter: ^1.0
- league/flysystem-sftp: ^1.0
- league/flysystem-webdav: ^1.0
- league/flysystem-ziparchive: ^1.0
- phpmd/phpmd: @stable
- phpunit/phpunit: ^5.0
- spatie/flysystem-dropbox: ^1.0
- squizlabs/php_codesniffer: *
This package is auto-updated.
Last update: 2023-08-16 03:11:14 UTC
README
Flysystem 是一个文件系统抽象,允许您轻松地将本地文件系统与远程文件系统进行交换。
此组件库提供组件,将 Flysystem API 暴露给您的 Yii 2 应用程序。以下是目前支持的内容
- AwsS3FsComponent:与 Amazon S3 存储桶交互。
- AzureFsComponent:与 Microsoft Azure 交互。
- DropboxFsComponent:与 Dropbox 交互。
- FtpFsComponent:与 FTP 服务器交互。
- GoogleCloudFsComponent:与 Google Cloud Storage 交互。
- GridFSFsComponent:与 GridFS 交互。
- LocalFsComponent:与您的本地服务器存储交互。
- MemoryFsComponent:与内存交互。当您不想持久化任何内容时很有用。
- NullFsComponent:用于测试。
- RackspaceFsComponent:与 Rackspace 交互。
- SftpFsComponent:与 Sftp 服务器交互。
- WebDAVFsComponent:与 WebDAV 交互。
- ZipArchiveFsComponent:与 zip 归档交互。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令
$ composer require 2amigos/yii2-flysystem-component
或将其添加到 composer.json
文件的 require
部分。
"2amigos/yii2-flysystem-component": "^1.0"
使用方法
AwsS3FsComponent
安装依赖
$ composer require league/flysystem-aws-s3-v3
在应用程序的 components
部分进行配置
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\AwsS3FsComponent', 'key' => 'your-key', 'secret' => 'your-secret', 'bucket' => 'your-bucket', 'region' => 'your-region', // 'version' => 'latest', // 'baseUrl' => 'your-base-url', // 'prefix' => 'your-prefix', // 'options' => [], ], ], ];
当您的应用程序运行时,您将能够使用该组件作为
Yii::$app->fs->read(....);
检查 http://flysystem.thephpleague.com/api/ 以获取所有可用方法。所有适配器都使用相同的方法。
AzureFsComponent
首先确保已将 pear 存储库添加到您的 composer.json
文件中
"repositories": [
{
"type": "pear",
"url": "http://pear.php.net"
}
],
然后安装插件的最新版本
$ composer require league/flysystem-azure
在应用程序的 components
部分进行配置
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\AzureFsComponent', 'accountName' => 'your-account-name', 'accountKey' => 'your-account-key', 'container' => 'your-container', ], ], ];
DropboxFsComponent
安装依赖
$ composer require spatie/flysystem-dropbox
在应用程序的 components
部分进行配置
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\DropboxFsComponent', 'token' => 'your-access-token', // 'prefix' => 'your-prefix', ], ], ];
FtpFsComponent
按以下方式配置应用程序的 components
return [ //... 'components' => [ //... 'ftpFs' => [ 'class' => 'dosamigos\flysystem\FtpFsComponent', 'host' => 'ftp.example.com', // 'port' => 21, // 'username' => 'your-username', // 'password' => 'your-password', // 'ssl' => true, // 'timeout' => 60, // 'root' => '/path/to/root', // 'permPrivate' => 0700, // 'permPublic' => 0744, // 'passive' => false, // 'transferMode' => FTP_TEXT, ], ], ];
GoogleCloudFsComponent
安装依赖
$ composer require cedricziel/flysystem-gcs
在应用程序的 components
部分进行配置
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\GoogleCloudFsComponent', 'projectId' => 'your-project-id', 'bucket' => 'your-bucket', // 'prefix' => 'your-prefix', ], ], ];
GridFSFsComponent
安装依赖
$ composer require league/flysystem-gridfs
在应用程序的 components
部分进行配置
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\GridFSFsComponent', 'server' => 'mongodb://localhost:27017', 'database' => 'your-database', ], ], ];
LocalFsComponent
按以下方式配置应用程序的 components
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\LocalFsComponent', 'path' => '@webroot/your-writable-folder-to-save-files', ], ], ];
MemoryFsComponent
安装依赖
$ composer require league/flysystem-memory
按以下方式配置应用程序的 components
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\MemoryFsComponent', ], ], ];
NullFsComponent
按以下方式配置应用程序的 components
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\NullFsComponent', ], ], ];
RackspaceFsComponent
安装依赖
$ composer require league/flysystem-rackspace
按以下方式配置应用程序的 components
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\RackspaceFsComponent', 'endpoint' => 'your-endpoint', 'region' => 'your-region', 'username' => 'your-username', 'apiKey' => 'your-api-key', 'container' => 'your-container', // 'prefix' => 'your-prefix', ], ], ];
SftpFsComponent
安装依赖
$ composer require league/flysystem-sftp
按以下方式配置应用程序的 components
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\SftpFsComponent', 'host' => 'sftp.example.com', 'username' => 'your-username', 'password' => 'your-password', 'privateKey' => '/path/to/or/contents/of/privatekey', // 'port' => 22, // 'timeout' => 60, // 'root' => '/path/to/root', // 'permPrivate' => 0700, // 'permPublic' => 0744, ], ], ];
WebDAVFsComponent
安装依赖
$ composer require league/flysystem-webdav
按以下方式配置应用程序的 components
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\WebDAVFsComponent', 'baseUri' => 'your-base-uri', // 'userName' => 'your-user-name', // 'password' => 'your-password', // 'proxy' => 'your-proxy', // 'authType' => \Sabre\DAV\Client::AUTH_BASIC, // 'encoding' => \Sabre\DAV\Client::ENCODING_IDENTITY, // 'prefix' => 'your-prefix', ], ], ];
ZipArchiveFsComponent
安装依赖
$ composer require league/flysystem-ziparchive
按以下方式配置应用程序的 components
return [ //... 'components' => [ //... 'fs' => [ 'class' => 'dosamigos\flysystem\ZipArchiveFsComponent', 'path' => '@webroot/files/archive.zip', // 'prefix' => 'your-prefix', ], ], ];
酷炫功能
多实例
您可以配置所需数量的组件。只需将它们添加到components
部分,并使用不同的名称。例如,我可以同时使用S3和FTP。
return [ //... 'components' => [ //... 's3Fs' => [ 'class' => 'dosamigos\flysystem\AwsS3FsComponent', 'key' => 'your-key', 'secret' => 'your-secret', 'bucket' => 'your-bucket', 'region' => 'your-region', // 'version' => 'latest', // 'baseUrl' => 'your-base-url', // 'prefix' => 'your-prefix', // 'options' => [], ], 'ftpFs => [ 'class' => 'dosamigos\flysystem\FtpFsComponent', 'host' => 'ftp.example.com', ] ], ];
现在,我可以分别使用Yii::$app->s3Fs
和Yii::$app->ftpFs
。
缓存
如果您想添加缓存功能,首先需要在您的composer.json
文件中包含依赖项。
$ composer require league/flysystem-cached-adapter
然后,在适配器上配置以下属性:
return [ //... 'components' => [ //... 'fs' => [ //... 'cache' => 'cacheID', // 'cacheKey' => 'my-cache-key', // 'cacheDuration' => 7200, ], ], ];
复制
复制功能简化了适配器之间的转换,使应用程序保持功能,并允许将文件从一个适配器迁移到另一个适配器。适配器采用两个其他适配器,即源适配器和副本适配器。所有更改都委托给这两个适配器,而所有读取操作仅传递给源适配器。
要使用复制功能,首先安装其依赖项。
$ composer require league/flysystem-replicate-adapter
然后,按照以下方式进行配置:
return [ //... 'components' => [ //... 's3Fs' => [ 'class' => 'dosamigos\flysystem\AwsS3FsComponent', 'key' => 'your-key', 'secret' => 'your-secret', 'bucket' => 'your-bucket', 'region' => 'your-region', ], 'ftpFs => [ 'class' => 'dosamigos\flysystem\FtpFsComponent', 'host' => 'ftp.example.com', 'replica' => 's3Fs' // we have added the ID of the replica component ] ], ];
更多信息
测试
$ phpunit
使用代码修复工具
我们添加了一个PHP代码修复工具来标准化我们的代码。它包括Symfony、PSR2和一些贡献者规则。
./vendor/bin/php-cs-fixer fix ./src --config .php_cs
贡献
有关详细信息,请参阅CONTRIBUTING。
致谢
许可证
BSD许可证(BSD)。有关更多信息,请参阅许可证文件。
定制软件 | 网络和移动软件开发
www.2amigos.us