2017 © Pedro Peláez
 

yii2-extension yii2-qiniu

The Qiniu integration for the Yii framework

image

dcb9/yii2-qiniu

The Qiniu integration for the Yii framework

  • Friday, October 14, 2016
  • by bobchengbin
  • Repository
  • 2 Watchers
  • 15 Stars
  • 1,461 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 1 Open issues
  • 10 Versions
  • 1 % Grown

The README.md

Qiniu Extension for Yii2

The Qiniu integration for the Yii framework, (*1)

Build Status Code Climate Issue Count Latest Stable Version Total Downloads License, (*2)

CHANGE LOG, (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

composer require --prefer-dist dcb9/yii2-qiniu

or add, (*6)

"dcb9/yii2-qiniu": "*"

to the require section of your composer.json., (*7)

Configuration

To use this extension, simply add the following code in your application configuration:, (*8)

return [
    //....
    'components' => [
        'qiniu' => [
            'class' => 'dcb9\qiniu\Component',
            'accessKey' => 'YOUR_ACCESS_KEY',
            'secretKey' => 'YOUR_SECRET_KEY',
            'disks' => [
                'testBucket' => [
                    'bucket' => 'bucketOnQiniu',
                    'baseUrl' => 'ACCESS_QINIU_URL',
                    'isPrivate' => true,
                    'zone' => 'zone0', // 可设置为 zone0, zone1 @see \Qiniu\Zone
                ],
            ],
        ],
    ],
];

资源操作

资源操作就 Flysystem 的一个扩展, 所以所有的调用方法与 Flysystem 调用方法一致., (*9)

// 获取 Disk
$filesystem = Yii::$app->qiniu->getDisk('testBucket');

$filesystem->has('hello.txt');

// 七牛独有 API
$filesystem->getUrl('hello.txt');  // 获取访问地址

其它所有可调用的 API, (*10)

上传策略

默认设置 Policy 是使用 Array 的方式来设置的, 但是这种方式对程序员不是很友好,于是创建了一个 Policy 的类,但所有的操作还是跟操作数组一样., (*11)

$policy = new \dcb9\qiniu\Policy();
$policy->callbackUrl = '';
$policy->callbackBody = '';

获取 UploadToken

$qiniu = Yii::$app->qiniu;

$diskName = 'testBucket';
$token1 = $qiniu->getUploadToken($diskName);

$key = null;
$expires = 3600;
$policy = new \dcb9\qiniu\Policy();
$policy->callbackUrl = '';
$policy->callbackBody = '';

// Fop @see src/Pfop.php
$policy->persistentOps = \dcb9\qiniu\Pfop::instance()
    ->avthumb('mp4')
    ->wmImage('http://o82pobmde.bkt.clouddn.com/yii2-logo.png')
    ->saveas('testbucket', 'after-ops' . date('Y-m-d H:i:s') . '.mp4')
    ->__toString();
$policy->persistentNotifyUrl = 'http://blog.phpor.me';

$diskName = 'testBucket';
$token2 = $qiniu->getUploadToken($diskName, $key, $expires, $policy);

使用 Token 上传文件

$token = '<TOKEN>'; // @see 获取 UploadToken
$config = ['token' => $token];
$filesystem->writeStream($path, $stream, $config);

$filesystem->write($path, $content, $config);

$filesystem->put($path, $content, $config);

Tricks

The Versions

14/10 2016

dev-master

9999999-dev

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

14/10 2016

v0.5

0.5.0.0

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

14/10 2016

dev-hotfix

dev-hotfix

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

14/10 2016

v0.4

0.4.0.0

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

14/10 2016

dev-addFetch

dev-addFetch

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

03/06 2016

v0.3

0.3.0.0

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

03/06 2016

v0.3.x-dev

0.3.9999999.9999999-dev

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

02/06 2016

v0.2

0.2.0.0

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

02/06 2016

v0.2.x-dev

0.2.9999999.9999999-dev

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9

01/06 2016

v0.1

0.1.0.0

The Qiniu integration for the Yii framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

yii2 helper qiniu dcb9