thadbryson / flysystem-sync
Flysystem 目录同步包装器。
v3.0.1
2022-04-11 16:12 UTC
Requires
- php: ^7.2 || ^8.0
- league/flysystem: >=2.0
Requires (Dev)
- phpunit/phpunit: ^8.5 || ^9.4
This package is auto-updated.
Last update: 2024-09-16 12:31:53 UTC
README
关于
这是 Flysystem 2 和 3 版本的包装器。注意,v1.* 是 Flysystem v1.* 的插件。
安装
使用 Composer
"thadbryson/flysystem-sync": ">=2.0"
支持 PHP 7.2 及以上版本。
它可以帮助您同时同步两个目录。有两种目录类型。
主目录
此目录的内容将移动到从目录进行写入和更新。如果此文件夹的路径在从目录中不存在,则从目录中的路径将被删除。
从目录
目标目录。事物将移动到这里或从这里删除。
如何使用
以下是一些设置示例代码。
use TCB\FlysystemSync\Sync; use League\Flysystem\Filesystem; use League\Flysystem\Local\LocalFilesystemAdapter as Adapter; // Setup file system. $master = new Filesystem(new Adapter(__DIR__ . '/sync-test/master')); $slave = new Filesystem(new Adapter(__DIR__ . '/sync-test/slave')); // Create the Sync object. Use root directory. That '/' variable can be any subpath directory. $sync = new Sync($master, $slave, $config = [], $directory = '/'); // Here is how to actually sync things. // Add all folders and files ON MASTER and NOT ON SLAVE. $sync->syncWrites(); // Delete all folders and files NOT ON MASTER and on SLAVE. $sync->syncDeletes(); // Update all folders and files that are on both MASTER and SLAVE. $sync->syncUpdates(); // This will do ->syncWrites(), ->syncDeletes(), and ->syncUpdates(). $sync->sync(); // And you can get what all these paths are going to be separately. $paths = $sync->getUtil()->getWrites(); // On Master but not on Slave. $paths = $sync->getUtil()->getDeletes(); // On Slave but not on Master. $paths = $sync->getUtil()->getUpdates(); // On both Master and Slave but with different properties.
示例路径数组
array(2) {
'create-dir/' => \League\Flysystem\DirectoryAttributes,
'create-dir/3.php' => \League\Flysystem\FileAttributes
}
这是 var_dump() 的一个示例,展示了路径将提供的内容。