4
4
use Qiniu \Config ;
5
5
use Qiniu \Http \Client ;
6
6
use Qiniu \Http \Error ;
7
+ use Qiniu \Processing \Operation ;
7
8
8
9
final class PersistentFop
9
10
{
10
11
private $ auth ;
11
- private $ bucket ;
12
- private $ pipeline ;
13
- private $ notify_url ;
12
+ private $ bucket ;
13
+ private $ pipeline ;
14
+ private $ notify_url ;
14
15
15
- public function __construct ($ auth , $ bucket , $ pipeline = null , $ notify_url = null )
16
+ public function __construct ($ auth , $ bucket , $ pipeline = null , $ notify_url = null , $ force = false )
16
17
{
17
18
$ this ->auth = $ auth ;
18
19
$ this ->bucket = $ bucket ;
19
20
$ this ->pipeline = $ pipeline ;
20
21
$ this ->notify_url = $ notify_url ;
22
+ $ this ->force = $ force ;
21
23
}
22
24
23
- public function execute ($ key , array $ fops, $ force = false )
25
+ public function execute ($ key , array $ fops )
24
26
{
25
27
$ ops = implode ('; ' , $ fops );
26
28
$ params = array ('bucket ' => $ this ->bucket , 'key ' => $ key , 'fops ' => $ ops );
@@ -30,15 +32,15 @@ public function execute($key, array $fops, $force = false)
30
32
if (!empty ($ this ->notify_url )) {
31
33
$ params ['notifyURL ' ] = $ this ->notify_url ;
32
34
}
33
- if ($ force ) {
35
+ if ($ this -> force ) {
34
36
$ params ['force ' ] = 1 ;
35
37
}
36
38
$ data = http_build_query ($ params );
37
39
$ url = Config::API_HOST . '/pfop/ ' ;
38
40
$ headers = $ this ->auth ->authorization ($ url , $ data , 'application/x-www-form-urlencoded ' );
39
41
$ headers ['Content-Type ' ] = 'application/x-www-form-urlencoded ' ;
40
42
$ response = Client::post ($ url , $ data , $ headers );
41
- if ($ response ->statusCode != 200 ) {
43
+ if (! $ response ->ok () ) {
42
44
return array (null , new Error ($ url , $ response ));
43
45
}
44
46
$ r = $ response ->json ();
@@ -50,9 +52,43 @@ public static function status($id)
50
52
{
51
53
$ url = Config::API_HOST . "/status/get/prefop?id= $ id " ;
52
54
$ response = Client::get ($ url );
53
- if ($ response ->statusCode != 200 ) {
55
+ if (! $ response ->ok () ) {
54
56
return array (null , new Error ($ url , $ response ));
55
57
}
56
58
return array ($ response ->json (), null );
57
59
}
60
+
61
+ public function __call ($ method , $ args )
62
+ {
63
+ $ key = $ args [0 ];
64
+ $ cmd = $ method ;
65
+ $ mod = null ;
66
+ if (count ($ args )>1 ) {
67
+ $ mod = $ args [1 ];
68
+ }
69
+
70
+ $ options = array ();
71
+ if (count ($ args )>2 ) {
72
+ $ options = $ args [2 ];
73
+ }
74
+
75
+ $ target_bucket = null ;
76
+ if (count ($ args )>3 ) {
77
+ $ target_bucket = $ args [3 ];
78
+ }
79
+
80
+ $ target_key = null ;
81
+ if (count ($ args )>4 ) {
82
+ $ target_key = $ args [4 ];
83
+ }
84
+
85
+ $ pfop = Operation::buildOp ($ cmd , $ mod , $ options );
86
+ if ($ target_bucket != null ) {
87
+ $ pfop = Operation::saveas ($ pfop , $ target_bucket , $ target_key );
88
+ }
89
+
90
+ $ ops = array ();
91
+ array_push ($ ops , $ pfop );
92
+ return $ this ->execute ($ key , $ ops );
93
+ }
58
94
}
0 commit comments