Completed
Push — master ( 30d3de...6bbfea )
by Xu
29:18 queued 23:02
created

CosV5Adapter::init()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 13
nc 7
nop 0
dl 0
loc 21
rs 7.551
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
9
namespace yuncms\filesystem\adapters;
10
11
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 $debug = false;
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
     * 准备适配器
58
     * @return \Freyo\Flysystem\QcloudCOSv5\Adapter
59
     */
60
    protected function prepareAdapter()
61
    {
62
        $config = [
63
            'region' => $this->region,
64
            'credentials' => [
65
                'appId' => $this->appId,
66
                'secretId' => $this->accessId,
67
                'secretKey' => $this->accessSecret,
68
            ],
69
            'timeout' => $this->timeout,
70
            'connect_timeout' => $this->timeout,
71
            'bucket' => $this->bucket,
72
            'cdn' => $this->cdn,
73
        ];
74
75
        return new Freyo\Flysystem\QcloudCOSv5\Adapter($config);
0 ignored issues
show
Bug introduced by
The type yuncms\filesystem\adapte...tem\QcloudCOSv5\Adapter was not found. Did you mean Freyo\Flysystem\QcloudCOSv5\Adapter? If so, make sure to prefix the type with \.
Loading history...
76
    }
77
}