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

OssAdapter::displayName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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
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
}