graham-campbell / flysystem
Flysystem 是 Laravel 的 Flysystem 桥接器
Requires
- php: ^7.4.15 || ^8.0.2
- graham-campbell/manager: ^4.7
- illuminate/contracts: ^8.75
- illuminate/support: ^8.75
- league/flysystem: ^1.1.9
Requires (Dev)
- alcaeus/mongo-php-adapter: ^1.1
- graham-campbell/analyzer: ^3.1
- graham-campbell/testbench: ^5.6
- league/flysystem-aws-s3-v3: ^1.0
- league/flysystem-azure-blob-storage: ^0.1.6
- league/flysystem-cached-adapter: ^1.0
- league/flysystem-eventable-filesystem: ^1.0
- league/flysystem-gridfs: ^1.0
- league/flysystem-sftp: ^1.0
- league/flysystem-webdav: ^1.0
- league/flysystem-ziparchive: ^1.0
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9.5
- spatie/flysystem-dropbox: ^1.0
- superbalist/flysystem-google-storage: ^7.2
Suggests
- alcaeus/mongo-php-adapter: GridFS adapter support.
- league/flysystem-aws-s3-v3: AwsS3 adapter support.
- league/flysystem-azure-blob-storage: Azure adapter support.
- league/flysystem-cached-adapter: Adapter caching support.
- league/flysystem-eventable-filesystem: Eventable filesystem support.
- league/flysystem-gridfs: GridFS 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.
- spatie/flysystem-dropbox: Dropbox adapter support.
- superbalist/flysystem-google-storage: GoogleCloudStorage adapter support.
- 8.0.x-dev
- v8.0.0
- 7.1.x-dev
- v7.1.2
- v7.1.1
- v7.1.0
- v7.0.1
- v7.0.0
- 6.3.x-dev
- v6.3.1
- v6.3.0
- v6.2.0
- v6.1.0
- v6.0.0
- 5.3.x-dev
- v5.3.0
- v5.2.0
- v5.1.0
- v5.0.0
- 4.1.x-dev
- v4.1.0
- v4.0.0
- 3.7.x-dev
- v3.7.0
- v3.6.0
- v3.5.0
- v3.4.0
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.0
- v2.1.1
- v2.1.0
- v2.0.0
- v1.0.0
- v1.0.0-RC1
- v0.7.0-alpha
- v0.6.2-alpha
- v0.6.1-alpha
- v0.6.0-alpha
- v0.5.2-alpha
- v0.5.1-alpha
- v0.5.0-alpha
- v0.4.0-alpha
- v0.3.0-alpha
- v0.2.0-alpha
- v0.1.0-alpha
This package is auto-updated.
Last update: 2024-08-29 03:58:00 UTC
README
Laravel Flysystem 由 Graham Campbell 创建并维护,是 Laravel 的 Flysystem 桥接器。它使用了我的 Laravel Manager 包。您可以查看 变更日志、发布、安全策略、许可证、行为准则 和 贡献指南。
安装
此版本需要 PHP 7.4-8.1 并支持 Laravel 8。
要获取最新版本,只需使用 Composer 引入项目
$ composer require "graham-campbell/flysystem:^8.0"
还有一些其他依赖项,您需要安装以使用某些功能
- AwsS3 适配器需要
league/flysystem-aws-s3-v3
(^1.0
)。 - Azure 适配器需要
league/flysystem-azure-blob-storage
(^0.1.6
)。 - Dropbox 适配器需要
spatie/flysystem-dropbox
(^1.0
)。 - GoogleCloudStorage 适配器需要
superbalist/flysystem-google-storage
(^7.2
)。 - GridFS 适配器需要
league/flysystem-gridfs
(^1.0
) 和alcaeus/mongo-php-adapter
(^1.1
)。 - Sftp 适配器需要
league/flysystem-sftp
(^1.0
)。 - WebDav 适配器需要
league/flysystem-webdav
(^1.0
)。 - ZipAdapter 适配器需要
league/flysystem-ziparchive
(^1.0
)。 - 适配器缓存支持需要
league/flysystem-cached-adapter
(^1.0
)。 - 可事件化文件系统支持需要
league/flysystem-eventable-filesystem
(^1.0
)。
安装完成后,如果您没有使用自动包发现,则需要在您的 config/app.php
中注册 GrahamCampbell\Flysystem\FlysystemServiceProvider
服务提供者。
您还可以选择性地别名我们的外观
'Flysystem' => GrahamCampbell\Flysystem\Facades\Flysystem::class,
配置
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
中的提供者数组。此类将设置ioc绑定。
真实示例
在这里,您可以看到此包是如何简单易用的。默认适配器为local
,它会立即工作。
use GrahamCampbell\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 GrahamCampbell\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 GrahamCampbell\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 GrahamCampbell\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://flysystem.thephpleague.com/docs/usage/filesystem-api/上的文档,以及管理类在https://github.com/GrahamCampbell/Laravel-Manager#usage。
更多信息
此包中还有其他未在此处记录的类。这是因为它们不是面向公众使用的,而是由该包内部使用。
安全
如果您在此包中发现安全漏洞,请通过security@tidelift.com发送电子邮件。所有安全漏洞都将得到及时解决。您可以在这里查看我们的完整安全策略https://github.com/GrahamCampbell/Laravel-Flysystem/security/policy。
许可
Laravel Flysystem 在The MIT License (MIT)下授权。
企业版
作为Tidelift订阅的一部分提供
graham-campbell/flysystem
及其它数千个软件包的维护者正在与Tidelift合作,为构建应用程序时使用的开源依赖项提供商业支持和维护。节省时间,降低风险,提升代码质量,同时为使用确切的依赖项的维护者付费。了解更多。