| 1 | <?php |
||
| 8 | final class Operation |
||
| 9 | { |
||
| 10 | |||
| 11 | private $auth; |
||
| 12 | private $token_expire; |
||
| 13 | private $domain; |
||
| 14 | |||
| 15 | 9 | public function __construct($domain, $auth = null, $token_expire = 3600) |
|
| 21 | |||
| 22 | |||
| 23 | /** |
||
| 24 | * 对资源文件进行处理 |
||
| 25 | * |
||
| 26 | * @param $key 待处理的资源文件名 |
||
| 27 | * @param $fops string|array fop操作,多次fop操作以array的形式传入。 |
||
| 28 | * eg. imageView2/1/w/200/h/200, imageMogr2/thumbnail/!75px |
||
| 29 | * |
||
| 30 | * @return array 文件处理后的结果及错误。 |
||
| 31 | * |
||
| 32 | * @link http://developer.qiniu.com/docs/v6/api/reference/fop/ |
||
| 33 | */ |
||
| 34 | 6 | public function execute($key, $fops) |
|
| 35 | { |
||
| 36 | 6 | $url = $this->buildUrl($key, $fops); |
|
| 37 | 6 | $resp = Client::get($url); |
|
| 38 | 6 | if (!$resp->ok()) { |
|
| 39 | 6 | return array(null, new Error($url, $resp)); |
|
| 40 | } |
||
| 41 | if ($resp->json() !== null) { |
||
| 42 | return array($resp->json(), null); |
||
| 43 | } |
||
| 44 | return array($resp->body, null); |
||
| 45 | } |
||
| 46 | |||
| 47 | 9 | public function buildUrl($key, $fops, $protocol = 'http') |
|
| 60 | } |
||
| 61 |