ajgl/flysystem-replicate

Flysystem 复制适配器

2.2.0 2022-10-28 09:06 UTC

This package is auto-updated.

Last update: 2024-09-16 23:20:26 UTC


README

此包是从原版 league/flysystem-replicate-adapter 分支出来的,由 @frankdejonge 编写。目标是支持 Flysystem V2 和 V3。

如果你使用 Flysystem 1.x,请使用 ajgl/flysystem-replicate 1.x

安装

composer require ajgl/flysystem-replicate

用法

$source = new League\Flysystem\AwsS3V3\AwsS3V3Adapter(...);
$replica = new League\Flysystem\Local\LocalFilesystemAdapter(...);
$adapter = new Ajgl\Flysystem\Replicate\ReplicateFilesystemAdapter($source, $replica);

这个功能很酷,你可以将它们串联起来,复制到多个其他存储系统。

$adapter = new Ajgl\Flysystem\Replicate\ReplicateFilesystemAdapter($source, $replica);

$anotherReplica = new League\Flysystem\WebDAV\WebDAVAdapter(...);
$adapter = new Ajgl\Flysystem\Replicate\ReplicateFilesystemAdapter($adapter, $anotherReplica);

使用 league/flysystem-bundle 的 Symfony

如果你的 Symfony 应用程序已安装了 league/flysystem-bundle,你必须定义一个复制适配器服务,引用你的源和副本存储。

# config/services.yaml
services:
    app.replicate.storage:
        class: Ajgl\Flysystem\Replicate\ReplicateFilesystemAdapter
        arguments: ['@flysystem.adapter.source.storage', '@flysystem.adapter.replica.storage']

然后,你必须在 league/flysystem-bundle 配置中定义一个自定义适配器。

# config/packages/flysystem.yaml
flysystem:
    storages:
        source.storage:
            adapter: 'local'
            options:
                directory: '%kernel.project_dir%/var/storage'
        replica.storage:
            adapter: 'aws'
            options:
                client: 'aws.client'
                bucket: 'storage'
        replicate.storage:
            adapter: 'app.replicate.storage'