argentcrusade / flysystem-selectel
Selectel云存储的Flysystem适配器
Requires
- php: >=5.6
- argentcrusade/selectel-cloud-storage: ~1.1
- league/flysystem: ~1.0
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~5.0
README
需求
此软件包需要PHP 5.6或更高版本。
安装
您可以通过composer安装此软件包
$ composer require argentcrusade/flysystem-selectel
升级
从1.0*到1.1.0
添加了新的设置container_url
。您可以将容器的自定义域名设置在此处(例如,https://static.example.org
),并且在检索文件和目录的完全限定URL时将使用此选项。
使用方法
use ArgentCrusade\Flysystem\Selectel\SelectelAdapter; use ArgentCrusade\Selectel\CloudStorage\Api\ApiClient; use ArgentCrusade\Selectel\CloudStorage\CloudStorage; use League\Flysystem\Filesystem; $api = new ApiClient('selectel-username', 'selectel-password'); $storage = new CloudStorage($api); $container = $storage->getContainer('container-name'); $adapter = new SelectelAdapter($container); $filesystem = new Filesystem($adapter);
Laravel集成
您可以使用此适配器与Laravel的存储系统。
如果您正在运行Laravel 5.5+,此软件包将通过自动发现功能自动添加到您的提供者列表中(需要此软件包的版本1.2+)。
Laravel <= 5.4
将ArgentCrusade\Flysystem\Selectel\SelectelServiceProvider::class
添加到您的config/app.php
中的提供者列表
/* * Package Service Providers... */ ArgentCrusade\Flysystem\Selectel\SelectelServiceProvider::class,
所有Laravel版本
将selectel
磁盘添加到config/filesystems.php
配置文件的disks
部分
'selectel' => [ 'driver' => 'selectel', 'username' => 'selectel-username', 'password' => 'selectel-password', 'container' => 'selectel-container', 'container_url' => 'https://static.example.org', ]
container_url
设置(自1.1.0版本新增)允许您覆盖默认的Selectel CDN域名(如果您附加了自定义域名)。如果您使用默认域名,文件URL将类似于http://XXX.selcdn.ru/container_name/path/to/file.txt
,其中XXX
- 您唯一的子域名(X-Storage-Url
头值)。
现在您可以使用Selectel磁盘作为
use Illuminate\Support\Facades\Storage; Storage::disk('selectel')->put('file.txt', 'Hello world');
您还可以将selectel
设置为默认磁盘,以省略disk('selectel')
调用并像使用存储一样使用Storage::put('file.txt', 'Hello world')
。
有关更多信息,请参阅Laravel的存储系统文档。
不支持的方法
由于Selectel API的实现,一些方法缺失或可能无法按预期工作。
可见性管理
Selectel仅提供容器级别的可见性支持,而不是文件级别的。将整个容器的可见性更改而不是单个文件或目录可能会让适配器用户感到困惑。在getVisibility
/setVisbility
调用中,适配器将抛出LogicException
。
目录管理
目前,Selectel适配器只能显示和删除通过createDir
方法创建的目录。动态目录(通过write
/writeStream
方法创建的目录)不能被删除或列出为目录。
$fs = new Filesystem($adapter); $fs->createDir('images'); // The 'images' directory can be deleted and will be listed as 'dir' in the results of `$fs->listContents()`. $fs->write('documents/hello.txt'); // The 'documents' directory can not be deleted and won't be listed in the results of `$fs->listContents()`.
关于关闭流的说明
Selectel适配器在消耗流后保留流为打开状态。请确保您已关闭您打开的所有流。
变更日志
请参阅CHANGELOG以获取最近更改的更多信息。
测试
$ vendor/bin/phpunit
贡献
请参阅CONTRIBUTING以获取详细信息。
安全性
如果您发现任何安全相关的问题,请通过电子邮件zurbaev@gmail.com报告,而不是使用问题跟踪器。
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。