1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlphaSnow\AliyunOss; |
4
|
|
|
|
5
|
|
|
use LogicException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class AliyunOssConfig |
9
|
|
|
* @package AlphaSnow\AliyunOss |
10
|
|
|
*/ |
11
|
|
|
class AliyunOssConfig |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $driver = 'aliyun'; |
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $accessId; |
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $accessKey; |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $bucket; |
29
|
|
|
/** |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $endpoint = 'oss-cn-shanghai.aliyuncs.com'; |
33
|
|
|
/** |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $endpointInternal = ''; |
37
|
|
|
/** |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
protected $ssl = false; |
41
|
|
|
/** |
42
|
|
|
* @var bool |
43
|
|
|
*/ |
44
|
|
|
protected $isCname = false; |
45
|
|
|
/** |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
protected $debug = false; |
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
protected $cdnDomain = ''; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
*/ |
57
|
|
|
protected $securityToken; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
protected $requestProxy; |
63
|
|
|
|
64
|
4 |
|
public function __construct(array $config = []) |
65
|
|
|
{ |
66
|
4 |
|
foreach ($config as $key => $value) { |
67
|
3 |
|
$this->{$key} = $value; |
68
|
|
|
} |
69
|
4 |
|
} |
70
|
|
|
|
71
|
3 |
|
public function checkRequired() |
72
|
|
|
{ |
73
|
3 |
|
if (!$this->accessId) { |
74
|
1 |
|
throw new LogicException('Empty accessId'); |
75
|
|
|
} |
76
|
2 |
|
if (!$this->accessKey) { |
77
|
|
|
throw new LogicException('Empty accessKey'); |
78
|
|
|
} |
79
|
2 |
|
if (!$this->bucket) { |
80
|
|
|
throw new LogicException('Empty bucket'); |
81
|
|
|
} |
82
|
2 |
|
} |
83
|
|
|
|
84
|
1 |
|
public function getOssEndpoint() |
85
|
|
|
{ |
86
|
1 |
|
if ($this->isCname) { |
87
|
|
|
if (empty($this->cdnDomain)) { |
88
|
|
|
throw new LogicException('Empty cdnDomain'); |
89
|
|
|
} |
90
|
|
|
return $this->cdnDomain; |
91
|
|
|
} |
92
|
|
|
|
93
|
1 |
|
if (!empty($this->endpointInternal)) { |
94
|
|
|
return $this->endpointInternal; |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
return $this->endpoint; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
1 |
|
public function getDriver() |
104
|
|
|
{ |
105
|
1 |
|
return $this->driver; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
1 |
|
public function getAccessId() |
112
|
|
|
{ |
113
|
1 |
|
return $this->accessId; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
1 |
|
public function getAccessKey() |
120
|
|
|
{ |
121
|
1 |
|
return $this->accessKey; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
1 |
|
public function getBucket() |
128
|
|
|
{ |
129
|
1 |
|
return $this->bucket; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
1 |
|
public function getEndpoint() |
136
|
|
|
{ |
137
|
1 |
|
return $this->endpoint; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getEndpointInternal() |
144
|
|
|
{ |
145
|
|
|
return $this->endpointInternal; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return bool |
150
|
|
|
*/ |
151
|
1 |
|
public function isSsl() |
152
|
|
|
{ |
153
|
1 |
|
return $this->ssl; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return bool |
158
|
|
|
*/ |
159
|
2 |
|
public function isCname() |
160
|
|
|
{ |
161
|
2 |
|
return $this->isCname; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @return bool |
166
|
|
|
*/ |
167
|
1 |
|
public function isDebug() |
168
|
|
|
{ |
169
|
1 |
|
return $this->debug; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
1 |
|
public function getCdnDomain() |
176
|
|
|
{ |
177
|
1 |
|
return $this->cdnDomain; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return string |
182
|
|
|
*/ |
183
|
1 |
|
public function getSecurityToken() |
184
|
|
|
{ |
185
|
1 |
|
return $this->securityToken; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
1 |
|
public function getRequestProxy() |
192
|
|
|
{ |
193
|
1 |
|
return $this->requestProxy; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|