| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace app\extra\tools;
- use app\extra\service\basic\UploadService;
- use Tinywan\Storage\Storage;
- /**
- * @see Storage
- * @mixin Storage
- *
- * @method static array uploadFile(array $config = []) 上传文件
- * @method static array uploadBase64(string $base64, string $extension = 'png') 上传Base64文件
- * @method static array uploadServerFile(string $file_path) 上传服务端文件
- */
- class UploadExtend
- {
- /**
- * 本地对象存储.
- */
- public const MODE_LOCAL = 'local';
- /**
- * 阿里云对象存储.
- */
- public const MODE_OSS = 'oss';
- /**
- * 腾讯云对象存储.
- */
- public const MODE_COS = 'cos';
- /**
- * 七牛云对象存储.
- */
- public const MODE_QINIU = 'qiniu';
- /**
- * S3对象存储.
- */
- public const MODE_S3 = 's3';
- protected array $config = [];
- /**
- * Support Storage
- */
- static $allowStorage = [
- self::MODE_LOCAL,
- self::MODE_OSS,
- self::MODE_COS,
- self::MODE_QINIU,
- self::MODE_S3
- ];
- /**
- * 存储磁盘
- * @param string|null $name
- * @param bool $_is_file_upload
- * @return mixed
- * @author Tinywan(ShaoBo Wan)
- */
- public static function disk(string $name = null, bool $_is_file_upload = true)
- {
- $storage = $name ?? self::getDefaultStorage();
- $config = self::getConfig($storage);
- return new $config['adapter'](array_merge(
- $config, ['_is_file_upload' => $_is_file_upload]
- ));
- }
- /**
- * 默认存储
- * @return mixed
- * @author Tinywan(ShaoBo Wan)
- */
- public static function getDefaultStorage()
- {
- return self::getConfig('default');
- }
- /**
- * 获取存储配置
- * @param string|null $name 名称
- * @return mixed
- * @author Tinywan(ShaoBo Wan)
- */
- public static function getConfig(string $name = null)
- {
- $config = (new UploadService)->setConfigVal();
- if (!is_null($name)) {
- return $config['storage'][$name];
- // return config('plugin.tinywan.storage.app.storage.' . $name, self::MODE_LOCAL);
- }
- return $config['storage']["default"];
- // return config('plugin.tinywan.storage.app.storage.default');
- }
- /**
- * 配置信息
- * @param array $config
- */
- public function config(array $config)
- {
- $this->$config = $config;
- return $this;
- }
- /**
- * @param $name
- * @param $arguments
- * @return mixed
- * @author Tinywan(ShaoBo Wan)
- */
- public static function __callStatic($name, $arguments)
- {
- return static::disk()->{$name}(...$arguments);
- }
- }
|