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) |
|
71 | |||
72 | /** |
||
73 | * 获取资源的元信息,但不返回文件内容 |
||
74 | * |
||
75 | * @param $bucket 待获取信息资源所在的空间 |
||
76 | * @param $key 待获取资源的文件名 |
||
77 | * |
||
78 | * @return array 包含文件信息的数组,类似: |
||
79 | * [ |
||
80 | * "hash" => "<Hash string>", |
||
81 | * "key" => "<Key string>", |
||
82 | * "fsize" => "<file size>", |
||
83 | * "putTime" => "<file modify time>" |
||
84 | * ] |
||
85 | * |
||
86 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/stat.html |
||
87 | */ |
||
88 | 3 | public function stat($bucket, $key) |
|
93 | |||
94 | /** |
||
95 | * 删除指定资源 |
||
96 | * |
||
97 | * @param $bucket 待删除资源所在的空间 |
||
98 | * @param $key 待删除资源的文件名 |
||
99 | * |
||
100 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
101 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/delete.html |
||
102 | */ |
||
103 | 15 | public function delete($bucket, $key) |
|
109 | |||
110 | |||
111 | /** |
||
112 | * 给资源进行重命名,本质为move操作。 |
||
113 | * |
||
114 | * @param $bucket 待操作资源所在空间 |
||
115 | * @param $oldname 待操作资源文件名 |
||
116 | * @param $newname 目标资源文件名 |
||
117 | * |
||
118 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
119 | */ |
||
120 | 3 | public function rename($bucket, $oldname, $newname) |
|
124 | |||
125 | /** |
||
126 | * 给资源进行重命名,本质为move操作。 |
||
127 | * |
||
128 | * @param $from_bucket 待操作资源所在空间 |
||
129 | * @param $from_key 待操作资源文件名 |
||
130 | * @param $to_bucket 目标资源空间名 |
||
131 | * @param $to_key 目标资源文件名 |
||
132 | * |
||
133 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
134 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/copy.html |
||
135 | */ |
||
136 | 12 | public function copy($from_bucket, $from_key, $to_bucket, $to_key) |
|
144 | |||
145 | /** |
||
146 | * 将资源从一个空间到另一个空间 |
||
147 | * |
||
148 | * @param $from_bucket 待操作资源所在空间 |
||
149 | * @param $from_key 待操作资源文件名 |
||
150 | * @param $to_bucket 目标资源空间名 |
||
151 | * @param $to_key 目标资源文件名 |
||
152 | * |
||
153 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
154 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/move.html |
||
155 | */ |
||
156 | 3 | public function move($from_bucket, $from_key, $to_bucket, $to_key) |
|
164 | |||
165 | /** |
||
166 | * 主动修改指定资源的文件类型 |
||
167 | * |
||
168 | * @param $bucket 待操作资源所在空间 |
||
169 | * @param $key 待操作资源文件名 |
||
170 | * @param $mime 待操作文件目标mimeType |
||
171 | * |
||
172 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
173 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/chgm.html |
||
174 | */ |
||
175 | 3 | public function changeMime($bucket, $key, $mime) |
|
183 | |||
184 | /** |
||
185 | * 从指定URL抓取资源,并将该资源存储到指定空间中 |
||
186 | * |
||
187 | * @param $url 指定的URL |
||
188 | * @param $bucket 目标资源空间 |
||
189 | * @param $key 目标资源文件名 |
||
190 | * |
||
191 | * @return array 包含已拉取的文件信息。 |
||
192 | * 成功时: [ |
||
193 | * [ |
||
194 | * "hash" => "<Hash string>", |
||
195 | * "key" => "<Key string>" |
||
196 | * ], |
||
197 | * null |
||
198 | * ] |
||
199 | * |
||
200 | * 失败时: [ |
||
201 | * null, |
||
202 | * Qiniu/Http/Error |
||
203 | * ] |
||
204 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html |
||
205 | */ |
||
206 | 3 | public function fetch($url, $bucket, $key = null) |
|
214 | |||
215 | /** |
||
216 | * 从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源 |
||
217 | * |
||
218 | * @param $bucket 待获取资源所在的空间 |
||
219 | * @param $key 代获取资源文件名 |
||
220 | * |
||
221 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
222 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html |
||
223 | */ |
||
224 | 3 | public function prefetch($bucket, $key) |
|
231 | |||
232 | /** |
||
233 | * 在单次请求中进行多个资源管理操作 |
||
234 | * |
||
235 | * @param $operations 资源管理操作数组 |
||
236 | * |
||
237 | * @return array 每个资源的处理情况,结果类似: |
||
238 | * [ |
||
239 | * { "code" => <HttpCode int>, "data" => <Data> }, |
||
240 | * { "code" => <HttpCode int> }, |
||
241 | * { "code" => <HttpCode int> }, |
||
242 | * { "code" => <HttpCode int> }, |
||
243 | * { "code" => <HttpCode int>, "data" => { "error": "<ErrorMessage string>" } }, |
||
244 | * ... |
||
245 | * ] |
||
246 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/batch.html |
||
247 | */ |
||
248 | 12 | public function batch($operations) |
|
253 | |||
254 | 24 | private function rsPost($path, $body = null) |
|
259 | |||
260 | 6 | private function rsGet($path) |
|
265 | |||
266 | 6 | private function ioPost($path, $body = null) |
|
271 | |||
272 | 9 | private function get($url) |
|
281 | |||
282 | 30 | private function post($url, $body) |
|
292 | |||
293 | 3 | public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket) |
|
297 | |||
298 | |||
299 | 3 | public static function buildBatchRename($bucket, $key_pairs) |
|
303 | |||
304 | |||
305 | 6 | public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket) |
|
309 | |||
310 | |||
311 | 3 | public static function buildBatchDelete($bucket, $keys) |
|
315 | |||
316 | |||
317 | 3 | public static function buildBatchStat($bucket, $keys) |
|
321 | |||
322 | 6 | private static function oneKeyBatch($operation, $bucket, $keys) |
|
330 | |||
331 | 9 | private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket) |
|
344 | } |
||
345 |