1 | <?php |
||
17 | final class BucketManager |
||
18 | { |
||
19 | private $auth; |
||
20 | 39 | private $zone; |
|
21 | |||
22 | 39 | public function __construct(Auth $auth, Zone $zone = null) |
|
29 | |||
30 | /** |
||
31 | * 获取指定账号下所有的空间名。 |
||
32 | * |
||
33 | 3 | * @return string[] 包含所有空间名 |
|
34 | */ |
||
35 | 3 | public function buckets() |
|
39 | |||
40 | /** |
||
41 | * 列取空间的文件列表 |
||
42 | * |
||
43 | * @param $bucket 空间名 |
||
44 | * @param $prefix 列举前缀 |
||
45 | * @param $marker 列举标识符 |
||
46 | * @param $limit 单次列举个数限制 |
||
47 | * @param $delimiter 指定目录分隔符 |
||
48 | * |
||
49 | * @return array 包含文件信息的数组,类似:[ |
||
50 | * { |
||
51 | * "hash" => "<Hash string>", |
||
52 | * "key" => "<Key string>", |
||
53 | * "fsize" => "<file size>", |
||
54 | * "putTime" => "<file modify time>" |
||
55 | * }, |
||
56 | * ... |
||
57 | * ] |
||
58 | 3 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html |
|
59 | */ |
||
60 | 3 | public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000, $delimiter = null) |
|
75 | |||
76 | /** |
||
77 | * 获取资源的元信息,但不返回文件内容 |
||
78 | * |
||
79 | * @param $bucket 待获取信息资源所在的空间 |
||
80 | * @param $key 待获取资源的文件名 |
||
81 | * |
||
82 | * @return array 包含文件信息的数组,类似: |
||
83 | * [ |
||
84 | * "hash" => "<Hash string>", |
||
85 | * "key" => "<Key string>", |
||
86 | * "fsize" => "<file size>", |
||
87 | * "putTime" => "<file modify time>" |
||
88 | * ] |
||
89 | * |
||
90 | 6 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/stat.html |
|
91 | */ |
||
92 | 6 | public function stat($bucket, $key) |
|
97 | |||
98 | /** |
||
99 | * 删除指定资源 |
||
100 | * |
||
101 | * @param $bucket 待删除资源所在的空间 |
||
102 | * @param $key 待删除资源的文件名 |
||
103 | * |
||
104 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
105 | 15 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/delete.html |
|
106 | */ |
||
107 | 15 | public function delete($bucket, $key) |
|
113 | |||
114 | |||
115 | /** |
||
116 | * 给资源进行重命名,本质为move操作。 |
||
117 | * |
||
118 | * @param $bucket 待操作资源所在空间 |
||
119 | * @param $oldname 待操作资源文件名 |
||
120 | * @param $newname 目标资源文件名 |
||
121 | * |
||
122 | 3 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
|
123 | */ |
||
124 | 3 | public function rename($bucket, $oldname, $newname) |
|
128 | |||
129 | /** |
||
130 | * 给资源进行重命名,本质为move操作。 |
||
131 | * |
||
132 | * @param $from_bucket 待操作资源所在空间 |
||
133 | * @param $from_key 待操作资源文件名 |
||
134 | * @param $to_bucket 目标资源空间名 |
||
135 | * @param $to_key 目标资源文件名 |
||
136 | * |
||
137 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
138 | 12 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/copy.html |
|
139 | */ |
||
140 | 12 | public function copy($from_bucket, $from_key, $to_bucket, $to_key, $force = false) |
|
151 | |||
152 | /** |
||
153 | * 将资源从一个空间到另一个空间 |
||
154 | * |
||
155 | * @param $from_bucket 待操作资源所在空间 |
||
156 | * @param $from_key 待操作资源文件名 |
||
157 | * @param $to_bucket 目标资源空间名 |
||
158 | * @param $to_key 目标资源文件名 |
||
159 | * |
||
160 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
161 | 3 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/move.html |
|
162 | */ |
||
163 | 3 | public function move($from_bucket, $from_key, $to_bucket, $to_key, $force = false) |
|
174 | |||
175 | /** |
||
176 | * 主动修改指定资源的文件类型 |
||
177 | * |
||
178 | * @param $bucket 待操作资源所在空间 |
||
179 | * @param $key 待操作资源文件名 |
||
180 | * @param $mime 待操作文件目标mimeType |
||
181 | * |
||
182 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
183 | 3 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/chgm.html |
|
184 | */ |
||
185 | 3 | public function changeMime($bucket, $key, $mime) |
|
193 | |||
194 | /** |
||
195 | * 从指定URL抓取资源,并将该资源存储到指定空间中 |
||
196 | * |
||
197 | * @param $url 指定的URL |
||
198 | * @param $bucket 目标资源空间 |
||
199 | * @param $key 目标资源文件名 |
||
200 | * |
||
201 | * @return array 包含已拉取的文件信息。 |
||
202 | * 成功时: [ |
||
203 | * [ |
||
204 | * "hash" => "<Hash string>", |
||
205 | * "key" => "<Key string>" |
||
206 | * ], |
||
207 | * null |
||
208 | * ] |
||
209 | * |
||
210 | * 失败时: [ |
||
211 | * null, |
||
212 | * Qiniu/Http/Error |
||
213 | * ] |
||
214 | 3 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html |
|
215 | */ |
||
216 | public function fetch($url, $bucket, $key = null) |
||
229 | |||
230 | /** |
||
231 | * 从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源 |
||
232 | * |
||
233 | * @param $bucket 待获取资源所在的空间 |
||
234 | * @param $key 代获取资源文件名 |
||
235 | * |
||
236 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
237 | 3 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html |
|
238 | */ |
||
239 | 3 | public function prefetch($bucket, $key) |
|
251 | |||
252 | /** |
||
253 | * 在单次请求中进行多个资源管理操作 |
||
254 | * |
||
255 | * @param $operations 资源管理操作数组 |
||
256 | * |
||
257 | * @return array 每个资源的处理情况,结果类似: |
||
258 | * [ |
||
259 | * { "code" => <HttpCode int>, "data" => <Data> }, |
||
260 | * { "code" => <HttpCode int> }, |
||
261 | * { "code" => <HttpCode int> }, |
||
262 | * { "code" => <HttpCode int> }, |
||
263 | * { "code" => <HttpCode int>, "data" => { "error": "<ErrorMessage string>" } }, |
||
264 | * ... |
||
265 | * ] |
||
266 | 12 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/batch.html |
|
267 | */ |
||
268 | 12 | public function batch($operations) |
|
273 | |||
274 | 24 | /** |
|
275 | 24 | * 设置文件的生命周期 |
|
276 | * |
||
277 | * @param $bucket 设置文件生命周期文件所在的空间 |
||
278 | 9 | * @param $key 设置文件生命周期文件的文件名 |
|
279 | * @param $days 设置该文件多少天后删除,当$days设置为0时表示取消该文件的生命周期 |
||
280 | 9 | * |
|
281 | 9 | * @return Mixed |
|
282 | */ |
||
283 | public function deleteAfterDays($bucket, $key, $days) |
||
290 | 12 | ||
291 | private function rsPost($path, $body = null) |
||
296 | |||
297 | 12 | private function rsGet($path) |
|
302 | 30 | ||
303 | 30 | private function ioPost($path, $body = null) |
|
308 | 27 | ||
309 | private function get($url) |
||
318 | |||
319 | 3 | private function post($url, $body) |
|
329 | 3 | ||
330 | public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket) |
||
334 | |||
335 | 3 | ||
336 | public static function buildBatchRename($bucket, $key_pairs) |
||
340 | 6 | ||
341 | |||
342 | 6 | public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket) |
|
346 | 6 | ||
347 | |||
348 | public static function buildBatchDelete($bucket, $keys) |
||
352 | |||
353 | |||
354 | 9 | public static function buildBatchStat($bucket, $keys) |
|
358 | 9 | ||
359 | 6 | private static function oneKeyBatch($operation, $bucket, $keys) |
|
367 | |||
368 | private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket) |
||
381 | } |
||
382 |