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