Passed
Pull Request — master (#37)
by sabaku
04:04
created

Config   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 70.83%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
dl 0
loc 129
ccs 17
cts 24
cp 0.7083
rs 10
c 2
b 1
f 0
wmc 9
lcom 2
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A setOperatorPassword() 0 4 1
A getFormApiKey() 0 8 2
A setFormApiKey() 0 4 1
A getVersion() 0 4 1
A getPretreatEndPoint() 0 4 1
A getProtocol() 0 4 2
1
<?php
2
namespace Upyun;
3
4
/**
5
 * Class Config
6
 *
7
 * @package Upyun
8
 */
9
class Config
10
{
11
    /**
12
     * @var string 服务名称,将会被弃用
13
     */
14
    public $bucketName;
15
16
    /**
17
     * @var string 服务名称
18
     */
19
    public $serviceName;
20
    /**
21
     * @var string 操作员名
22
     */
23
    public $operatorName;
24
    /**
25
     * @var string 操作员密码 md5 hash 值
26
     */
27
    public $operatorPassword;
28
29
    /**
30
     * @var bool 是否使用 https
31
     */
32
    public $useSsl;
33
34
    /**
35
     * @var string 上传使用的接口类型,可以设置为 `REST`:使用 rest api 上传,`AUTO` 根据文件大小自动判断,`BLOCK` 使用断点续传
36
     * 当上传小文件时,不推荐使用断点续传;上传时如果设置了异步预处理`withAsyncProcess=true`,将会使用表单 api 上传
37
     */
38
    public $uploadType = 'AUTO';
39
40
    /**
41
     * @var int 上传的接口类型设置为 `AUTO` 时,文件大小的边界值:小于该值时,使用 rest api,否则使用断点续传。 默认 30M
42
     */
43
    public $sizeBoundary = 31457280;
44
45
    /**
46
     * @var int request timeout seconds
47
     */
48
    public $timeout = 60;
49
50
51
    /**
52
     * @var string 异步云处理的回调通知地址
53
     */
54
    public $processNotifyUrl;
55
56
    /**
57
     * @var boolean curl debug
58
     */
59
    public $debug = false;
60
61
    private $version = '3.0.0';
62
63
64
65
    /**
66
     * @var string 表单 api 的秘钥
67
     */
68
    private $formApiKey;
69
70
    /**
71
     * @var string rest api 和 form api 的接口地址
72
     */
73
    public static $restApiEndPoint;
74
75
76
    /**
77
     * rest api 和 form api 接口请求地址,详见:http://docs.upyun.com/api/rest_api/
78
     */
79
    const ED_AUTO            = 'v0.api.upyun.com';
80
    const ED_TELECOM         = 'v1.api.upyun.com';
81
    const ED_CNC             = 'v2.api.upyun.com';
82
    const ED_CTT             = 'v3.api.upyun.com';
83
84
    /**
85
     * 异步云处理接口地址
86
     */
87
    const ED_VIDEO           = 'p0.api.upyun.com';
88
89
    /**
90
     * 刷新接口地址
91
     */
92
    const ED_PURGE           = 'http://purge.upyun.com/purge/';
93
94 2
    public function __construct($serviceName, $operatorName, $operatorPassword)
95
    {
96 2
        $this->serviceName = $serviceName;
97 2
        $this->bucketName = $serviceName;
98 2
        $this->operatorName = $operatorName;
99 2
        $this->setOperatorPassword($operatorPassword);
100 2
        $this->useSsl          = false;
101 2
        self::$restApiEndPoint = self::ED_AUTO;
102 2
    }
103
104 2
    public function setOperatorPassword($operatorPassword)
105
    {
106 2
        $this->operatorPassword = md5($operatorPassword);
107 2
    }
108
109
    public function getFormApiKey()
110
    {
111
        if (! $this->formApiKey) {
112
            throw new \Exception('form api key is empty.');
113
        }
114
115
        return $this->formApiKey;
116
    }
117
118
    public function setFormApiKey($key)
119
    {
120
        $this->formApiKey = $key;
121
    }
122
123 17
    public function getVersion()
124
    {
125 17
        return $this->version;
126
    }
127
128 3
    public function getPretreatEndPoint()
129
    {
130 3
        return $this->getProtocol() . self::ED_VIDEO;
131
    }
132
133 17
    public function getProtocol()
134
    {
135 17
        return $this->useSsl ? 'https://' : 'http://';
136
    }
137
}
138