2amigos/yii2-flysystem-component

此包已被废弃,不再维护。未建议替代包。

League Flysystem 对 Yii 框架的集成


README

Latest Stable Version Software License Build Status Quality Score Total Downloads

Flysystem 是一个文件系统抽象,允许您轻松地将本地文件系统与远程文件系统进行交换。

此组件库提供组件,将 Flysystem API 暴露给您的 Yii 2 应用程序。以下是目前支持的内容

安装

安装此扩展的首选方式是通过 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->s3FsYii::$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)。有关更多信息,请参阅许可证文件

687474703a2f2f7777772e67726176617461722e636f6d2f6176617461722f35353336333339346437323934356666376564333132353536656330343165302e706e67
定制软件 | 网络和移动软件开发
www.2amigos.us