1 | <?php |
||
16 | final class BucketManager |
||
17 | { |
||
18 | private $auth; |
||
19 | private $zone; |
||
20 | |||
21 | 42 | public function __construct(Auth $auth, Zone $zone = null) |
|
28 | |||
29 | /** |
||
30 | * 获取指定账号下所有的空间名。 |
||
31 | * |
||
32 | * @return string[] 包含所有空间名 |
||
33 | */ |
||
34 | 3 | public function buckets() |
|
38 | |||
39 | /** |
||
40 | * 列取空间的文件列表 |
||
41 | * |
||
42 | * @param $bucket 空间名 |
||
43 | * @param $prefix 列举前缀 |
||
44 | * @param $marker 列举标识符 |
||
45 | * @param $limit 单次列举个数限制 |
||
46 | * @param $delimiter 指定目录分隔符 |
||
47 | * |
||
48 | * @return array 包含文件信息的数组,类似:[ |
||
49 | * { |
||
50 | * "hash" => "<Hash string>", |
||
51 | * "key" => "<Key string>", |
||
52 | * "fsize" => "<file size>", |
||
53 | * "putTime" => "<file modify time>" |
||
54 | * }, |
||
55 | * ... |
||
56 | * ] |
||
57 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html |
||
58 | */ |
||
59 | 3 | public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000, $delimiter = null) |
|
74 | |||
75 | /** |
||
76 | * 获取资源的元信息,但不返回文件内容 |
||
77 | * |
||
78 | * @param $bucket 待获取信息资源所在的空间 |
||
79 | * @param $key 待获取资源的文件名 |
||
80 | * |
||
81 | * @return array 包含文件信息的数组,类似: |
||
82 | * [ |
||
83 | * "hash" => "<Hash string>", |
||
84 | * "key" => "<Key string>", |
||
85 | * "fsize" => <file size>, |
||
86 | * "putTime" => "<file modify time>" |
||
87 | * "fileType" => <file type> |
||
88 | * ] |
||
89 | * |
||
90 | * @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 | * @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 | * @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 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/copy.html |
||
139 | */ |
||
140 | 15 | 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 | * @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 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/chgm.html |
||
184 | */ |
||
185 | 3 | public function changeMime($bucket, $key, $mime) |
|
193 | |||
194 | |||
195 | /** |
||
196 | * 修改指定资源的存储类型 |
||
197 | * |
||
198 | * @param $bucket 待操作资源所在空间 |
||
199 | * @param $key 待操作资源文件名 |
||
200 | * @param $fileType 待操作文件目标文件类型 |
||
201 | * |
||
202 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
203 | * @link https://developer.qiniu.com/kodo/api/3710/modify-the-file-type |
||
204 | */ |
||
205 | public function changeType($bucket, $key, $fileType) |
||
212 | |||
213 | |||
214 | /** |
||
215 | * 从指定URL抓取资源,并将该资源存储到指定空间中 |
||
216 | * |
||
217 | * @param $url 指定的URL |
||
218 | * @param $bucket 目标资源空间 |
||
219 | * @param $key 目标资源文件名 |
||
220 | * |
||
221 | * @return array 包含已拉取的文件信息。 |
||
222 | * 成功时: [ |
||
223 | * [ |
||
224 | * "hash" => "<Hash string>", |
||
225 | * "key" => "<Key string>" |
||
226 | * ], |
||
227 | * null |
||
228 | * ] |
||
229 | * |
||
230 | * 失败时: [ |
||
231 | * null, |
||
232 | * Qiniu/Http/Error |
||
233 | * ] |
||
234 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html |
||
235 | */ |
||
236 | 3 | public function fetch($url, $bucket, $key = null) |
|
249 | |||
250 | /** |
||
251 | * 从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源 |
||
252 | * |
||
253 | * @param $bucket 待获取资源所在的空间 |
||
254 | * @param $key 代获取资源文件名 |
||
255 | * |
||
256 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
257 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html |
||
258 | */ |
||
259 | 3 | public function prefetch($bucket, $key) |
|
271 | |||
272 | /** |
||
273 | * 在单次请求中进行多个资源管理操作 |
||
274 | * |
||
275 | * @param $operations 资源管理操作数组 |
||
276 | * |
||
277 | * @return array 每个资源的处理情况,结果类似: |
||
278 | * [ |
||
279 | * { "code" => <HttpCode int>, "data" => <Data> }, |
||
280 | * { "code" => <HttpCode int> }, |
||
281 | * { "code" => <HttpCode int> }, |
||
282 | * { "code" => <HttpCode int> }, |
||
283 | * { "code" => <HttpCode int>, "data" => { "error": "<ErrorMessage string>" } }, |
||
284 | * ... |
||
285 | * ] |
||
286 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/batch.html |
||
287 | */ |
||
288 | 12 | public function batch($operations) |
|
293 | |||
294 | /** |
||
295 | * 设置文件的生命周期 |
||
296 | * |
||
297 | * @param $bucket 设置文件生命周期文件所在的空间 |
||
298 | * @param $key 设置文件生命周期文件的文件名 |
||
299 | * @param $days 设置该文件多少天后删除,当$days设置为0时表示取消该文件的生命周期 |
||
300 | * |
||
301 | * @return Mixed |
||
302 | * @link https://developer.qiniu.com/kodo/api/update-file-lifecycle |
||
303 | */ |
||
304 | 3 | public function deleteAfterDays($bucket, $key, $days) |
|
311 | |||
312 | 27 | private function rsPost($path, $body = null) |
|
317 | |||
318 | 9 | private function rsGet($path) |
|
323 | |||
324 | private function ioPost($path, $body = null) |
||
329 | |||
330 | 12 | private function get($url) |
|
339 | |||
340 | 33 | private function post($url, $body) |
|
350 | |||
351 | 3 | public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket) |
|
355 | |||
356 | |||
357 | 3 | public static function buildBatchRename($bucket, $key_pairs) |
|
361 | |||
362 | |||
363 | 6 | public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket) |
|
367 | |||
368 | |||
369 | 3 | public static function buildBatchDelete($bucket, $keys) |
|
373 | |||
374 | |||
375 | 3 | public static function buildBatchStat($bucket, $keys) |
|
379 | |||
380 | 6 | private static function oneKeyBatch($operation, $bucket, $keys) |
|
388 | |||
389 | 9 | private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket) |
|
402 | } |
||
403 |