Completed
Push — master ( 3e12c1...698c08 )
by Xu
32:46 queued 26:30
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\base\InvalidConfigException;
11
use yuncms\filesystem\Adapter;
12
13
/**
14
 * Class CosV3Adapter
15
 *
16
 * @author Tongle Xu <[email protected]>
17
 * @since 3.0
18
 */
19
class CosV3Adapter extends Adapter
20
{
21
    public $protocol = 'http';
22
    public $appId;
23
    public $accessId;
24
    public $accessSecret;
25
    public $bucket;
26
    public $domain;
27
    public $region;
28
    public $timeout = 60;
29
    public $debug = false;
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function init()
35
    {
36
        if ($this->appId === null) {
37
            throw new InvalidConfigException('The "appId" property must be set.');
38
        }
39
        if ($this->accessId === null) {
40
            throw new InvalidConfigException('The "accessId" property must be set.');
41
        }
42
        if ($this->accessSecret === null) {
43
            throw new InvalidConfigException('The "accessSecret" property must be set.');
44
        }
45
        if ($this->bucket === null) {
46
            throw new InvalidConfigException('The "bucket" property must be set.');
47
        }
48
        if ($this->domain === null) {
49
            throw new InvalidConfigException('The "domain" property must be set.');
50
        }
51
        if ($this->region === null) {
52
            throw new InvalidConfigException('The "region" property must be set.');
53
        }
54
        parent::init();
55
    }
56
57
    /**
58
     * 准备适配器
59
     * @return \Freyo\Flysystem\QcloudCOSv3\Adapter
60
     */
61
    protected function prepareAdapter()
62
    {
63
        return new \Freyo\Flysystem\QcloudCOSv3\Adapter([
64
            'protocol' => $this->protocol,
65
            'domain' => $this->domain,
66
            'app_id' => $this->appId,
67
            'secret_id' => $this->accessId,
68
            'secret_key' => $this->accessSecret,
69
            'timeout' => $this->timeout,
70
            'bucket' => $this->bucket,
71
            'region' => $this->region,
72
            'debug' => $this->debug,
73
        ]);
74
    }
75
}