icyboy / flysystem
Flysystem 是 Laravel 5 的 Flysystem 桥接器
Requires
- php: >=5.5.9
- graham-campbell/manager: ^2.3
- illuminate/cache: 5.1.*|5.2.*|5.3.*
- illuminate/contracts: 5.1.*|5.2.*|5.3.*
- illuminate/support: 5.1.*|5.2.*|5.3.*
- league/flysystem: ^1.0
Requires (Dev)
- graham-campbell/testbench: ^3.1
- league/flysystem-aws-s3-v3: ^1.0
- league/flysystem-azure: ^1.0
- league/flysystem-cached-adapter: ^1.0
- league/flysystem-copy: ^1.0
- league/flysystem-dropbox: ^1.0
- league/flysystem-eventable-filesystem: ^1.0
- league/flysystem-gridfs: ^1.0
- league/flysystem-rackspace: ^1.0
- league/flysystem-sftp: ^1.0
- league/flysystem-webdav: ^1.0
- league/flysystem-ziparchive: ^1.0
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^4.8|^5.0
Suggests
- league/flysystem-aws-s3-v3: AwsS3 adapter support.
- league/flysystem-azure: Azure adapter support.
- league/flysystem-cached-adapter: Adapter caching support.
- league/flysystem-copy: Copy adapter support.
- league/flysystem-dropbox: Dropbox adapter support.
- league/flysystem-eventable-filesystem: Eventable filesystem support.
- league/flysystem-gridfs: GridFS adapter support.
- league/flysystem-rackspace: Rackspace adapter support.
- league/flysystem-replicate-adapter: Replicate adapter support.
- league/flysystem-sftp: Sftp adapter support.
- league/flysystem-webdav: WebDav adapter support.
- league/flysystem-ziparchive: ZipArchive adapter support.
This package is not auto-updated.
Last update: 2024-09-15 02:16:44 UTC
README
安装
需要 PHP 5.5+ 或 HHVM 3.6+。
要获取 Laravel Flysystem 的最新版本,只需使用 Composer 引入项目即可。
$ composer require icyboy/flysystem
当然,您也可以手动更新 require 块并运行 composer update
。
{ "require": { "icyboy/flysystem": "^3.0" } }
您还需要安装一些额外的依赖项才能使用某些功能。
- AwsS3 适配器需要在您的
composer.json
中包含"league/flysystem-aws-s3-v3": "^1.0"
。 - Azure 适配器需要在您的
composer.json
中包含"league/flysystem-azure": "^1.0"
。 - Copy 适配器需要在您的
composer.json
中包含"league/flysystem-copy": "^1.0"
。 - Dropbox 适配器需要在您的
composer.json
中包含"league/flysystem-dropbox": "^1.0"
。 - GridFS 适配器需要在您的
composer.json
中包含"league/flysystem-gridfs": "^1.0"
。 - Rackspace 适配器需要在您的
composer.json
中包含"league/flysystem-rackspace": "^1.0"
。 - Sftp 适配器需要在您的
composer.json
中包含"league/flysystem-sftp": "^1.0"
。 - WebDav 适配器需要在您的
composer.json
中包含"league/flysystem-webdav": "^1.0"
。 - ZipAdapter 适配器需要在您的
composer.json
中包含"league/flysystem-ziparchive": "^1.0"
。 - 适配器缓存支持需要在您的
composer.json
中包含"league/flysystem-cached-adapter": "^1.0"
。 - 事件文件系统支持需要在您的
composer.json
中包含"league/flysystem-eventable-filesystem": "^1.0"
。
一旦安装了 Laravel Flysystem,您需要注册服务提供者。打开 config/app.php
并将以下内容添加到 providers
键中。
'Icyboy\Flysystem\FlysystemServiceProvider'
您还可以在 config/app.php
文件的 aliases
键中注册 Flysystem facades。
'Flysystem' => 'Icyboy\Flysystem\Facades\Flysystem'
配置
Laravel Flysystem 需要连接配置。
要开始,您需要发布所有供应商资产
$ php artisan vendor:publish
这将在您的应用程序中创建一个 config/flysystem.php
文件,您可以修改它来设置配置。同时,请确保检查本包发布之间原始配置文件的变化。
有三个配置选项
默认连接名称
此选项('default'
)是您指定要使用的以下连接中的哪一个作为您所有工作的默认连接的地方。当然,您可以使用管理类一次使用多个连接。此设置的默认值为 'local'
。
Flysystem 连接
此选项('connections'
)是您为应用程序设置的每个连接。配置文件中包含了配置每个支持的驱动程序的示例。当然,您可以为每个驱动程序有多个连接。
Flysystem 缓存
此选项('cache'
)是您为应用程序设置的每个缓存配置。目前有两个驱动程序:illuminate 和 adapter。其中包含了配置示例。当然,您可以为每个驱动程序有多个连接,如示例所示。
用法
FlysystemManager
这是最有兴趣的类。它绑定到IoC容器上的 'flysystem'
,可以通过使用 Facades\Flysystem
外观来访问。这个类通过扩展 AbstractManager
实现了 ManagerInterface
接口。接口和抽象类都是我 Laravel Manager 包的一部分,因此你可能想去检查如何在 该仓库 中使用管理器类。请注意,返回的连接类将始终是实现了 \League\Flysystem\FilesystemInterface
的类的实例,默认情况下是 \League\Flysystem\Filesystem
类。
Facades\Flysystem
这个外观将动态地将静态方法调用传递给IoC容器中的 'flysystem'
对象,默认情况下是 FlysystemManager
类。
FlysystemServiceProvider
这个类不包含任何感兴趣的公开方法。这个类应该被添加到 config/app.php
中的 providers 数组。这个类将设置IoC绑定。
真实示例
在这里,你可以看到一个示例,说明这个包有多简单易用。开箱即用,默认适配器是 local
,它将立即开始工作
use Icyboy\Flysystem\Facades\Flysystem; // you can alias this in config/app.php if you like Flysystem::put('hi.txt', 'foo'); // we're done here - how easy was that, it just works! Flysystem::read('hi.txt'); // this will return foo
Flysystem管理器将表现得像是一个 \League\Flysystem\Filesystem
类。如果你想调用特定的连接,你可以使用 connection
方法
use Icyboy\Flysystem\Facades\Flysystem; // note the foo connection does not ship with this package, it's hypothetical Flysystem::connection('foo')->put('test.txt', 'bar'); // now we can read that file Flysystem::connection('foo')->read('test.txt'); // this will return bar
考虑到这一点,请注意
use Icyboy\Flysystem\Facades\Flysystem; // writing this: Flysystem::connection('local')->read('test.txt'); // is identical to writing this: Flysystem::read('test.txt'); // and is also identical to writing this: Flysystem::connection()->read('test.txt'); // this is because the local connection is configured to be the default Flysystem::getDefaultConnection(); // this will return local // we can change the default connection Flysystem::setDefaultConnection('foo'); // the default is now foo
如果你像我一样喜欢使用依赖注入而不是外观,那么你可以轻松地按照以下方式注入管理器
use Icyboy\Flysystem\FlysystemManager; use Illuminate\Support\Facades\App; // you probably have this aliased already class Foo { protected $flysystem; public function __construct(FlysystemManager $flysystem) { $this->flysystem = $flysystem; } public function bar() { $this->flysystem->read('test.txt'); } } App::make('Foo')->bar();
有关如何使用我们在这里调用的幕后 \League\Flysystem\Filesystem
类的更多信息,请参阅 https://github.com/thephpleague/flysystem#general-usage 上的文档,以及管理器类在 https://github.com/Icyxp/Laravel-Manager#usage 上的文档。
更多信息
这个包中还有其他一些类没有在这里记录。这是因为它们不是为了公开使用而设计的,而是由这个包内部使用的。
安全
如果你在这个包中发现安全漏洞,请发送电子邮件至 Graham Campbell 的 graham@alt-three.com。所有安全漏洞都将得到及时处理。
许可证
Laravel Flysystem 在 MIT 许可证 (MIT) 下授权。