Skip to content

Commit 7184b01

Browse files
yangzong18huiguangjun
authored andcommitted
add restore info and owner to object list
1 parent fc2388f commit 7184b01

File tree

7 files changed

+360
-120
lines changed

7 files changed

+360
-120
lines changed

samples/Object.php

Lines changed: 153 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
$tier = 'Expedited';
5656
$config = new RestoreConfig($day,$tier);
5757
$options = array(
58-
OssClient::OSS_RESTORE_CONFIG => $config
58+
OssClient::OSS_RESTORE_CONFIG => $config
5959
);
6060
$ossClient->restoreObject($bucket, 'b.file',$options);
6161

@@ -93,9 +93,9 @@
9393

9494
// The speed limit is 100 KB/s, which is 819200 bit/s.
9595
$options = array(
96-
OssClient::OSS_HEADERS => array(
97-
OssClient::OSS_TRAFFIC_LIMIT => 819200,
98-
));
96+
OssClient::OSS_HEADERS => array(
97+
OssClient::OSS_TRAFFIC_LIMIT => 819200,
98+
));
9999
// Speed limit upload.
100100
$ossClient->putObject($bucket, $object, $content, $options);
101101

@@ -205,7 +205,7 @@ function uploadFile($ossClient, $bucket)
205205
}
206206

207207
/**
208-
* Lists all files and folders in the bucket.
208+
* Lists all files and folders in the bucket.
209209
* Note if there's more items than the max-keys specified, the caller needs to use the nextMarker returned as the value for the next call's maker paramter.
210210
* Loop through all the items returned from ListObjects.
211211
*
@@ -227,30 +227,47 @@ function listObjects($ossClient, $bucket)
227227
);
228228
try {
229229
$listObjectInfo = $ossClient->listObjects($bucket, $options);
230+
printf("Bucket Name: %s". "\n",$listObjectInfo->getBucketName());
231+
printf("Prefix: %s". "\n",$listObjectInfo->getPrefix());
232+
printf("Marker: %s". "\n",$listObjectInfo->getMarker());
233+
printf("Next Marker: %s". "\n",$listObjectInfo->getNextMarker());
234+
printf("Max Keys: %s". "\n",$listObjectInfo->getMaxKeys());
235+
printf("Delimiter: %s". "\n",$listObjectInfo->getDelimiter());
236+
printf("Is Truncated: %s". "\n",$listObjectInfo->getIsTruncated());
237+
$objectList = $listObjectInfo->getObjectList(); // object list
238+
$prefixList = $listObjectInfo->getPrefixList(); // directory list
239+
if (!empty($objectList)) {
240+
print("objectList:\n");
241+
foreach ($objectList as $objectInfo) {
242+
printf("Object Name: %s". "\n",$objectInfo->getKey());
243+
printf("Object Size: %s". "\n",$objectInfo->getSize());
244+
printf("Object Type: %s". "\n",$objectInfo->getType());
245+
printf("Object ETag: %s". "\n",$objectInfo->getETag());
246+
printf("Object Last Modified: %s". "\n",$objectInfo->getLastModified());
247+
printf("Object Storage Class: %s". "\n",$objectInfo->getStorageClass());
248+
249+
if ($objectInfo->getRestoreInfo()){
250+
printf("Restore Info: %s". "\n",$objectInfo->getRestoreInfo() );
251+
}
252+
253+
if($objectInfo->getOwner()){
254+
printf("Owner Id:".$objectInfo->getOwner()->getId() . "\n");
255+
printf("Owner Name:".$objectInfo->getOwner()->getDisplayName() . "\n");
256+
}
257+
}
258+
}
259+
if (!empty($prefixList)) {
260+
print("prefixList: \n");
261+
foreach ($prefixList as $prefixInfo) {
262+
printf("Common Prefix:%s\n",$prefixInfo->getPrefix());
263+
}
264+
}
230265
} catch (OssException $e) {
231266
printf(__FUNCTION__ . ": FAILED\n");
232267
printf($e->getMessage() . "\n");
233268
return;
234269
}
235270
print(__FUNCTION__ . ": OK" . "\n");
236-
$objectList = $listObjectInfo->getObjectList(); // object list
237-
$prefixList = $listObjectInfo->getPrefixList(); // directory list
238-
if (!empty($objectList)) {
239-
print("objectList:\n");
240-
foreach ($objectList as $objectInfo) {
241-
print($objectInfo->getKey() . "\n");
242-
if($objectInfo->getOwner() != null){
243-
printf("owner id:".$objectInfo->getOwner()->getId() . "\n");
244-
printf("owner name:".$objectInfo->getOwner()->getDisplayName() . "\n");
245-
}
246-
}
247-
}
248-
if (!empty($prefixList)) {
249-
print("prefixList: \n");
250-
foreach ($prefixList as $prefixInfo) {
251-
print($prefixInfo->getPrefix() . "\n");
252-
}
253-
}
254271
}
255272

256273
/**
@@ -264,42 +281,61 @@ function listObjects($ossClient, $bucket)
264281
*/
265282
function listObjectsV2($ossClient, $bucket)
266283
{
267-
$prefix = 'oss-php-sdk-test/';
268-
$delimiter = '/';
269-
$maxkeys = 1000;
270-
$options = array(
271-
'delimiter' => $delimiter,
272-
'prefix' => $prefix,
273-
'max-keys' => $maxkeys,
274-
'start-after' =>'test-object',
275-
'fetch-owner' =>'true',
276-
);
277-
try {
278-
$listObjectInfo = $ossClient->listObjectsV2($bucket, $options);
279-
} catch (OssException $e) {
280-
printf(__FUNCTION__ . ": FAILED\n");
281-
printf($e->getMessage() . "\n");
282-
return;
283-
}
284-
print(__FUNCTION__ . ": OK" . "\n");
285-
$objectList = $listObjectInfo->getObjectList(); // object list
286-
$prefixList = $listObjectInfo->getPrefixList(); // directory list
287-
if (!empty($objectList)) {
288-
print("objectList:\n");
289-
foreach ($objectList as $objectInfo) {
290-
print($objectInfo->getKey() . "\n");
291-
if($objectInfo->getOwner() != null){
292-
printf("owner id:".$objectInfo->getOwner()->getId() . "\n");
293-
printf("owner name:".$objectInfo->getOwner()->getDisplayName() . "\n");
294-
}
295-
}
296-
}
297-
if (!empty($prefixList)) {
298-
print("prefixList: \n");
299-
foreach ($prefixList as $prefixInfo) {
300-
print($prefixInfo->getPrefix() . "\n");
301-
}
302-
}
284+
$prefix = 'oss-php-sdk-test/';
285+
$delimiter = '/';
286+
$maxkeys = 1000;
287+
$options = array(
288+
'delimiter' => $delimiter,
289+
'prefix' => $prefix,
290+
'max-keys' => $maxkeys,
291+
'start-after' =>'test-object',
292+
'fetch-owner' =>'true',
293+
);
294+
try {
295+
$listObjectInfo = $ossClient->listObjectsV2($bucket, $options);
296+
printf("Bucket Name: %s". "\n",$listObjectInfo->getBucketName());
297+
printf("Prefix: %s". "\n",$listObjectInfo->getPrefix());
298+
printf("Next Continuation Token: %s". "\n",$listObjectInfo->getNextContinuationToken());
299+
printf("Continuation Token: %s". "\n",$listObjectInfo->getContinuationToken());
300+
printf("Max Keys: %s". "\n",$listObjectInfo->getMaxKeys());
301+
printf("Key Count: %s". "\n",$listObjectInfo->getKeyCount());
302+
printf("Delimiter: %s". "\n",$listObjectInfo->getDelimiter());
303+
printf("Is Truncated: %s". "\n",$listObjectInfo->getIsTruncated());
304+
printf("Start After: %s". "\n",$listObjectInfo->getStartAfter());
305+
$objectList = $listObjectInfo->getObjectList(); // object list
306+
$prefixList = $listObjectInfo->getPrefixList(); // directory list
307+
if (!empty($objectList)) {
308+
print("objectList:\n");
309+
foreach ($objectList as $objectInfo) {
310+
printf("Object Name: %s". "\n",$objectInfo->getKey());
311+
printf("Object Size: %s". "\n",$objectInfo->getSize());
312+
printf("Object Type: %s". "\n",$objectInfo->getType());
313+
printf("Object ETag: %s". "\n",$objectInfo->getETag());
314+
printf("Object Last Modified: %s". "\n",$objectInfo->getLastModified());
315+
printf("Object Storage Class: %s". "\n",$objectInfo->getStorageClass());
316+
317+
if ($objectInfo->getRestoreInfo()){
318+
printf("Restore Info: %s". "\n",$objectInfo->getRestoreInfo() );
319+
}
320+
321+
if($objectInfo->getOwner()){
322+
printf("Owner Id:".$objectInfo->getOwner()->getId() . "\n");
323+
printf("Owner Name:".$objectInfo->getOwner()->getDisplayName() . "\n");
324+
}
325+
}
326+
}
327+
if (!empty($prefixList)) {
328+
print("prefixList: \n");
329+
foreach ($prefixList as $prefixInfo) {
330+
printf("Common Prefix:%s\n",$prefixInfo->getPrefix());
331+
}
332+
}
333+
} catch (OssException $e) {
334+
printf(__FUNCTION__ . ": FAILED\n");
335+
printf($e->getMessage() . "\n");
336+
return;
337+
}
338+
print(__FUNCTION__ . ": OK" . "\n");
303339
}
304340

305341
/**
@@ -623,20 +659,20 @@ function doesObjectExist($ossClient, $bucket)
623659
*/
624660
function putObjectSpeed($ossClient, $bucket)
625661
{
626-
$object = "upload-test-object-name.txt";
627-
$content = file_get_contents(__FILE__);
628-
$options = array(
629-
OssClient::OSS_HEADERS => array(
630-
OssClient::OSS_TRAFFIC_LIMIT => 819200,
631-
));
632-
try {
633-
$ossClient->putObject($bucket, $object, $content, $options);
634-
} catch (OssException $e) {
635-
printf(__FUNCTION__ . ": FAILED\n");
636-
printf($e->getMessage() . "\n");
637-
return;
638-
}
639-
print(__FUNCTION__ . ": OK" . "\n");
662+
$object = "upload-test-object-name.txt";
663+
$content = file_get_contents(__FILE__);
664+
$options = array(
665+
OssClient::OSS_HEADERS => array(
666+
OssClient::OSS_TRAFFIC_LIMIT => 819200,
667+
));
668+
try {
669+
$ossClient->putObject($bucket, $object, $content, $options);
670+
} catch (OssException $e) {
671+
printf(__FUNCTION__ . ": FAILED\n");
672+
printf($e->getMessage() . "\n");
673+
return;
674+
}
675+
print(__FUNCTION__ . ": OK" . "\n");
640676
}
641677

642678
/**
@@ -648,19 +684,19 @@ function putObjectSpeed($ossClient, $bucket)
648684
*/
649685
function getObjectSpeed($ossClient, $bucket)
650686
{
651-
$object = "upload-test-object-name.txt";
652-
$options = array(
653-
OssClient::OSS_HEADERS => array(
654-
OssClient::OSS_TRAFFIC_LIMIT => 819200,
655-
));
656-
try {
657-
$ossClient->getObject($bucket, $object, $options);
658-
} catch (OssException $e) {
659-
printf(__FUNCTION__ . ": FAILED\n");
660-
printf($e->getMessage() . "\n");
661-
return;
662-
}
663-
print(__FUNCTION__ . ": OK" . "\n");
687+
$object = "upload-test-object-name.txt";
688+
$options = array(
689+
OssClient::OSS_HEADERS => array(
690+
OssClient::OSS_TRAFFIC_LIMIT => 819200,
691+
));
692+
try {
693+
$ossClient->getObject($bucket, $object, $options);
694+
} catch (OssException $e) {
695+
printf(__FUNCTION__ . ": FAILED\n");
696+
printf($e->getMessage() . "\n");
697+
return;
698+
}
699+
print(__FUNCTION__ . ": OK" . "\n");
664700
}
665701

666702
/**
@@ -672,14 +708,14 @@ function getObjectSpeed($ossClient, $bucket)
672708
*/
673709
function signUrlSpeedUpload($ossClient, $bucket)
674710
{
675-
$object = "upload-test-object-name.txt";
676-
$timeout = 120;
677-
$options = array(
678-
OssClient::OSS_TRAFFIC_LIMIT => 819200,
679-
);
680-
$timeout = 60;
681-
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT", $options);
682-
print($signedUrl);
711+
$object = "upload-test-object-name.txt";
712+
$timeout = 120;
713+
$options = array(
714+
OssClient::OSS_TRAFFIC_LIMIT => 819200,
715+
);
716+
$timeout = 60;
717+
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "PUT", $options);
718+
print($signedUrl);
683719
}
684720

685721

@@ -692,14 +728,14 @@ function signUrlSpeedUpload($ossClient, $bucket)
692728
*/
693729
function signUrlSpeedDownload($ossClient, $bucket)
694730
{
695-
$object = "upload-test-object-name.txt";
696-
$timeout = 120;
697-
$options = array(
698-
OssClient::OSS_TRAFFIC_LIMIT => 819200,
699-
);
700-
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET", $options);
701-
print($signedUrl);
702-
print(__FUNCTION__ . ": OK" . "\n");
731+
$object = "upload-test-object-name.txt";
732+
$timeout = 120;
733+
$options = array(
734+
OssClient::OSS_TRAFFIC_LIMIT => 819200,
735+
);
736+
$signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET", $options);
737+
print($signedUrl);
738+
print(__FUNCTION__ . ": OK" . "\n");
703739
}
704740

705741
/**
@@ -711,19 +747,19 @@ function signUrlSpeedDownload($ossClient, $bucket)
711747
*/
712748
function restoreObject($ossClient, $bucket)
713749
{
714-
$object = "oss-php-sdk-test/upload-test-object-name.txt";
715-
$day = 3;
716-
$tier = 'Expedited';
717-
$config = new RestoreConfig($day,$tier);
718-
$options = array(
719-
OssClient::OSS_RESTORE_CONFIG => $config
720-
);
721-
try {
722-
$ossClient->restoreObject($bucket, $object,$options);
723-
} catch (OssException $e) {
724-
printf(__FUNCTION__ . ": FAILED\n");
725-
printf($e->getMessage() . "\n");
726-
return;
727-
}
728-
print(__FUNCTION__ . ": OK" . "\n");
750+
$object = "oss-php-sdk-test/upload-test-object-name.txt";
751+
$day = 3;
752+
$tier = 'Expedited';
753+
$config = new RestoreConfig($day,$tier);
754+
$options = array(
755+
OssClient::OSS_RESTORE_CONFIG => $config
756+
);
757+
try {
758+
$ossClient->restoreObject($bucket, $object,$options);
759+
} catch (OssException $e) {
760+
printf(__FUNCTION__ . ": FAILED\n");
761+
printf($e->getMessage() . "\n");
762+
return;
763+
}
764+
print(__FUNCTION__ . ": OK" . "\n");
729765
}

src/OSS/Model/ObjectInfo.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@ class ObjectInfo
2424
* @param string $type
2525
* @param string $size
2626
* @param string $storageClass
27+
* @param Owner|null $owner
28+
* @param null $restoreInfo
2729
*/
28-
public function __construct($key, $lastModified, $eTag, $type, $size, $storageClass)
30+
public function __construct($key, $lastModified, $eTag, $type, $size, $storageClass,$owner=null,$restoreInfo=null)
2931
{
3032
$this->key = $key;
3133
$this->lastModified = $lastModified;
3234
$this->eTag = $eTag;
3335
$this->type = $type;
3436
$this->size = $size;
3537
$this->storageClass = $storageClass;
38+
$this->owner = $owner;
39+
$this->restoreInfo = $restoreInfo;
3640
}
3741

3842
/**
@@ -94,10 +98,32 @@ public function getStorageClass()
9498
return $this->storageClass;
9599
}
96100

101+
/**
102+
* @return string
103+
*/
104+
public function getRestoreInfo()
105+
{
106+
return $this->restoreInfo;
107+
}
108+
109+
110+
/**
111+
* @return Owner|null
112+
*/
113+
public function getOwner()
114+
{
115+
return $this->owner;
116+
}
117+
97118
private $key = "";
98119
private $lastModified = "";
99120
private $eTag = "";
100121
private $type = "";
101122
private $size = "0";
102123
private $storageClass = "";
124+
/**
125+
* @var Owner
126+
*/
127+
private $owner;
128+
private $restoreInfo;
103129
}

0 commit comments

Comments
 (0)