|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @link http://www.tintsoft.com/ |
|
4
|
|
|
* @copyright Copyright (c) 2012 TintSoft Technology Co. Ltd. |
|
5
|
|
|
* @license http://www.tintsoft.com/license/ |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace yuncms\filesystem\adapters; |
|
9
|
|
|
|
|
10
|
|
|
use Qcloud\Cos\Client; |
|
11
|
|
|
use Yii; |
|
12
|
|
|
use yii\base\InvalidConfigException; |
|
13
|
|
|
use yuncms\filesystem\Adapter; |
|
14
|
|
|
|
|
15
|
|
|
class CosV5Adapter extends Adapter |
|
16
|
|
|
{ |
|
17
|
|
|
public $appId; |
|
18
|
|
|
public $accessId; |
|
19
|
|
|
public $accessSecret; |
|
20
|
|
|
public $bucket; |
|
21
|
|
|
public $domain; |
|
22
|
|
|
public $region; |
|
23
|
|
|
public $timeout = 60; |
|
24
|
|
|
public $connectTimeout = 10; |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string https://{your-bucket}-{your-app-id}.file.myqcloud.com |
|
27
|
|
|
*/ |
|
28
|
|
|
public $cdn = ''; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritdoc |
|
32
|
|
|
*/ |
|
33
|
|
|
public function init() |
|
34
|
|
|
{ |
|
35
|
|
|
if ($this->appId === null) { |
|
36
|
|
|
throw new InvalidConfigException('The "appId" property must be set.'); |
|
37
|
|
|
} |
|
38
|
|
|
if ($this->accessId === null) { |
|
39
|
|
|
throw new InvalidConfigException('The "accessId" property must be set.'); |
|
40
|
|
|
} |
|
41
|
|
|
if ($this->accessSecret === null) { |
|
42
|
|
|
throw new InvalidConfigException('The "accessSecret" property must be set.'); |
|
43
|
|
|
} |
|
44
|
|
|
if ($this->bucket === null) { |
|
45
|
|
|
throw new InvalidConfigException('The "bucket" property must be set.'); |
|
46
|
|
|
} |
|
47
|
|
|
if ($this->domain === null) { |
|
48
|
|
|
throw new InvalidConfigException('The "domain" property must be set.'); |
|
49
|
|
|
} |
|
50
|
|
|
if ($this->region === null) { |
|
51
|
|
|
throw new InvalidConfigException('The "region" property must be set.'); |
|
52
|
|
|
} |
|
53
|
|
|
parent::init(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @inheritdoc |
|
58
|
|
|
*/ |
|
59
|
|
|
public static function displayName(): string |
|
60
|
|
|
{ |
|
61
|
|
|
return Yii::t('yuncms', 'QCloud COS'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* 准备适配器 |
|
66
|
|
|
* @return \Freyo\Flysystem\QcloudCOSv5\Adapter |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function prepareAdapter() |
|
69
|
|
|
{ |
|
70
|
|
|
$config = [ |
|
71
|
|
|
'region' => $this->region, |
|
72
|
|
|
'credentials' => [ |
|
73
|
|
|
'appId' => $this->appId, |
|
74
|
|
|
'secretId' => $this->accessId, |
|
75
|
|
|
'secretKey' => $this->accessSecret, |
|
76
|
|
|
], |
|
77
|
|
|
'timeout' => $this->timeout, |
|
78
|
|
|
'connect_timeout' => $this->timeout, |
|
79
|
|
|
'bucket' => $this->bucket, |
|
80
|
|
|
'cdn' => $this->cdn, |
|
81
|
|
|
]; |
|
82
|
|
|
|
|
83
|
|
|
$client = new Client($config); |
|
84
|
|
|
|
|
85
|
|
|
return new \Freyo\Flysystem\QcloudCOSv5\Adapter($client, $config); |
|
86
|
|
|
} |
|
87
|
|
|
} |