1 | <?php |
||
14 | final class BucketManager |
||
15 | { |
||
16 | private $auth; |
||
17 | |||
18 | 39 | public function __construct(Auth $auth) |
|
22 | |||
23 | /** |
||
24 | * 获取指定账号下所有的空间名。 |
||
25 | * |
||
26 | * @return string[] 包含所有空间名 |
||
27 | */ |
||
28 | 3 | public function buckets() |
|
32 | |||
33 | /** |
||
34 | * 列取空间的文件列表 |
||
35 | * |
||
36 | * @param $bucket 空间名 |
||
37 | * @param $prefix 列举前缀 |
||
38 | * @param $marker 列举标识符 |
||
39 | * @param $limit 单次列举个数限制 |
||
40 | * @param $delimiter 指定目录分隔符 |
||
41 | * |
||
42 | * @return array 包含文件信息的数组,类似:[ |
||
43 | * { |
||
44 | * "hash" => "<Hash string>", |
||
45 | * "key" => "<Key string>", |
||
46 | * "fsize" => "<file size>", |
||
47 | * "putTime" => "<file modify time>" |
||
48 | * }, |
||
49 | * ... |
||
50 | * ] |
||
51 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html |
||
52 | */ |
||
53 | 3 | public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000, $delimiter = null) |
|
68 | |||
69 | /** |
||
70 | * 获取资源的元信息,但不返回文件内容 |
||
71 | * |
||
72 | * @param $bucket 待获取信息资源所在的空间 |
||
73 | * @param $key 待获取资源的文件名 |
||
74 | * |
||
75 | * @return array 包含文件信息的数组,类似: |
||
76 | * [ |
||
77 | * "hash" => "<Hash string>", |
||
78 | * "key" => "<Key string>", |
||
79 | * "fsize" => "<file size>", |
||
80 | * "putTime" => "<file modify time>" |
||
81 | * ] |
||
82 | * |
||
83 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/stat.html |
||
84 | */ |
||
85 | 3 | public function stat($bucket, $key) |
|
90 | |||
91 | /** |
||
92 | * 删除指定资源 |
||
93 | * |
||
94 | * @param $bucket 待删除资源所在的空间 |
||
95 | * @param $key 待删除资源的文件名 |
||
96 | * |
||
97 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
98 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/delete.html |
||
99 | */ |
||
100 | 13 | public function delete($bucket, $key) |
|
106 | |||
107 | |||
108 | /** |
||
109 | * 给资源进行重命名,本质为move操作。 |
||
110 | * |
||
111 | * @param $bucket 待操作资源所在空间 |
||
112 | * @param $oldname 待操作资源文件名 |
||
113 | * @param $newname 目标资源文件名 |
||
114 | * |
||
115 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
116 | */ |
||
117 | 3 | public function rename($bucket, $oldname, $newname) |
|
121 | |||
122 | /** |
||
123 | * 给资源进行重命名,本质为move操作。 |
||
124 | * |
||
125 | * @param $from_bucket 待操作资源所在空间 |
||
126 | * @param $from_key 待操作资源文件名 |
||
127 | * @param $to_bucket 目标资源空间名 |
||
128 | * @param $to_key 目标资源文件名 |
||
129 | * |
||
130 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
131 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/copy.html |
||
132 | */ |
||
133 | 12 | public function copy($from_bucket, $from_key, $to_bucket, $to_key) |
|
141 | |||
142 | /** |
||
143 | * 将资源从一个空间到另一个空间 |
||
144 | * |
||
145 | * @param $from_bucket 待操作资源所在空间 |
||
146 | * @param $from_key 待操作资源文件名 |
||
147 | * @param $to_bucket 目标资源空间名 |
||
148 | * @param $to_key 目标资源文件名 |
||
149 | * |
||
150 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
151 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/move.html |
||
152 | */ |
||
153 | 3 | public function move($from_bucket, $from_key, $to_bucket, $to_key) |
|
161 | |||
162 | /** |
||
163 | * 主动修改指定资源的文件类型 |
||
164 | * |
||
165 | * @param $bucket 待操作资源所在空间 |
||
166 | * @param $key 待操作资源文件名 |
||
167 | * @param $mime 待操作文件目标mimeType |
||
168 | * |
||
169 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
170 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/chgm.html |
||
171 | */ |
||
172 | 3 | public function changeMime($bucket, $key, $mime) |
|
180 | |||
181 | /** |
||
182 | * 从指定URL抓取资源,并将该资源存储到指定空间中 |
||
183 | * |
||
184 | * @param $url 指定的URL |
||
185 | * @param $bucket 目标资源空间 |
||
186 | * @param $key 目标资源文件名 |
||
187 | * |
||
188 | * @return array 包含已拉取的文件信息。 |
||
189 | * 成功时: [ |
||
190 | * [ |
||
191 | * "hash" => "<Hash string>", |
||
192 | * "key" => "<Key string>" |
||
193 | * ], |
||
194 | * null |
||
195 | * ] |
||
196 | * |
||
197 | * 失败时: [ |
||
198 | * null, |
||
199 | * Qiniu/Http/Error |
||
200 | * ] |
||
201 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html |
||
202 | */ |
||
203 | 3 | public function fetch($url, $bucket, $key = null) |
|
211 | |||
212 | /** |
||
213 | * 从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源 |
||
214 | * |
||
215 | * @param $bucket 待获取资源所在的空间 |
||
216 | * @param $key 代获取资源文件名 |
||
217 | * |
||
218 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
219 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html |
||
220 | */ |
||
221 | 3 | public function prefetch($bucket, $key) |
|
228 | |||
229 | /** |
||
230 | * 在单次请求中进行多个资源管理操作 |
||
231 | * |
||
232 | * @param $operations 资源管理操作数组 |
||
233 | * |
||
234 | * @return array 每个资源的处理情况,结果类似: |
||
235 | * [ |
||
236 | * { "code" => <HttpCode int>, "data" => <Data> }, |
||
237 | * { "code" => <HttpCode int> }, |
||
238 | * { "code" => <HttpCode int> }, |
||
239 | * { "code" => <HttpCode int> }, |
||
240 | * { "code" => <HttpCode int>, "data" => { "error": "<ErrorMessage string>" } }, |
||
241 | * ... |
||
242 | * ] |
||
243 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/batch.html |
||
244 | */ |
||
245 | 12 | public function batch($operations) |
|
250 | |||
251 | 24 | private function rsPost($path, $body = null) |
|
256 | |||
257 | 6 | private function rsGet($path) |
|
262 | |||
263 | 6 | private function ioPost($path, $body = null) |
|
268 | |||
269 | 9 | private function get($url) |
|
278 | |||
279 | 30 | private function post($url, $body) |
|
289 | |||
290 | 3 | public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket) |
|
294 | |||
295 | |||
296 | 3 | public static function buildBatchRename($bucket, $key_pairs) |
|
300 | |||
301 | |||
302 | 6 | public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket) |
|
306 | |||
307 | |||
308 | 3 | public static function buildBatchDelete($bucket, $keys) |
|
312 | |||
313 | |||
314 | 3 | public static function buildBatchStat($bucket, $keys) |
|
318 | |||
319 | 6 | private static function oneKeyBatch($operation, $bucket, $keys) |
|
327 | |||
328 | 9 | private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket) |
|
341 | } |
||
342 |