-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQiNiuComponent.php
64 lines (58 loc) · 1.33 KB
/
QiNiuComponent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace kriss\qiniu;
use League\Flysystem\Filesystem;
use Overtrue\Flysystem\Qiniu\QiniuAdapter;
use yii\base\Component;
use yii\base\InvalidConfigException;
class QiNiuComponent extends Component
{
/**
* AK
* @var string
*/
public $access_key;
/**
* SK
* @var string
*/
public $secret_key;
/**
* bucket name
* @var string
*/
public $bucket;
/**
* xxxx.xx.com or host: https://xxxx.xx.com
* @var string
*/
public $domain;
/**
* @var bool|Filesystem
*/
private $_flysystem = false;
/**
* use this to get disk instance
* @return Filesystem
*/
public function getDisk()
{
if ($this->_flysystem !== false) {
return $this->_flysystem;
}
$this->configCanNotBeNull(['access_key', 'secret_key', 'bucket', 'domain']);
$adapter = new QiniuAdapter($this->access_key, $this->secret_key, $this->bucket, $this->domain);
return new Filesystem($adapter);
}
/**
* @param $params array
* @throws InvalidConfigException
*/
protected function configCanNotBeNull($params)
{
foreach ($params as $param) {
if (!$this->$param) {
throw new InvalidConfigException($param . 'must be set');
}
}
}
}