* @version : HuoMp 1.0 */ namespace FileSystem; use Xxtime\Flysystem\Aliyun\OssAdapter; use League\Flysystem\Filesystem as LeagueFilesystem; /** * 文件系统工厂类 * Class FileSystem * Usage * * // Write Files * $filesystem->write('path/to/file.txt', 'contents'); * // get RAW data from aliYun OSS * $raw = $aliyun->supports->getFlashData(); * * // Write Use writeStream * $stream = fopen('local/path/to/file.txt', 'r+'); * $result = $filesystem->writeStream('path/to/file.txt', $stream); * if (is_resource($stream)) { * fclose($stream); * } * * // Update Files * $filesystem->update('path/to/file.txt', 'new contents'); * * // Check if a file exists * $exists = $filesystem->has('path/to/file.txt'); * * // Read Files * $contents = $filesystem->read('path/to/file.txt'); * * // Delete Files * $filesystem->delete('path/to/file.txt'); * * // Rename Files * $filesystem->rename('filename.txt', 'newname.txt'); * * // Copy Files * $filesystem->copy('filename.txt', 'duplicate.txt'); * * * @package FileSystem */ class FileSystem { private static $adapter; /** * @param array $config * * @return LeagueFilesystem * @throws \Exception */ public static function create($config = []) { if (empty($config)) { $config = config('filesystem'); } $_default = get_val($config, 'default', 'oss'); try { switch ($_default) { case 'oss': $_driver_config = get_val($config, 'oss', []); $_adapter = new OssAdapter($_driver_config); break; default: $_driver_config = get_val($config, 'oss', []); $_adapter = new OssAdapter($_driver_config); } self::setAdapter($_adapter); $filesystem = new LeagueFilesystem($_adapter); } catch (\Exception $exception) { throw new $exception; } return $filesystem; } /** * @return mixed */ public static function getAdapter() { return self::$adapter; } /** * @param mixed $adapter */ public static function setAdapter($adapter) { self::$adapter = $adapter; } }