ListObjectVersionsResult.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace OSS\Result;
  3. use OSS\Core\OssUtil;
  4. use OSS\Model\ObjectVersionInfo;
  5. use OSS\Model\ObjectVersionListInfo;
  6. use OSS\Model\DeleteMarkerInfo;
  7. use OSS\Model\PrefixInfo;
  8. /**
  9. * Class ListObjectVersionsResult
  10. * @package OSS\Result
  11. */
  12. class ListObjectVersionsResult extends Result
  13. {
  14. /**
  15. * Parse the xml data returned by the ListObjectVersions interface
  16. *
  17. * return ObjectVersionListInfo
  18. */
  19. protected function parseDataFromResponse()
  20. {
  21. $xml = simplexml_load_string($this->rawResponse->body);
  22. $encodingType = isset($xml->EncodingType) ? strval($xml->EncodingType) : "";
  23. $objectVersionList = $this->parseObjecVersionList($xml, $encodingType);
  24. $deleteMarkerList = $this->parseDeleteMarkerList($xml, $encodingType);
  25. $prefixList = $this->parsePrefixList($xml, $encodingType);
  26. $bucketName = isset($xml->Name) ? strval($xml->Name) : "";
  27. $prefix = isset($xml->Prefix) ? strval($xml->Prefix) : "";
  28. $prefix = OssUtil::decodeKey($prefix, $encodingType);
  29. $keyMarker = isset($xml->KeyMarker) ? strval($xml->KeyMarker) : "";
  30. $keyMarker = OssUtil::decodeKey($keyMarker, $encodingType);
  31. $nextKeyMarker = isset($xml->NextKeyMarker) ? strval($xml->NextKeyMarker) : "";
  32. $nextKeyMarker = OssUtil::decodeKey($nextKeyMarker, $encodingType);
  33. $versionIdMarker = isset($xml->VersionIdMarker) ? strval($xml->VersionIdMarker) : "";
  34. $nextVersionIdMarker = isset($xml->NextVersionIdMarker) ? strval($xml->NextVersionIdMarker) : "";
  35. $maxKeys = isset($xml->MaxKeys) ? intval($xml->MaxKeys) : 0;
  36. $delimiter = isset($xml->Delimiter) ? strval($xml->Delimiter) : "";
  37. $delimiter = OssUtil::decodeKey($delimiter, $encodingType);
  38. $isTruncated = isset($xml->IsTruncated) ? strval($xml->IsTruncated) : "";
  39. return new ObjectVersionListInfo($bucketName, $prefix, $keyMarker, $nextKeyMarker,
  40. $versionIdMarker, $nextVersionIdMarker,$maxKeys, $delimiter, $isTruncated,
  41. $objectVersionList, $deleteMarkerList, $prefixList);
  42. }
  43. private function parseObjecVersionList($xml, $encodingType)
  44. {
  45. $retList = array();
  46. if (isset($xml->Version)) {
  47. foreach ($xml->Version as $content) {
  48. $key = isset($content->Key) ? strval($content->Key) : "";
  49. $key = OssUtil::decodeKey($key, $encodingType);
  50. $versionId = isset($content->VersionId) ? strval($content->VersionId) : "";
  51. $lastModified = isset($content->LastModified) ? strval($content->LastModified) : "";
  52. $eTag = isset($content->ETag) ? strval($content->ETag) : "";
  53. $type = isset($content->Type) ? strval($content->Type) : "";
  54. $size = isset($content->Size) ? intval($content->Size) : 0;
  55. $storageClass = isset($content->StorageClass) ? strval($content->StorageClass) : "";
  56. $isLatest = isset($content->IsLatest) ? strval($content->IsLatest) : "";
  57. $retList[] = new ObjectVersionInfo($key, $versionId, $lastModified, $eTag, $type, $size, $storageClass, $isLatest);
  58. }
  59. }
  60. return $retList;
  61. }
  62. private function parseDeleteMarkerList($xml, $encodingType)
  63. {
  64. $retList = array();
  65. if (isset($xml->DeleteMarker)) {
  66. foreach ($xml->DeleteMarker as $content) {
  67. $key = isset($content->Key) ? strval($content->Key) : "";
  68. $key = OssUtil::decodeKey($key, $encodingType);
  69. $versionId = isset($content->VersionId) ? strval($content->VersionId) : "";
  70. $lastModified = isset($content->LastModified) ? strval($content->LastModified) : "";
  71. $isLatest = isset($content->IsLatest) ? strval($content->IsLatest) : "";
  72. $retList[] = new DeleteMarkerInfo($key, $versionId, $lastModified, $isLatest);
  73. }
  74. }
  75. return $retList;
  76. }
  77. private function parsePrefixList($xml, $encodingType)
  78. {
  79. $retList = array();
  80. if (isset($xml->CommonPrefixes)) {
  81. foreach ($xml->CommonPrefixes as $commonPrefix) {
  82. $prefix = isset($commonPrefix->Prefix) ? strval($commonPrefix->Prefix) : "";
  83. $prefix = OssUtil::decodeKey($prefix, $encodingType);
  84. $retList[] = new PrefixInfo($prefix);
  85. }
  86. }
  87. return $retList;
  88. }
  89. }