Completed
Push — master ( 5289b1...66334b )
by Xu
06:18
created

CosV3Adapter::prepareAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
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 Yii;
11
use yii\base\InvalidConfigException;
12
use yuncms\filesystem\Adapter;
13
14
/**
15
 * Class CosV3Adapter
16
 *
17
 * @author Tongle Xu <[email protected]>
18
 * @since 3.0
19
 */
20
class CosV3Adapter extends Adapter
21
{
22
    public $protocol = 'http';
23
    public $appId;
24
    public $accessId;
25
    public $accessSecret;
26
    public $bucket;
27
    public $domain;
28
    public $region;
29
    public $timeout = 60;
30
    public $debug = false;
31
32
    /**
33
     * @inheritdoc
34
     */
35
    public function init()
36
    {
37
        if ($this->appId === null) {
38
            throw new InvalidConfigException('The "appId" property must be set.');
39
        }
40
        if ($this->accessId === null) {
41
            throw new InvalidConfigException('The "accessId" property must be set.');
42
        }
43
        if ($this->accessSecret === null) {
44
            throw new InvalidConfigException('The "accessSecret" property must be set.');
45
        }
46
        if ($this->bucket === null) {
47
            throw new InvalidConfigException('The "bucket" property must be set.');
48
        }
49
        if ($this->domain === null) {
50
            throw new InvalidConfigException('The "domain" property must be set.');
51
        }
52
        if ($this->region === null) {
53
            throw new InvalidConfigException('The "region" property must be set.');
54
        }
55
        parent::init();
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public static function displayName(): string
62
    {
63
        return Yii::t('yuncms', 'QCloud COS');
64
    }
65
66
    /**
67
     * 准备适配器
68
     * @return \Freyo\Flysystem\QcloudCOSv3\Adapter
69
     */
70
    protected function prepareAdapter()
71
    {
72
        return new \Freyo\Flysystem\QcloudCOSv3\Adapter([
73
            'protocol' => $this->protocol,
74
            'domain' => $this->domain,
75
            'app_id' => $this->appId,
76
            'secret_id' => $this->accessId,
77
            'secret_key' => $this->accessSecret,
78
            'timeout' => $this->timeout,
79
            'bucket' => $this->bucket,
80
            'region' => $this->region,
81
            'debug' => $this->debug,
82
        ]);
83
    }
84
}