Complex classes like BucketManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BucketManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | final class BucketManager |
||
| 16 | { |
||
| 17 | private $auth; |
||
| 18 | private $config; |
||
| 19 | |||
| 20 | 42 | public function __construct(Auth $auth, Config $config = null) |
|
| 29 | |||
| 30 | /** |
||
| 31 | * 获取指定账号下所有的空间名。 |
||
| 32 | * |
||
| 33 | * @return string[] 包含所有空间名 |
||
| 34 | */ |
||
| 35 | 3 | public function buckets($shared = true) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * 创建空间 |
||
| 46 | * |
||
| 47 | * @param $name 创建的空间名 |
||
| 48 | * @param $region 创建的区域,默认华东 |
||
| 49 | * |
||
| 50 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 51 | */ |
||
| 52 | public function creatBucket($name, $region='z0') |
||
| 57 | |||
| 58 | /** |
||
| 59 | * 删除空间 |
||
| 60 | * |
||
| 61 | * @param $name 删除的空间名 |
||
| 62 | * |
||
| 63 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 64 | */ |
||
| 65 | public function deleteBucket($name) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * 获取指定空间绑定的所有的域名 |
||
| 73 | * |
||
| 74 | * @return string[] 包含所有空间域名 |
||
| 75 | */ |
||
| 76 | public function domains($bucket) |
||
| 80 | |||
| 81 | 3 | /** |
|
| 82 | 3 | * 获取指定空间的相关信息 |
|
| 83 | 3 | * |
|
| 84 | 3 | * @return string[] 包含空间信息 |
|
| 85 | 3 | */ |
|
| 86 | 3 | public function bucketInfo($bucket){ |
|
| 91 | |||
| 92 | /** |
||
| 93 | * 获取指定zone的空间信息列表 |
||
| 94 | * 在Region 未指定且Global 不为 true 时(包含未指定的情况,下同),返回用户的所有空间。 |
||
| 95 | * 在指定了 region 参数且 global 不为 true 时,只列举非全局空间。 |
||
| 96 | * 在指定了global为 true 时,返回所有全局空间,忽略region 参数 |
||
| 97 | * shared 不指定shared参数或指定shared为rw或false时,返回包含具有读写权限空间,指定shared为rd或true时,返回包含具有读权限空间。 |
||
| 98 | * fs:如果为 true,会返回每个空间当前的文件数和存储量(实时数据)。 |
||
| 99 | * |
||
| 100 | * @return string[] 包含空间信息 |
||
| 101 | */ |
||
| 102 | public function bucketInfos($region=null, $global='false', $shared='false', $fs='false'){ |
||
| 107 | 6 | ||
| 108 | /** |
||
| 109 | 6 | * 获取空间绑定的域名列表 |
|
| 110 | 6 | * @return string[] 包含空间绑定的所有域名 |
|
| 111 | */ |
||
| 112 | |||
| 113 | /** |
||
| 114 | * 列取空间的文件列表 |
||
| 115 | * |
||
| 116 | * @param $bucket 空间名 |
||
| 117 | * @param $prefix 列举前缀 |
||
| 118 | * @param $marker 列举标识符 |
||
| 119 | * @param $limit 单次列举个数限制 |
||
| 120 | * @param $delimiter 指定目录分隔符 |
||
| 121 | * |
||
| 122 | 15 | * @return array 包含文件信息的数组,类似:[ |
|
| 123 | * { |
||
| 124 | 15 | * "hash" => "<Hash string>", |
|
| 125 | 15 | * "key" => "<Key string>", |
|
| 126 | 15 | * "fsize" => "<file size>", |
|
| 127 | * "putTime" => "<file modify time>" |
||
| 128 | * }, |
||
| 129 | * ... |
||
| 130 | * ] |
||
| 131 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html |
||
| 132 | */ |
||
| 133 | public function listFiles($bucket, $prefix = null, $marker = null, $limit = 1000, $delimiter = null) |
||
| 143 | |||
| 144 | /** |
||
| 145 | * 设置Referer防盗链 |
||
| 146 | * |
||
| 147 | * @param $bucket 空间名 |
||
| 148 | * @param $mode 0: 表示关闭Referer(使用此选项将会忽略以下参数并将恢复默认值); 1: 表示设置Referer白名单; 2: 表示设置Referer黑名单 |
||
| 149 | * @param $norefer 0: 表示不允许空 Refer 访问; 1: 表示允许空 Refer 访问 |
||
| 150 | * @param $pattern 规则字符串, 当前允许格式分为三种: 一种为空主机头域名, 比如 foo.com; 一种是泛域名, 比如 *.bar.com; 一种是完全通配符, 即一个 *; 多个规则之间用;隔开, 比如: foo.com;*.bar.com;sub.foo.com;*.sub.bar.com |
||
| 151 | * @param $source_enabled 源站是否支持,默认为0只给CDN配置, 设置为1表示开启源站防盗链 |
||
| 152 | * |
||
| 153 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 154 | */ |
||
| 155 | 15 | public function referAntiLeech(){ |
|
| 158 | 15 | ||
| 159 | 15 | /** |
|
| 160 | 15 | * 增加bucket生命规则 |
|
| 161 | 3 | * |
|
| 162 | 3 | * @param $bucket 空间名 |
|
| 163 | 15 | * @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、数字、下划线 |
|
| 164 | 15 | * @param $prefix 同一个 bucket 里面前缀不能重复 |
|
| 165 | * @param $delete_after_days 指定上传文件多少天后删除,指定为0表示不删除,大于0表示多少天后删除,需大于 to_line_after_days |
||
| 166 | * @param $to_line_after_days 指定文件上传多少天后转低频存储。指定为0表示不转低频存储,小于0表示上传的文件立即变低频存储 |
||
| 167 | * |
||
| 168 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 169 | */ |
||
| 170 | public function bucketLifecycleRule($bucket, $name, $prefix, $delete_after_days, $to_line_after_days){ |
||
| 191 | |||
| 192 | /** |
||
| 193 | * 更新bucket生命规则 |
||
| 194 | * |
||
| 195 | * @param $bucket 空间名 |
||
| 196 | * @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、数字、下划线 |
||
| 197 | * @param $prefix 同一个 bucket 里面前缀不能重复 |
||
| 198 | * @param $delete_after_days 指定上传文件多少天后删除,指定为0表示不删除,大于0表示多少天后删除,需大于 to_line_after_days |
||
| 199 | * @param $to_line_after_days 指定文件上传多少天后转低频存储。指定为0表示不转低频存储,小于0表示上传的文件立即变低频存储 |
||
| 200 | 3 | * |
|
| 201 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 202 | 3 | */ |
|
| 203 | 3 | public function updateBucketLifecycleRule($bucket, $name, $prefix, $delete_after_days, $to_line_after_days){ |
|
| 224 | |||
| 225 | /** |
||
| 226 | * 获取bucket生命规则 |
||
| 227 | * |
||
| 228 | * @param $bucket 空间名 |
||
| 229 | * |
||
| 230 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 231 | */ |
||
| 232 | public function getBucketLifecycleRules($bucket){ |
||
| 237 | |||
| 238 | /** |
||
| 239 | * 删除bucket生命规则 |
||
| 240 | * |
||
| 241 | * @param $bucket 空间名 |
||
| 242 | * @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、数字、下划线 |
||
| 243 | * |
||
| 244 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 245 | */ |
||
| 246 | public function deleteBucketLifecycleRule($bucket, $name){ |
||
| 258 | |||
| 259 | /** |
||
| 260 | * 增加bucket事件通知规则 |
||
| 261 | * |
||
| 262 | * @param $bucket 空间名 |
||
| 263 | * @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、数字、下划线 |
||
| 264 | * @param $prefix 同一个 bucket 里面前缀不能重复 |
||
| 265 | * @param $suffix 可选,文件配置的后缀 |
||
| 266 | * @param $event 事件类型,可以指定多个,包括 put,mkfile,delete,copy,move,append,disable,enable,deleteMarkerCreate |
||
| 267 | * @param $callbackURL 通知URL,可以指定多个,失败依次重试 |
||
| 268 | 3 | * @param $access_key 可选,设置的话会对通知请求用对应的ak、sk进行签名 |
|
| 269 | * @param $host 可选,通知请求的host |
||
| 270 | * |
||
| 271 | 3 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
|
| 272 | 3 | */ |
|
| 273 | 3 | public function putBucketEvent($bucket, $name, $prefix, $suffix, $event, $callbackURL, $access_key=null, $host=null){ |
|
| 303 | |||
| 304 | /** |
||
| 305 | * 更新bucket事件通知规则 |
||
| 306 | * |
||
| 307 | * @param $bucket 空间名 |
||
| 308 | * @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、数字、下划线 |
||
| 309 | * @param $prefix 同一个 bucket 里面前缀不能重复 |
||
| 310 | * @param $suffix 可选,文件配置的后缀 |
||
| 311 | * @param $event 事件类型,可以指定多个,包括 put,mkfile,delete,copy,move,append,disable,enable,deleteMarkerCreate |
||
| 312 | * @param $callbackURL 通知URL,可以指定多个,失败依次重试 |
||
| 313 | * @param $access_key 可选,设置的话会对通知请求用对应的ak、sk进行签名 |
||
| 314 | * @param $host 可选,通知请求的host |
||
| 315 | * |
||
| 316 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 317 | */ |
||
| 318 | public function updateBucketEvent($bucket, $name, $prefix, $suffix, $event, $callbackURL, $access_key=null, $host=null){ |
||
| 348 | |||
| 349 | /** |
||
| 350 | 3 | * 获取bucket事件通知规则 |
|
| 351 | * |
||
| 352 | * @param $bucket 空间名 |
||
| 353 | 33 | * |
|
| 354 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 355 | 33 | */ |
|
| 356 | 33 | public function getBucketEvents($bucket){ |
|
| 361 | |||
| 362 | /** |
||
| 363 | * 删除bucket事件通知规则 |
||
| 364 | * |
||
| 365 | * @param $bucket 空间名 |
||
| 366 | * @param $name 规则名称 bucket 内唯一,长度小于50,不能为空,只能为字母、数字、下划线 |
||
| 367 | * |
||
| 368 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 369 | */ |
||
| 370 | public function deleteBucketEvent($bucket, $name){ |
||
| 382 | |||
| 383 | 9 | /** |
|
| 384 | * 设置bucket的跨域信息,最多允许设置10条跨域规则。 |
||
| 385 | 9 | * 对于同一个域名如果设置了多条规则,那么按顺序使用第一条匹配的规则去生成返回值。 |
|
| 386 | 9 | * 对于简单跨域请求,只匹配 Origin; |
|
| 387 | * 对于预检请求, 需要匹配 Origin、AllowedMethod、AllowedHeader; |
||
| 388 | * allowed_orgin: 允许的域名。必填;支持通配符*;*表示全部匹配;只有第一个*生效;需要设置"Scheme";大小写敏感。例如 |
||
| 389 | 12 | * 规则:http://*.abc.*.com 请求:"http://test.abc.test.com" 结果:不通过 |
|
| 390 | * 规则:"http://abc.com" 请求:"https://abc.com"/"abc.com" 结果:不通过 |
||
| 391 | 12 | * 规则:"abc.com" 请求:"http://abc.com" 结果:不通过 |
|
| 392 | 12 | * allowed_method: 允许的方法。必填;不支持通配符;大小写不敏感; |
|
| 393 | 12 | * allowed_header: 允许的header。选填;支持通配符*,但只能是单独的*,表示允许全部header,其他*不生效;空则不允许任何header;大小写不敏感; |
|
| 394 | 8 | * exposed_header: 暴露的header。选填;不支持通配符;X-Log, X-Reqid是默认会暴露的两个header;其他的header如果没有设置,则不会暴露;大小写不敏感; |
|
| 395 | * max_age: 结果可以缓存的时间。选填;空则不缓存; |
||
| 396 | 8 | * allowed_credentials:该配置不支持设置,默认为true。 |
|
| 397 | * 备注:如果没有设置任何corsRules,那么默认允许所有的跨域请求 |
||
| 398 | */ |
||
| 399 | 33 | public function putCorsRules($bucket, $params){ |
|
| 405 | |||
| 406 | 30 | /** |
|
| 407 | 30 | * 获取bucket的跨域信息 |
|
| 408 | * |
||
| 409 | * $bucket 空间名 |
||
| 410 | 3 | */ |
|
| 411 | public function getCorsRules($bucket){ |
||
| 416 | 3 | ||
| 417 | /** |
||
| 418 | 3 | * 设置回源规则 |
|
| 419 | * 使用该API设置源站优先级高于/image设置的源站,即IO优先读取source接口设置的源站配置,如果存在会忽略/image设置的源站 |
||
| 420 | * Bucket 空间名 |
||
| 421 | * Host(可选)回源Host |
||
| 422 | 6 | * RetryCodes(可选),镜像回源时源站返回Code可以重试,最多指定3个,当前只支持4xx错误码重试 |
|
| 423 | * SourceQiniuAK,SourceQiniuSK(可选)如果存在将在回源时对URL进行签名,客户源站可以验证以保证请求来自Qiniu服务器 |
||
| 424 | 6 | * Expires(可选) 签名过期时间,如果不设置默认为1小时 |
|
| 425 | * Addr 回源地址,不可重复。 |
||
| 426 | * Weight 权重,范围限制1-100,不填默认为1,回源时会根据所有源的权重值进行源站选择,主备源会分开计算. |
||
| 427 | * Backup 是否备用回源,回源优先尝试主源 |
||
| 428 | 3 | */ |
|
| 429 | public function putBucktSourceConfig($params){ |
||
| 435 | |||
| 436 | 3 | /** |
|
| 437 | * 获取空间回源配置 |
||
| 438 | */ |
||
| 439 | public function getBucktSourceConfig($params){ |
||
| 445 | |||
| 446 | /** |
||
| 447 | * 开关原图保护 |
||
| 448 | * mode 为1表示开启原图保护,0表示关闭 |
||
| 449 | */ |
||
| 450 | public function putBucketAccessStyleMode($bucket, $mode){ |
||
| 455 | |||
| 456 | /** |
||
| 457 | * 设置Bucket的maxAge |
||
| 458 | * maxAge为0或者负数表示为默认值(31536000) |
||
| 459 | */ |
||
| 460 | public function putBucketMaxAge($bucket, $maxAge){ |
||
| 465 | |||
| 466 | 6 | /** |
|
| 467 | * 设置配额 |
||
| 468 | 6 | * <bucket>: 空间名称,不支持授权空间 |
|
| 469 | 6 | * <size>: 空间存储量配额,参数传入0或不传表示不更改当前配置,传入-1表示取消限额,新创建的空间默认没有限额。 |
|
| 470 | 6 | * <count>: 空间文件数配额,参数含义同<size> |
|
| 471 | 6 | */ |
|
| 472 | 6 | public function putBucketQuota($bucket, $size, $count){ |
|
| 477 | 9 | ||
| 478 | /** |
||
| 479 | * 获取配额 |
||
| 480 | 9 | * bucket 空间名称 |
|
| 481 | 9 | */ |
|
| 482 | 9 | public function getBucketQuota($bucket){ |
|
| 487 | 9 | ||
| 488 | 9 | /** |
|
| 489 | 9 | * 获取资源的元信息,但不返回文件内容 |
|
| 490 | 9 | * |
|
| 491 | * @param $bucket 待获取信息资源所在的空间 |
||
| 492 | * @param $key 待获取资源的文件名 |
||
| 493 | * |
||
| 494 | * @return array 包含文件信息的数组,类似: |
||
| 495 | * [ |
||
| 496 | * "hash" => "<Hash string>", |
||
| 497 | * "key" => "<Key string>", |
||
| 498 | * "fsize" => <file size>, |
||
| 499 | * "putTime" => "<file modify time>" |
||
| 500 | * "fileType" => <file type> |
||
| 501 | * ] |
||
| 502 | * |
||
| 503 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/stat.html |
||
| 504 | */ |
||
| 505 | public function stat($bucket, $key) |
||
| 510 | |||
| 511 | /** |
||
| 512 | * 删除指定资源 |
||
| 513 | * |
||
| 514 | * @param $bucket 待删除资源所在的空间 |
||
| 515 | * @param $key 待删除资源的文件名 |
||
| 516 | * |
||
| 517 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 518 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/delete.html |
||
| 519 | */ |
||
| 520 | public function delete($bucket, $key) |
||
| 526 | |||
| 527 | |||
| 528 | /** |
||
| 529 | * 给资源进行重命名,本质为move操作。 |
||
| 530 | * |
||
| 531 | * @param $bucket 待操作资源所在空间 |
||
| 532 | * @param $oldname 待操作资源文件名 |
||
| 533 | * @param $newname 目标资源文件名 |
||
| 534 | * |
||
| 535 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 536 | */ |
||
| 537 | public function rename($bucket, $oldname, $newname) |
||
| 541 | |||
| 542 | /** |
||
| 543 | * 给资源进行重命名,本质为move操作。 |
||
| 544 | * |
||
| 545 | * @param $from_bucket 待操作资源所在空间 |
||
| 546 | * @param $from_key 待操作资源文件名 |
||
| 547 | * @param $to_bucket 目标资源空间名 |
||
| 548 | * @param $to_key 目标资源文件名 |
||
| 549 | * |
||
| 550 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 551 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/copy.html |
||
| 552 | */ |
||
| 553 | public function copy($from_bucket, $from_key, $to_bucket, $to_key, $force = false) |
||
| 564 | |||
| 565 | /** |
||
| 566 | * 将资源从一个空间到另一个空间 |
||
| 567 | * |
||
| 568 | * @param $from_bucket 待操作资源所在空间 |
||
| 569 | * @param $from_key 待操作资源文件名 |
||
| 570 | * @param $to_bucket 目标资源空间名 |
||
| 571 | * @param $to_key 目标资源文件名 |
||
| 572 | * |
||
| 573 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 574 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/move.html |
||
| 575 | */ |
||
| 576 | public function move($from_bucket, $from_key, $to_bucket, $to_key, $force = false) |
||
| 587 | |||
| 588 | /** |
||
| 589 | * 主动修改指定资源的文件元信息 |
||
| 590 | * |
||
| 591 | * @param $bucket 待操作资源所在空间 |
||
| 592 | * @param $key 待操作资源文件名 |
||
| 593 | * @param $mime 待操作文件目标mimeType |
||
| 594 | * |
||
| 595 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 596 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/chgm.html |
||
| 597 | */ |
||
| 598 | public function changeMime($bucket, $key, $mime) |
||
| 606 | |||
| 607 | |||
| 608 | /** |
||
| 609 | * 修改指定资源的存储类型 |
||
| 610 | * |
||
| 611 | * @param $bucket 待操作资源所在空间 |
||
| 612 | * @param $key 待操作资源文件名 |
||
| 613 | * @param $fileType 待操作文件目标文件类型 |
||
| 614 | * |
||
| 615 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 616 | * @link https://developer.qiniu.com/kodo/api/3710/modify-the-file-type |
||
| 617 | */ |
||
| 618 | public function changeType($bucket, $key, $fileType) |
||
| 625 | |||
| 626 | /** |
||
| 627 | * 修改文件的存储状态,即禁用状态和启用状态间的的互相转换 |
||
| 628 | * |
||
| 629 | * @param $bucket 待操作资源所在空间 |
||
| 630 | * @param $key 待操作资源文件名 |
||
| 631 | * @param $status 待操作文件目标文件类型 |
||
| 632 | * |
||
| 633 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 634 | * @link https://developer.qiniu.com/kodo/api/4173/modify-the-file-status |
||
| 635 | */ |
||
| 636 | public function changeStatus($bucket, $key, $status) |
||
| 643 | |||
| 644 | /** |
||
| 645 | * 从指定URL抓取资源,并将该资源存储到指定空间中 |
||
| 646 | * |
||
| 647 | * @param $url 指定的URL |
||
| 648 | * @param $bucket 目标资源空间 |
||
| 649 | * @param $key 目标资源文件名 |
||
| 650 | * |
||
| 651 | * @return array 包含已拉取的文件信息。 |
||
| 652 | * 成功时: [ |
||
| 653 | * [ |
||
| 654 | * "hash" => "<Hash string>", |
||
| 655 | * "key" => "<Key string>" |
||
| 656 | * ], |
||
| 657 | * null |
||
| 658 | * ] |
||
| 659 | * |
||
| 660 | * 失败时: [ |
||
| 661 | * null, |
||
| 662 | * Qiniu/Http/Error |
||
| 663 | * ] |
||
| 664 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/fetch.html |
||
| 665 | */ |
||
| 666 | public function fetch($url, $bucket, $key = null) |
||
| 679 | |||
| 680 | /** |
||
| 681 | * 从镜像源站抓取资源到空间中,如果空间中已经存在,则覆盖该资源 |
||
| 682 | * |
||
| 683 | * @param $bucket 待获取资源所在的空间 |
||
| 684 | * @param $key 代获取资源文件名 |
||
| 685 | * |
||
| 686 | * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error |
||
| 687 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/prefetch.html |
||
| 688 | */ |
||
| 689 | public function prefetch($bucket, $key) |
||
| 701 | |||
| 702 | /** |
||
| 703 | * 在单次请求中进行多个资源管理操作 |
||
| 704 | * |
||
| 705 | * @param $operations 资源管理操作数组 |
||
| 706 | * |
||
| 707 | * @return array 每个资源的处理情况,结果类似: |
||
| 708 | * [ |
||
| 709 | * { "code" => <HttpCode int>, "data" => <Data> }, |
||
| 710 | * { "code" => <HttpCode int> }, |
||
| 711 | * { "code" => <HttpCode int> }, |
||
| 712 | * { "code" => <HttpCode int> }, |
||
| 713 | * { "code" => <HttpCode int>, "data" => { "error": "<ErrorMessage string>" } }, |
||
| 714 | * ... |
||
| 715 | * ] |
||
| 716 | * @link http://developer.qiniu.com/docs/v6/api/reference/rs/batch.html |
||
| 717 | */ |
||
| 718 | public function batch($operations) |
||
| 723 | |||
| 724 | /** |
||
| 725 | * 设置文件的生命周期 |
||
| 726 | * |
||
| 727 | * @param $bucket 设置文件生命周期文件所在的空间 |
||
| 728 | * @param $key 设置文件生命周期文件的文件名 |
||
| 729 | * @param $days 设置该文件多少天后删除,当$days设置为0时表示取消该文件的生命周期 |
||
| 730 | * |
||
| 731 | * @return Mixed |
||
| 732 | * @link https://developer.qiniu.com/kodo/api/update-file-lifecycle |
||
| 733 | */ |
||
| 734 | public function deleteAfterDays($bucket, $key, $days) |
||
| 741 | |||
| 742 | private function getRsfHost() |
||
| 750 | |||
| 751 | private function getRsHost() |
||
| 759 | |||
| 760 | private function getApiHost() |
||
| 768 | |||
| 769 | private function getUcHost() |
||
| 777 | |||
| 778 | private function rsPost($path, $body = null) |
||
| 783 | |||
| 784 | private function apiPost($path, $body = null) |
||
| 789 | |||
| 790 | private function ucPost($path, $body = null) |
||
| 795 | |||
| 796 | private function ucGet($path) |
||
| 801 | |||
| 802 | private function apiGet($path) |
||
| 807 | |||
| 808 | private function rsGet($path) |
||
| 813 | |||
| 814 | private function get($url) |
||
| 823 | |||
| 824 | private function post($url, $body) |
||
| 834 | |||
| 835 | private function ucPostV2($path, $body){ |
||
| 839 | |||
| 840 | private function postV2($url, $body) |
||
| 851 | |||
| 852 | public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket, $force) |
||
| 856 | |||
| 857 | |||
| 858 | public static function buildBatchRename($bucket, $key_pairs, $force) |
||
| 862 | |||
| 863 | |||
| 864 | public static function buildBatchMove($source_bucket, $key_pairs, $target_bucket, $force) |
||
| 868 | |||
| 869 | |||
| 870 | public static function buildBatchDelete($bucket, $keys) |
||
| 874 | |||
| 875 | |||
| 876 | public static function buildBatchStat($bucket, $keys) |
||
| 880 | |||
| 881 | public static function buildBatchDeleteAfterDays($bucket, $key_day_pairs) |
||
| 889 | |||
| 890 | public static function buildBatchChangeMime($bucket, $key_mime_pairs) |
||
| 898 | |||
| 899 | public static function buildBatchChangeType($bucket, $key_type_pairs) |
||
| 907 | |||
| 908 | private static function oneKeyBatch($operation, $bucket, $keys) |
||
| 916 | |||
| 917 | private static function twoKeyBatch($operation, $source_bucket, $key_pairs, $target_bucket, $force) |
||
| 934 | } |
||
| 935 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.