slivka-b / flysystem-selectel
针对Selectel云存储的Flysystem适配器
Requires
- php: >=5.6
- league/flysystem: ~1.0
- slivka-b/selectel-cloud-storage: ^1.2
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~5.0
This package is not auto-updated.
Last update: 2024-09-26 02:59:01 UTC
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)。请参阅许可文件以获取更多信息。