doesntcarewho/modifyed_flysystem

Flysystem 是 Laravel 的 Flysystem 桥接器

v7.1.1 2020-11-27 22:02 UTC

README

Laravel Flysystem 由 GrahamCampbell 创建并维护,是一个Flysystem 桥接器,用于 Laravel。它使用我的 Laravel Manager 包。您可以查看变更日志版本发布安全策略许可行为准则以及贡献指南

Banner

Promo Banner

Build Status StyleCI Status Software License Packagist Downloads Latest Version

安装

Laravel Flysystem 需要 PHP 7.2-8.0。这个特定版本支持 Laravel 6-8。

要获取最新版本,只需使用 Composer 引入项目

$ composer require "graham-campbell/flysystem:^7.1"

还有一些额外的依赖项需要安装以支持某些功能

  • 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

更多信息

此包中还有其他未在此记录的类。这是因为它们不是用于公共用途的,而是由本包内部使用的。

安全

如果你在此包中发现安全漏洞,请发送电子邮件到Graham Campbell的graham@alt-three.com。所有安全漏洞都将得到及时处理。您可以在此查看我们的完整安全策略。

许可

Laravel Flysystem受MIT许可(MIT)许可。

企业版

作为Tidelift订阅的一部分提供

graham-campbell/flysystem的维护者以及成千上万的包维护者正在与Tidelift合作,为构建应用程序时使用的开源依赖项提供商业支持和维护。节省时间,降低风险,并提高代码健康,同时支付您使用的确切依赖项的维护者。了解更多。