Skip to content

Commit 1691d22

Browse files
authored
Add V2 implements (#12)
* Add lifecycle * Add Cors * Fix phpunit * Rename .travis to .travis.yml * Fix test * Fix test * Fix test * Fix test * Fix test * Update test
1 parent 4ee5524 commit 1691d22

File tree

10 files changed

+1681
-410
lines changed

10 files changed

+1681
-410
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: php
2+
php:
3+
- 5.6
4+
script: phpunit -v

cos-autoloader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
'Qcloud\Cos\Exception\ServiceResponseException' => 'src/Qcloud/Cos/Exception/ServiceResponseException.php',
249249
'Qcloud\Cos\ExceptionListener' => 'src/Qcloud/Cos/ExceptionListener.php',
250250
'Qcloud\Cos\ExceptionParser' => 'src/Qcloud/Cos/ExceptionParser.php',
251+
'Qcloud\Cos\Md5Listener' => 'src/Qcloud/Cos/Md5Listener.php',
251252
'Qcloud\Cos\MultipartUpload' => 'src/Qcloud/Cos/MultipartUpload.php',
252253
'Qcloud\Cos\Service' => 'src/Qcloud/Cos/Service.php',
253254
'Qcloud\Cos\Signature' => 'src/Qcloud/Cos/Signature.php',
@@ -277,4 +278,4 @@
277278
if (isset($mapping[$class])) {
278279
require $mapping[$class];
279280
}
280-
}, true);
281+
}, true);

sample.php

Lines changed: 253 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
require(__DIR__ . DIRECTORY_SEPARATOR . 'cos-autoloader.php');
44

5-
$cosClient = new Qcloud\Cos\Client(
6-
array(
7-
'region' => 'cn-north',
8-
'credentials'=> array(
9-
'appId' => '',
10-
'secretId' => '',
11-
'secretKey' => '')));
12-
#listBuckets
13-
try {
14-
$result = $cosClient->listBuckets();
15-
print_r($result);
16-
} catch (\Exception $e) {
17-
echo "$e\n";
18-
}
19-
20-
5+
$cosClient = new Qcloud\Cos\Client(array('region' => getenv('COS_REGION'),
6+
'credentials'=> array(
7+
'appId' => getenv('COS_APPID'),
8+
'secretId' => getenv('COS_KEY'),
9+
'secretKey' => getenv('COS_SECRET'))));
10+
//#listBuckets
11+
//try {
12+
// $result = $cosClient->listBuckets();
13+
// print_r($result);
14+
//} catch (\Exception $e) {
15+
// echo "$e\n";
16+
//}
17+
//
18+
//
2119
#createBucket
2220
try {
2321
$result = $cosClient->createBucket(array('Bucket' => 'testbucket'));
@@ -26,91 +24,257 @@
2624
echo "$e\n";
2725
}
2826

29-
#uploadbigfile
30-
try {
31-
$result = $cosClient->upload(
32-
$bucket='testbucket',
33-
'111.txt',
34-
str_repeat('a', 5* 1024 * 1024));
35-
print_r($result);
36-
} catch (\Exception $e) {
37-
echo "$e\n";
38-
}
39-
40-
#putObject
27+
//#uploadbigfile
28+
//try {
29+
// $result = $cosClient->upload(
30+
// $bucket='testbucket',
31+
// '111.txt',
32+
// str_repeat('a', 5* 1024 * 1024));
33+
// print_r($result);1
34+
// } catch (\Exception $e) {
35+
// echo "$e\n";
36+
//}
37+
//
38+
//#putObject
4139
try {
4240
$result = $cosClient->putObject(array(
4341
'Bucket' => 'testbucket',
44-
'Key' => '111',
42+
'Key' => '11',
4543
'Body' => 'Hello World!'));
4644
print_r($result);
4745
} catch (\Exception $e) {
4846
echo "$e\n";
4947
}
50-
51-
#getObject
52-
try {
53-
$result = $cosClient->getObject(array(
54-
'Bucket' => 'testbucket',
55-
'Key' => '111',
56-
'Body' => 'Hello World!'));
57-
print_r($result);
58-
} catch (\Exception $e) {
59-
echo "$e\n";
60-
}
61-
62-
#deleteObject
63-
try {
64-
$result = $cosClient->deleteObject(array(
65-
'Bucket' => 'testbucket',
66-
'Key' => '111'));
67-
print_r($result);
68-
} catch (\Exception $e) {
69-
echo "$e\n";
70-
}
71-
72-
73-
#deleteBucket
48+
//
49+
//#getObject
50+
//try {
51+
// $result = $cosClient->getObject(array(
52+
// 'Bucket' => 'testbucket',
53+
// 'Key' => '111'));
54+
// echo($result['Body']);
55+
//} catch (\Exception $e) {
56+
// echo "$e\n";
57+
//}
58+
//
59+
//#deleteObject
60+
//try {
61+
// $result = $cosClient->deleteObject(array(
62+
// 'Bucket' => 'testbucket',
63+
// 'Key' => '111'));
64+
// print_r($result);
65+
//} catch (\Exception $e) {
66+
// echo "$e\n";
67+
//}
68+
//
69+
//
70+
//#deleteBucket
71+
//try {
72+
// $result = $cosClient->deleteBucket(array(
73+
// 'Bucket' => 'testbucket'));
74+
// print_r($result);
75+
//} catch (\Exception $e) {
76+
// echo "$e\n";
77+
//}
78+
//
79+
//#headObject
80+
//try {
81+
// $result = $cosClient->headObject(array(
82+
// 'Bucket' => 'testbucket',
83+
// 'Key' => 'hello.txt'));
84+
// print_r($result);
85+
//} catch (\Exception $e) {
86+
// echo "$e\n";
87+
//}
88+
//
89+
//#listObjects
90+
//try {
91+
// $result = $cosClient->listObjects(array(
92+
// 'Bucket' => 'testbucket'));
93+
// print_r($result);
94+
//} catch (\Exception $e) {
95+
// echo "$e\n";
96+
//}
97+
//#putObjectUrl
98+
//try {
99+
// $bucket = 'testbucket';
100+
// $key = 'hello.txt';
101+
// $region = 'cn-south';
102+
// $url = "/{$key}";
103+
// $request = $cosClient->get($url);
104+
// $signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes');
105+
// echo ($signedUrl);
106+
//
107+
//} catch (\Exception $e) {
108+
// echo "$e\n";
109+
//}
110+
//#putBucketACL
111+
//try {
112+
// $result = $cosClient->PutBucketAcl(array(
113+
// 'Bucket' => 'testbucket',
114+
// 'Grants' => array(
115+
// array(
116+
// 'Grantee' => array(
117+
// 'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225',
118+
// 'ID' => 'qcs::cam::uin/327874225:uin/327874225',
119+
// 'Type' => 'CanonicalUser',
120+
// ),
121+
// 'Permission' => 'FULL_CONTROL',
122+
// ),
123+
// // ... repeated
124+
// ),
125+
// 'Owner' => array(
126+
// 'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098',
127+
// 'ID' => 'qcs::cam::uin/3210232098:uin/3210232098',
128+
// ),));
129+
// print_r($result);
130+
//} catch (\Exception $e) {
131+
// echo "$e\n";
132+
//}
133+
//#getBucketACL
134+
//try {
135+
// $result = $cosClient->GetBucketAcl(array(
136+
// 'Bucket' => 'testbucket',));
137+
// print_r($result);
138+
//} catch (\Exception $e) {
139+
// echo "$e\n";
140+
//}
141+
//
142+
#putObjectACL
74143
try {
75-
$result = $cosClient->deleteBucket(array(
76-
'Bucket' => 'testbucket'));
77-
print_r($result);
78-
} catch (\Exception $e) {
79-
echo "$e\n";
80-
}
81-
82-
#headObject
83-
try {
84-
$result = $cosClient->headObject(array(
144+
$result = $cosClient->PutBucketAcl(array(
85145
'Bucket' => 'testbucket',
86-
'Key' => 'hello.txt'));
146+
'Grants' => array(
147+
array(
148+
'Grantee' => array(
149+
'DisplayName' => 'qcs::cam::uin/327874225:uin/327874225',
150+
'ID' => 'qcs::cam::uin/327874225:uin/327874225',
151+
'Type' => 'CanonicalUser',
152+
),
153+
'Permission' => 'FULL_CONTROL',
154+
),
155+
// ... repeated
156+
),
157+
'Owner' => array(
158+
'DisplayName' => 'qcs::cam::uin/3210232098:uin/3210232098',
159+
'ID' => 'qcs::cam::uin/3210232098:uin/3210232098',
160+
),));
87161
print_r($result);
88162
} catch (\Exception $e) {
89163
echo "$e\n";
90164
}
91165

92-
#listObjects
93-
try {
94-
$result = $cosClient->listObjects(array(
95-
'Bucket' => 'testbucket'));
96-
print_r($result);
97-
} catch (\Exception $e) {
98-
echo "$e\n";
99-
}
100-
101-
102-
#getObjectUrl
103-
try {
104-
$bucket = 'testbucket';
105-
$key = 'hello.txt';
106-
$region = 'cn-south';
107-
$url = "/{$key}";
108-
$request = $cosClient->get($url);
109-
$signedUrl = $cosClient->getObjectUrl($bucket, $key, '+10 minutes');
110-
echo ($signedUrl);
111-
112-
} catch (\Exception $e) {
113-
echo "$e\n";
114-
}
115-
116-
166+
//#getObjectACL
167+
//try {
168+
// $result = $cosClient->getObjectAcl(array(
169+
// 'Bucket' => 'testbucket',
170+
// 'Key' => '11'));
171+
// print_r($result);
172+
//} catch (\Exception $e) {
173+
// echo "$e\n";
174+
//}
175+
//#putBucketLifecycle
176+
//try {
177+
// $result = $cosClient->putBucketLifecycle(array(
178+
// // Bucket is required
179+
// 'Bucket' => 'lewzylu02',
180+
// // Rules is required
181+
// 'Rules' => array(
182+
// array(
183+
// 'Expiration' => array(
184+
// 'Days' => 1,
185+
// ),
186+
// 'ID' => 'id1',
187+
// 'Filter' => array(
188+
// 'Prefix' => 'documents/'
189+
// ),
190+
// // Status is required
191+
// 'Status' => 'Enabled',
192+
// 'Transition' => array(
193+
// 'Days' => 100,
194+
// 'StorageClass' => 'NEARLINE',
195+
// ),
196+
// // ... repeated
197+
// ),
198+
// )));
199+
// print_r($result);
200+
//} catch (\Exception $e) {
201+
// echo "$e\n";
202+
//}
203+
//#getBucketLifecycle
204+
//try {
205+
// $result = $cosClient->getBucketLifecycle(array(
206+
// // Bucket is required
207+
// 'Bucket' =>'lewzylu02',
208+
// ));
209+
// print_r($result);
210+
//} catch (\Exception $e) {
211+
// echo "$e\n";
212+
//}
213+
//
214+
//#deleteBucketLifecycle
215+
//try {
216+
// $result = $cosClient->deleteBucketLifecycle(array(
217+
// // Bucket is required
218+
// 'Bucket' =>'lewzylu02',
219+
// ));
220+
// print_r($result);
221+
//} catch (\Exception $e) {
222+
// echo "$e\n";
223+
//}
224+
//#putBucketCors
225+
//try {
226+
// $result = $cosClient->putBucketCors(array(
227+
// // Bucket is required
228+
// 'Bucket' => 'lewzylu02',
229+
// // CORSRules is required
230+
// 'CORSRules' => array(
231+
// array(
232+
// 'AllowedHeaders' => array('*',),
233+
// // AllowedMethods is required
234+
// 'AllowedMethods' => array('Put', ),
235+
// // AllowedOrigins is required
236+
// 'AllowedOrigins' => array('*', ),
237+
// 'ExposeHeaders' => array('*', ),
238+
// 'MaxAgeSeconds' => 1,
239+
// ),
240+
// // ... repeated
241+
// ),
242+
// ));
243+
// print_r($result);
244+
//} catch (\Exception $e) {
245+
// echo "$e\n";
246+
//}
247+
//#getBucketCors
248+
//try {
249+
// $result = $cosClient->getBucketCors(array(
250+
// // Bucket is required
251+
// 'Bucket' => 'lewzylu02',
252+
// ));
253+
// print_r($result);
254+
//} catch (\Exception $e) {
255+
// echo "$e\n";
256+
//}
257+
//#deleteBucketCors
258+
//try {
259+
// $result = $cosClient->deleteBucketCors(array(
260+
// // Bucket is required
261+
// 'Bucket' => 'lewzylu02',
262+
// ));
263+
// print_r($result);
264+
//} catch (\Exception $e) {
265+
// echo "$e\n";
266+
//}
267+
//#copyobject
268+
//try {
269+
// $result = $cosClient->copyObject(array(
270+
// // Bucket is required
271+
// 'Bucket' => 'lewzylu02',
272+
// // CopySource is required
273+
// 'CopySource' => 'lewzylu03-1252448703.cos.ap-guangzhou.myqcloud.com/tox.ini',
274+
// // Key is required
275+
// 'Key' => 'string',
276+
// ));
277+
// print_r($result);
278+
//} catch (\Exception $e) {
279+
// echo "$e\n";
280+
//}

0 commit comments

Comments
 (0)