初始化

This commit is contained in:
2026-03-02 13:44:38 +08:00
commit 05b785083c
677 changed files with 58662 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
<?php
namespace addons\webman\filesystem;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Filesystem;
interface AdapterFactoryInterface
{
/**
* @return AdapterInterface|Filesystem
*/
public function make(array $options);
}

View File

@@ -0,0 +1,38 @@
<?php
namespace addons\webman\filesystem;
use Illuminate\Filesystem\FilesystemAdapter;
class Filesystem
{
/**
* @param string|null $disk
* @return FilesystemAdapter
*/
public function driver(string $disk = null): FilesystemAdapter
{
$disk = $disk ?: config('plugin.rockys.ex-admin-webman.filesystems.default');
$config = config('plugin.rockys.ex-admin-webman.filesystems.disks.'.$disk);
$driver = (new $config['driver'])->make($config);
if($driver instanceof \League\Flysystem\Filesystem){
$filesystem = $driver;
}else{
$filesystem = new \League\Flysystem\Filesystem($driver,$config);
}
return new FilesystemAdapter($filesystem);
}
public static function __callStatic($name, $arguments)
{
$self = new static();
if($name == 'disk'){
return $self->driver(...$arguments);
}else{
return $self->driver()->$name(...$arguments);
}
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace addons\webman\filesystem\driver;
use addons\webman\filesystem\AdapterFactoryInterface;
class Local implements AdapterFactoryInterface
{
public function make(array $options)
{
return new \League\Flysystem\Adapter\Local($options['root'], $options['lock'] ?? LOCK_EX);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace addons\webman\filesystem\driver;
use addons\webman\filesystem\AdapterFactoryInterface;
use Iidestiny\Flysystem\Oss\OssAdapter;
use Iidestiny\Flysystem\Oss\Plugins\FileUrl;
use Iidestiny\Flysystem\Oss\Plugins\Kernel;
use Iidestiny\Flysystem\Oss\Plugins\SetBucket;
use Iidestiny\Flysystem\Oss\Plugins\SignatureConfig;
use Iidestiny\Flysystem\Oss\Plugins\SignUrl;
use Iidestiny\Flysystem\Oss\Plugins\TemporaryUrl;
use Iidestiny\Flysystem\Oss\Plugins\Verify;
use League\Flysystem\Filesystem;
class Oss implements AdapterFactoryInterface
{
public function make(array $options)
{
$root = $options['root'] ?? null;
$buckets = isset($options['buckets'])?$options['buckets']:[];
$adapter = new OssAdapter(
$options['access_key'],
$options['secret_key'],
$options['endpoint'],
$options['bucket'],
$options['isCName'],
$root,
$buckets
);
$filesystem = new Filesystem($adapter);
$filesystem->addPlugin(new FileUrl());
$filesystem->addPlugin(new SignUrl());
$filesystem->addPlugin(new TemporaryUrl());
$filesystem->addPlugin(new SignatureConfig());
$filesystem->addPlugin(new SetBucket());
$filesystem->addPlugin(new Verify());
$filesystem->addPlugin(new Kernel());
return $filesystem;
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace addons\webman\filesystem\driver;
use addons\webman\filesystem\AdapterFactoryInterface;
use League\Flysystem\Filesystem;
use Overtrue\Flysystem\Qiniu\Plugins\FetchFile;
use Overtrue\Flysystem\Qiniu\Plugins\FileUrl;
use Overtrue\Flysystem\Qiniu\Plugins\PrivateDownloadUrl;
use Overtrue\Flysystem\Qiniu\Plugins\RefreshFile;
use Overtrue\Flysystem\Qiniu\Plugins\UploadToken;
use Overtrue\Flysystem\Qiniu\QiniuAdapter;
class Qiniu implements AdapterFactoryInterface
{
public function make(array $options)
{
$adapter = new QiniuAdapter(
$options['access_key'], $options['secret_key'],
$options['bucket'], $options['domain']
);
$flysystem = new Filesystem($adapter);
$flysystem->addPlugin(new FetchFile());
$flysystem->addPlugin(new UploadToken());
$flysystem->addPlugin(new FileUrl());
$flysystem->addPlugin(new PrivateDownloadUrl());
$flysystem->addPlugin(new RefreshFile());
return $flysystem;
}
}