stupiddev/flysystem

Flysystem 是 Laravel 5 的 Flysystem 桥接器

v5.1.1 2018-11-09 09:55 UTC

README

注意:这是一个基于 GrahamCampbell/Laravel-Flysystem 的自定义版本

新增功能

  • 你可以自定义连接器。例如,当你想连接 minio/seaweedfs(s3 接口)时。
<?php
/**
 * Minio Connector Class
 * User: hocvt
 * Date: 11/9/18
 * Time: 16:27
 */

namespace App\Colombo\Minio;


use GrahamCampbell\Flysystem\Adapters\AwsS3Connector;

class MinioConnector extends AwsS3Connector {
    
    protected function getAuth( array $config ) {
        
        $auth = parent::getAuth( $config );
        
        if (array_key_exists('use_path_style_endpoint', $config)) {
            $auth['use_path_style_endpoint'] = $config['use_path_style_endpoint'];
        }
        return $auth;
    }
    
}

连接配置

'minio' => [
        'driver'          => \App\Colombo\Minio\MinioConnector::class,
        'key'             => '0NTTRHXQDBWE0N2Y9YEB',
        'secret'          => 'VC7rw7X4nA1ZJgx8SOIoh6fBmQjVl0JFOnk4vkTz',
        'bucket'          => 'local',
        'region'          => '',
        'version'         => 'latest',
        'bucket_endpoint' => false,
        'use_path_style_endpoint' => true,// this will be passed to S3Client
        // 'calculate_md5'   => true,
        // 'scheme'          => 'https',
         'endpoint'        => 'http://127.0.0.1:9000',
//       'prefix'          => '',
        // 'visibility'      => 'public',
        // 'pirate'          => false,
        // 'eventable'       => true,
        // 'cache'           => 'foo'
    ],

Laravel Flysystem 由 Graham Campbell 创建并维护,是一个 Flysystem 桥接器,用于 Laravel 5。它利用了我的 Laravel Manager 包。您可以随意查看 变更日志发布许可贡献指南

Laravel Flysystem

StyleCI Status Build Status Coverage Status Quality Score Software License Latest Version

安装

Laravel Flysystem 需要 PHP 7。此特定版本仅支持 Laravel 5.1、5.2、5.3、5.4 或 5.5。

要获取最新版本,只需使用 Composer 需求项目即可。

$ composer require stupiddev/flysystem

您还需要安装一些其他依赖项,以使用某些功能

  • AwsS3 适配器需要 league/flysystem-aws-s3-v3^1.0)。
  • Azure 适配器需要 league/flysystem-azure^1.0)。
  • Dropbox 适配器需要 spatie/flysystem-dropbox^1.0)。
  • GridFS 适配器需要 league/flysystem-gridfs^1.0)。
  • Rackspace 适配器需要 league/flysystem-rackspace^1.0)。
  • 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 服务提供者,或者如果您正在使用 Laravel 5.5,可以通过自动包发现来完成此操作。

您还可以选择性地对我们的外观进行别名设置

        '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://github.com/thephpleague/flysystem#general-usage的文档,以及管理器类在https://github.com/GrahamCampbell/Laravel-Manager#usage

更多信息

此包中还有其他一些未在此处文档化的类。这是因为它们不是用于公共用途的,而是由本包内部使用。

安全

如果您在此包中发现安全漏洞,请发送电子邮件至Graham Campbell的graham@alt-three.com。所有安全漏洞都将得到及时处理。

许可

Laravel Flysystem采用MIT许可(MIT)