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 | 3 | ||
69 | 3 | /** |
|
70 | 3 | * 获取资源的元信息,但不返回文件内容 |
|
71 | * |
||
72 | * @param $bucket 待获取信息资源所在的空间 |
||
73 | 3 | * @param $key 待获取资源的文件名 |
|
74 | 3 | * |
|
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 | public function stat($bucket, $key) |
||
90 | |||
91 | /** |
||
92 | * 删除指定资源 |
||
93 | 3 | * |
|
94 | * @param $bucket 待删除资源所在的空间 |
||
95 | 3 | * @param $key 待删除资源的文件名 |
|
96 | 3 | * |
|
97 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
98 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/delete.html |
||
99 | */ |
||
100 | public function delete($bucket, $key) |
||
106 | |||
107 | |||
108 | 14 | /** |
|
109 | * 给资源进行重命名,本质为move操作。 |
||
110 | 14 | * |
|
111 | 14 | * @param $bucket 待操作资源所在空间 |
|
112 | 14 | * @param $oldname 待操作资源文件名 |
|
113 | * @param $newname 目标资源文件名 |
||
114 | * |
||
115 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
116 | */ |
||
117 | public function rename($bucket, $oldname, $newname) |
||
121 | |||
122 | /** |
||
123 | * 给资源进行重命名,本质为move操作。 |
||
124 | * |
||
125 | 3 | * @param $from_bucket 待操作资源所在空间 |
|
126 | * @param $from_key 待操作资源文件名 |
||
127 | 3 | * @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 | public function copy($from_bucket, $from_key, $to_bucket, $to_key) |
||
141 | 12 | ||
142 | /** |
||
143 | 12 | * 将资源从一个空间到另一个空间 |
|
144 | 12 | * |
|
145 | 12 | * @param $from_bucket 待操作资源所在空间 |
|
146 | 12 | * @param $from_key 待操作资源文件名 |
|
147 | 12 | * @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 | public function move($from_bucket, $from_key, $to_bucket, $to_key) |
||
161 | 3 | ||
162 | /** |
||
163 | 3 | * 主动修改指定资源的文件类型 |
|
164 | 3 | * |
|
165 | 3 | * @param $bucket 待操作资源所在空间 |
|
166 | 3 | * @param $key 待操作资源文件名 |
|
167 | 3 | * @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 | public function changeMime($bucket, $key, $mime) |
||
180 | 3 | ||
181 | /** |
||
182 | 3 | * 从指定URL抓取资源,并将该资源存储到指定空间中 |
|
183 | 3 | * |
|
184 | 3 | * @param $url 指定的URL |
|
185 | 3 | * @param $bucket 目标资源空间 |
|
186 | 3 | * @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 | public function fetch($url, $bucket, $key = null) |
||
211 | 3 | ||
212 | /** |
||
213 | * 从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源 |
||
214 | 3 | * |
|
215 | 3 | * @param $bucket 待获取资源所在的空间 |
|
216 | 3 | * @param $key 代获取资源文件名 |
|
217 | 3 | * |
|
218 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
219 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html |
||
220 | */ |
||
221 | public function prefetch($bucket, $key) |
||
228 | |||
229 | 3 | /** |
|
230 | * 在单次请求中进行多个资源管理操作 |
||
231 | 3 | * |
|
232 | 3 | * @param $operations 资源管理操作数组 |
|
233 | 3 | * |
|
234 | 3 | * @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 | public function batch($operations) |
||
250 | |||
251 | private function rsPost($path, $body = null) |
||
256 | 12 | ||
257 | private function rsGet($path) |
||
262 | 24 | ||
263 | private function ioPost($path, $body = null) |
||
268 | 6 | ||
269 | private function get($url) |
||
278 | |||
279 | 9 | private function post($url, $body) |
|
289 | 30 | ||
290 | 30 | public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket) |
|
294 | 25 | ||
295 | 25 | ||
296 | public static function buildBatchRename($bucket, $key_pairs) |
||
300 | 3 | ||
301 | |||
302 | public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket) |
||
306 | 3 | ||
307 | |||
308 | public static function buildBatchDelete($bucket, $keys) |
||
312 | 6 | ||
313 | |||
314 | public static function buildBatchStat($bucket, $keys) |
||
318 | 2 | ||
319 | private static function oneKeyBatch($operation, $bucket, $keys) |
||
327 | 5 | ||
328 | private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket) |
||
341 | } |
||
342 |