|
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
|
|
|
|
|
9
|
|
|
namespace yuncms\filesystem\adapters; |
|
10
|
|
|
|
|
11
|
|
|
use Yii; |
|
12
|
|
|
use yii\base\InvalidConfigException; |
|
13
|
|
|
use yuncms\filesystem\Adapter; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class OSSAdapter |
|
17
|
|
|
* |
|
18
|
|
|
* @author Tongle Xu <[email protected]> |
|
19
|
|
|
* @since 3.0 |
|
20
|
|
|
*/ |
|
21
|
|
|
class OssAdapter extends Adapter |
|
22
|
|
|
{ |
|
23
|
|
|
public $accessId; |
|
24
|
|
|
public $accessSecret; |
|
25
|
|
|
public $bucket; |
|
26
|
|
|
public $endpoint; |
|
27
|
|
|
public $timeout = 3600; |
|
28
|
|
|
public $connectTimeout = 10; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @inheritdoc |
|
32
|
|
|
*/ |
|
33
|
|
|
public function init() |
|
34
|
|
|
{ |
|
35
|
|
|
if ($this->accessId === null) { |
|
36
|
|
|
throw new InvalidConfigException('The "accessId" property must be set.'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if ($this->accessSecret === null) { |
|
40
|
|
|
throw new InvalidConfigException('The "accessSecret" property must be set.'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if ($this->bucket === null) { |
|
44
|
|
|
throw new InvalidConfigException('The "bucket" property must be set.'); |
|
45
|
|
|
} |
|
46
|
|
|
if ($this->endpoint === null) { |
|
47
|
|
|
throw new InvalidConfigException('The "endpoint" property must be set.'); |
|
48
|
|
|
} |
|
49
|
|
|
parent::init(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @inheritdoc |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function displayName(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return Yii::t('yuncms', 'Aliyun OSS'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return \Xxtime\Flysystem\Aliyun\OssAdapter |
|
62
|
|
|
* @throws \Exception |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function prepareAdapter() |
|
65
|
|
|
{ |
|
66
|
|
|
return new \Xxtime\Flysystem\Aliyun\OssAdapter([ |
|
67
|
|
|
'access_id' => $this->accessId, |
|
68
|
|
|
'access_secret' => $this->accessSecret, |
|
69
|
|
|
'bucket' => $this->bucket, |
|
70
|
|
|
'endpoint' => $this->endpoint, |
|
71
|
|
|
'timeout' => $this->timeout, |
|
72
|
|
|
'connectTimeout' => $this->connectTimeout, |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |