callmez/yii2-file-system

This extension provides a filesystem solution for Yii 2.

Installs: 277

Dependents: 1

Suggesters: 0

Security: 0

Stars: 25

Watchers: 4

Forks: 33

Open Issues: 2

Type:yii2-extension

1.01 2014-12-08 08:13 UTC

This package is auto-updated.

Last update: 2024-04-13 02:42:29 UTC


README

Yii2-file-system是 Flysystem基础上基于 Yii2 框架的实现的扩展。 任何存储,统一的函数调用

###扩展存储

  • Qinu 七牛云存储

将要实现的功能 (欢迎PR)

  • 阿里云存储
  • 又拍云存储 (未实现大文件流API[还是老牌存储...], 如果实现功能后.大文件操作会有资源要求)
  • 百度云存储
  • 新浪云存储

使用要求

使用教程

###使用Componser安装 (以下2种方式)

  • 命令行执行 composer require callmez/yii2-file-system

  • 编辑composer.json

    "require": {
        ...
        "callmez/yii2-file-system": "*"
    },

编辑配置文件(2种使用方式)

  • 编辑config/main.php

    'components' => [
      'fileSystem' => [
        'class' => 'callmez\file\system\Collection',
            'fileSystems' => [
                //根据需求可设置多个存储, 以下来使用例子
                'local' => function() {
                    return new \callmez\file\system\FileSystem(
                        new \callmez\file\system\adapters\Local(\Yii::getAlias('@webroot\images'))
                    );
                },
                'qiniu' => function() {
                    return new \callmez\file\system\FileSystem(
                        new \callmez\file\system\adapters\Qiniu(
                            '七牛空间的 bucket',
                            '七牛空间的 access key',
                            '七牛空间的 access secret',
                            '七牛的空间域名,默认为 {bucket}.qiniu.com 选填'
                        )
                    );
                }
            ]
      ]
    ]
  • 使用例子(推荐wrapper方式)

      // 集合方式
      $local = Yii::$app->fileSystem->get('local');
      $local->write('test.txt', 'hello world');
      echo $local->read('test.txt');
      
      $qiniu = Yii::$app->fileSystem->get('qiniu');
      $qiniu->write('test.txt', 'hello world');
      echo $qiniu->read('test.txt');
      
      // wrapper 方式 (推荐)
      //等同于Yii::$app->fileSystem->get('local')->write('test.txt', 'hello world');
      Yii::$app->fileSystem->write('local://test.txt', 'hello world'); 
      //等同于Yii::$app->fileSystem->get('qiniu')->write('test.txt', 'hello world');
      Yii::$app->fileSystem->write('qiniu://test.txt', 'hello world');