chleniang/filesystem

TP6 filesystem by flysystem^3.0

v3.0.1 2022-11-14 06:12 UTC

This package is auto-updated.

Last update: 2024-05-14 12:58:33 UTC


README

基于 flysystem ^3.0filesystem

需求

  • php >= 8.0.2 ( league/flysystem ^3.0的要求 )
  • topthink/framework ^6.0 ( 建议使用6.1 移除了TP framework自带的filesystem )
  • league/flysystem ^3.0

安装、使用

composer require "chleniang/filesystem"

  # 方式一: 直接通过facade类使用
  \chleniang\filesystem\facade\Filesystem::disk()
    
  # 方式二: 通过注册服务使用
  # 可直接添加服务到公共文件 `service.php` 文件中 
  return [
    ... ,
    // 注册的服务名是'file_system',与TP的'filesystem'作以区分
    \chleniang\filesystem\Service::class,
  ];
  # 使用服务;
  app('file_system')->disk()

特点

  • 支持 league/flysystem 完整API

    详细请参考 > flysystem API手册 <

      write($path, $contents, $config)
      writeStream($path, $stream, $config)
      read($path)
      readStream($path)
      delete($path)
      deleteDirectory($path)
      listContents($path, $recursive)
      fileExists($path)
      directoryExists($path)
      has($path)
      lastModified($path)
      mimeType($path)
      fileSize($path)
      visibility($path)
      setVisibility($path, $visibility)
      createDirectory($path, $config)
      move($source, $destination, $config)
      copy($source, $destination, $config)
    
  • adapter独有API可直接调用 (如果adapter中API与flysystemAPI重名,优先调用flysystemAPI)

      // 使用方法
      \chleniang\filesystem\facade\Filesystem::disk('qiniu')->[adapter独有API...];
        
      // 实现方式  src/Driver.php
      /**
       * 除filesystem API 之外,adapter中的方法也可直接调用
       *      如果adapter中有与filesystem同名方法,优先调用filesystem中的
       */
      public function __call($method, $parameters)
      {
          if (method_exists($this->filesystem, $method)) {
              return $this->filesystem->$method(...$parameters);
          }
          else {
              return $this->adapter->$method(...$parameters);
          }
      }
    

支持存储类型

本库 chleniang/filesystem 作为支持 TP 文件存储的基础类库,自身带本地存储 local 驱动

其他存储驱动作为独立库存在(没有与本库打包在一起是为了更加灵活,只安装自已需要的)

安装其他存储驱动示例: 七牛云 composer chleniang/filesystem-qiniu

1. 本地存储

( 也可直接使用 topthink/think-filesystem 2.0 )

2. 七牛云

请安装 composer require chleniang/filesystem-qiniu

用法请参考 chleniang/filesystem-qiniu > 使用说明 <

3. 阿里云OSS

请安装 composer require chleniang/filesystem-aliyun-oss

用法请参考 chleniang/filesystem-aliyun-oss > 使用说明 <

4. 其他(待完成)

Lisence