artpetrov/flysystem-selectel

Selectel云存储的Flysystem适配器

2.0.2 2019-08-09 22:21 UTC

This package is auto-updated.

Last update: 2024-09-10 09:56:24 UTC


README

要求

此包需要PHP 7.3。

安装

您可以通过composer安装此包

$ composer require artPetrov/flysystem-selectel

升级

从1.0*到1.1.0

新增设置 container_url。您可以将容器的自定义域名设置在这里(例如,https://static.example.org),在检索文件的完全限定URL时将使用此选项。

用法

use ArtPetrov\Flysystem\Selectel\SelectelAdapter;
use ArtPetrov\Selectel\CloudStorage\Api\ApiClient;
use ArtPetrov\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);

Symfony 4.3集成

services.yaml

services:

  openstack.selectel.client:
    class: ArtPetrov\Selectel\CloudStorage\Api\ApiClient
    arguments: ['%env(SELECTEL_USERNAME)%','%env(SELECTEL_PASSWORD)%','%env(SELECTEL_AUTH_PATH)%']

  ArtPetrov\Selectel\CloudStorage\CloudStorage:
    arguments: ['@openstack.selectel.client']

  openstack.selectel.storage_container:
    class: ArtPetrov\Selectel\CloudStorage\CloudStorage
    factory: ['@ArtPetrov\Selectel\CloudStorage\CloudStorage','getContainer']
    arguments: ['%env(SELECTEL_CONTAINER_NAME)%']

  ArtPetrov\Flysystem\Selectel\SelectelAdapter:
    arguments:
      $container: '@openstack.selectel.storage_container'

packages/oneup_flysystem.yaml

oneup_flysystem:
  adapters:
    public_uploads_adapter:
      custom:
        service: ArtPetrov\Flysystem\Selectel\SelectelAdapter

  filesystems:
    public_uploads_filesystem:
      adapter: public_uploads_adapter

Laravel集成

您可以使用此适配器与Laravel的存储系统

如果您正在运行Laravel 5.5+,此包将通过自动发现功能自动添加到您的提供者列表中(需要此包的1.2+版本)。

Laravel <= 5.4

ArtPetrov\Flysystem\Selectel\SelectelServiceProvider::class 添加到您的 config/app.php 中的提供者列表

/*
 * Package Service Providers...
 */
ArtPetrov\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

许可

MIT许可证(MIT)。有关更多信息,请参阅许可文件