Config::getFormApiKey()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
crap 6
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` 使用串行式断点续传,`BLOCK_PARALLEL` 使用并行式断点续传
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 并行式断点续传的并发数
47
     */
48
    public $concurrency = 5;
49
50
    /**
51
     * @var int request timeout seconds
52
     */
53
    public $timeout = 60;
54
55
56
    /**
57
     * @var string 异步云处理的回调通知地址
58
     */
59
    public $processNotifyUrl;
60
61
    /**
62
     * @var boolean curl debug
63
     */
64
    public $debug = false;
65
66
    private $version = '3.0.0';
67
68
69
70
    /**
71
     * @var string 表单 api 的秘钥
72
     */
73
    private $formApiKey;
74
75
    /**
76
     * @var string rest api 和 form api 的接口地址
77
     */
78
    public static $restApiEndPoint;
79
80
81
    /**
82
     * rest api 和 form api 接口请求地址,详见:http://docs.upyun.com/api/rest_api/
83
     */
84
    const ED_AUTO            = 'v0.api.upyun.com';
85
    const ED_TELECOM         = 'v1.api.upyun.com';
86
    const ED_CNC             = 'v2.api.upyun.com';
87
    const ED_CTT             = 'v3.api.upyun.com';
88
89
    /**
90
     * 异步云处理接口地址
91
     */
92
    const ED_VIDEO           = 'p0.api.upyun.com';
93
94
    /**
95
     * 刷新接口地址
96
     */
97
    const ED_PURGE           = 'http://purge.upyun.com/purge/';
98
99
    /**
100
     * 同步视频处理接口地址
101
     */
102
    const ED_SYNC_VIDEO           = 'p1.api.upyun.com';
103
104 3
    public function __construct($serviceName, $operatorName, $operatorPassword)
105
    {
106 3
        $this->serviceName = $serviceName;
107 3
        $this->bucketName = $serviceName;
108 3
        $this->operatorName = $operatorName;
109 3
        $this->setOperatorPassword($operatorPassword);
110 3
        $this->useSsl          = false;
111 3
        self::$restApiEndPoint = self::ED_AUTO;
112 3
    }
113
114 3
    public function setOperatorPassword($operatorPassword)
115
    {
116 3
        $this->operatorPassword = md5($operatorPassword);
117 3
    }
118
119
    public function getFormApiKey()
120
    {
121
        if (! $this->formApiKey) {
122
            throw new \Exception('form api key is empty.');
123
        }
124
125
        return $this->formApiKey;
126
    }
127
128
    public function setFormApiKey($key)
129
    {
130
        $this->formApiKey = $key;
131
    }
132
133 22
    public function getVersion()
134
    {
135 22
        return $this->version;
136
    }
137
138 3
    public function getPretreatEndPoint()
139
    {
140 3
        return $this->getProtocol() . self::ED_VIDEO;
141
    }
142
143 2
    public function getSyncVideoEndPoint()
144
    {
145 2
        return $this->getProtocol() . self::ED_SYNC_VIDEO;
146
    }
147
148 22
    public function getProtocol()
149
    {
150 22
        return $this->useSsl ? 'https://' : 'http://';
151
    }
152
153 1
    public function setUploadType($uploadType)
154
    {
155 1
        $this->uploadType = $uploadType;
156 1
    }
157
158
    public function setConcurrency($concurrency)
159
    {
160
        $this->concurrency = $concurrency;
161
    }
162
}
163