Skip to content

Commit 3a62355

Browse files
committed
refact fop
1 parent 9d8fa00 commit 3a62355

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

src/Qiniu/Processing/Operation.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Qiniu\Processing;
4+
5+
use Qiniu\Http\Client;
6+
use Qiniu\Http\Error;
7+
8+
final class Operation
9+
{
10+
11+
private $auth;
12+
private $token_expire;
13+
private $domain;
14+
15+
public function __construct($domain, $auth = null, $token_expire = 3600)
16+
{
17+
$this->auth = $auth;
18+
$this->domain = $domain;
19+
$this->token_expire = $token_expire;
20+
}
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+
public function execute($key, $fops)
35+
{
36+
$url = $this->buildUrl($key, $fops);
37+
$resp = Client::get($url);
38+
if (!$resp->ok()) {
39+
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+
public function buildUrl($key, $fops)
48+
{
49+
if (is_array($fops)) {
50+
implode('|', $fops)
51+
}
52+
53+
$url = "http://$this->domain/$key?$fops";
54+
if ($this->auth !== null) {
55+
$url = $this->auth->privateDownloadUrl($url, $this->token_expire);
56+
}
57+
58+
return $url;
59+
}
60+
}

src/Qiniu/Processing/PersistentFop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ public function __construct($auth, $bucket, $pipeline = null, $notify_url = null
4343
}
4444

4545
/**
46-
* 列取空间的文件列表
46+
* 对资源文件进行异步持久化处理
4747
*
4848
* @param $key 待处理的源文件
49-
* @param $fops string|array 待处理的pfop操作,多个操作已array的形式传入
49+
* @param $fops string|array 待处理的pfop操作,多个pfop操作以array的形式传入
5050
* eg. avthumb/mp3/ab/192k, vframe/jpg/offset/7/w/480/h/360
5151
*
5252
* @return array[] 返回持久化处理的persistentId, 和返回的错误。

0 commit comments

Comments
 (0)