6
6
use Qiniu \Http \Error ;
7
7
use Qiniu \Http \Client ;
8
8
use Qiniu \Http \Proxy ;
9
+ use Qiniu \Zone ;
9
10
10
11
/**
11
12
* 持久化处理类,该类用于主动触发异步持久化操作.
@@ -45,25 +46,34 @@ public function __construct($auth, $config = null, $proxy = null, $proxy_auth =
45
46
* 对资源文件进行异步持久化处理
46
47
* @param string $bucket 资源所在空间
47
48
* @param string $key 待处理的源文件
48
- * @param string $fops string |array 待处理的pfop操作,多个pfop操作以array的形式传入。
49
+ * @param string|array $fops 待处理的pfop操作,多个pfop操作以array的形式传入。
49
50
* eg. avthumb/mp3/ab/192k, vframe/jpg/offset/7/w/480/h/360
50
51
* @param string $pipeline 资源处理队列
51
52
* @param string $notify_url 处理结果通知地址
52
53
* @param bool $force 是否强制执行一次新的指令
54
+ * @param int $type 为 `1` 时开启闲时任务
53
55
*
54
56
*
55
- * @return array 返回持久化处理的persistentId, 和返回的错误 。
57
+ * @return array 返回持久化处理的 persistentId 与可能出现的错误 。
56
58
*
57
59
* @link http://developer.qiniu.com/docs/v6/api/reference/fop/
58
60
*/
59
- public function execute ($ bucket , $ key , $ fops , $ pipeline = null , $ notify_url = null , $ force = false )
60
- {
61
+ public function execute (
62
+ $ bucket ,
63
+ $ key ,
64
+ $ fops ,
65
+ $ pipeline = null ,
66
+ $ notify_url = null ,
67
+ $ force = false ,
68
+ $ type = null
69
+ ) {
61
70
if (is_array ($ fops )) {
62
71
$ fops = implode ('; ' , $ fops );
63
72
}
64
73
$ params = array ('bucket ' => $ bucket , 'key ' => $ key , 'fops ' => $ fops );
65
74
\Qiniu \setWithoutEmpty ($ params , 'pipeline ' , $ pipeline );
66
75
\Qiniu \setWithoutEmpty ($ params , 'notifyURL ' , $ notify_url );
76
+ \Qiniu \setWithoutEmpty ($ params , 'type ' , $ type );
67
77
if ($ force ) {
68
78
$ params ['force ' ] = 1 ;
69
79
}
@@ -72,7 +82,8 @@ public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = nu
72
82
if ($ this ->config ->useHTTPS === true ) {
73
83
$ scheme = "https:// " ;
74
84
}
75
- $ url = $ scheme . Config::API_HOST . '/pfop/ ' ;
85
+ $ apiHost = $ this ->getApiHost ();
86
+ $ url = $ scheme . $ apiHost . '/pfop/ ' ;
76
87
$ headers = $ this ->auth ->authorization ($ url , $ data , 'application/x-www-form-urlencoded ' );
77
88
$ headers ['Content-Type ' ] = 'application/x-www-form-urlencoded ' ;
78
89
$ response = Client::post ($ url , $ data , $ headers , $ this ->proxy ->makeReqOpt ());
@@ -84,18 +95,33 @@ public function execute($bucket, $key, $fops, $pipeline = null, $notify_url = nu
84
95
return array ($ id , null );
85
96
}
86
97
98
+ /**
99
+ * @param string $id
100
+ * @return array 返回任务状态与可能出现的错误
101
+ */
87
102
public function status ($ id )
88
103
{
89
104
$ scheme = "http:// " ;
90
105
91
106
if ($ this ->config ->useHTTPS === true ) {
92
107
$ scheme = "https:// " ;
93
108
}
94
- $ url = $ scheme . Config::API_HOST . "/status/get/prefop?id= $ id " ;
109
+ $ apiHost = $ this ->getApiHost ();
110
+ $ url = $ scheme . $ apiHost . "/status/get/prefop?id= $ id " ;
95
111
$ response = Client::get ($ url , array (), $ this ->proxy ->makeReqOpt ());
96
112
if (!$ response ->ok ()) {
97
113
return array (null , new Error ($ url , $ response ));
98
114
}
99
115
return array ($ response ->json (), null );
100
116
}
117
+
118
+ private function getApiHost ()
119
+ {
120
+ if (!empty ($ this ->config ->zone ) && !empty ($ this ->config ->zone ->apiHost )) {
121
+ $ apiHost = $ this ->config ->zone ->apiHost ;
122
+ } else {
123
+ $ apiHost = Config::API_HOST ;
124
+ }
125
+ return $ apiHost ;
126
+ }
101
127
}
0 commit comments