Passed
Push — master ( 812cef...79dd4d )
by sabaku
25:16 queued 11:52
created

Config::getPretreatEndPoint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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