update
This commit is contained in:
32
addons/alioss/library/OSS/Result/AclResult.php
Normal file
32
addons/alioss/library/OSS/Result/AclResult.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* Class AclResult getBucketAcl接口返回结果类,封装了
|
||||
* 返回的xml数据的解析
|
||||
*
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class AclResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @throws OssException
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
if (empty($content)) {
|
||||
throw new OssException("body is null");
|
||||
}
|
||||
$xml = simplexml_load_string($content);
|
||||
if (isset($xml->AccessControlList->Grant)) {
|
||||
return strval($xml->AccessControlList->Grant);
|
||||
} else {
|
||||
throw new OssException("xml format exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
27
addons/alioss/library/OSS/Result/AppendResult.php
Normal file
27
addons/alioss/library/OSS/Result/AppendResult.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* Class AppendResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class AppendResult extends Result
|
||||
{
|
||||
/**
|
||||
* 结果中part的next-append-position
|
||||
*
|
||||
* @return int
|
||||
* @throws OssException
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$header = $this->rawResponse->header;
|
||||
if (isset($header["x-oss-next-append-position"])) {
|
||||
return intval($header["x-oss-next-append-position"]);
|
||||
}
|
||||
throw new OssException("cannot get next-append-position");
|
||||
}
|
||||
}
|
||||
19
addons/alioss/library/OSS/Result/BodyResult.php
Normal file
19
addons/alioss/library/OSS/Result/BodyResult.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
|
||||
/**
|
||||
* Class BodyResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class BodyResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
return empty($this->rawResponse->body) ? "" : $this->rawResponse->body;
|
||||
}
|
||||
}
|
||||
21
addons/alioss/library/OSS/Result/CallbackResult.php
Normal file
21
addons/alioss/library/OSS/Result/CallbackResult.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
|
||||
/**
|
||||
* Class CallbackResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class CallbackResult extends PutSetDeleteResult
|
||||
{
|
||||
protected function isResponseOk()
|
||||
{
|
||||
$status = $this->rawResponse->status;
|
||||
if ((int)(intval($status) / 100) == 2 && (int)(intval($status)) !== 203) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
30
addons/alioss/library/OSS/Result/CopyObjectResult.php
Normal file
30
addons/alioss/library/OSS/Result/CopyObjectResult.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
|
||||
/**
|
||||
* Class CopyObjectResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class CopyObjectResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return array()
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$body = $this->rawResponse->body;
|
||||
$xml = simplexml_load_string($body);
|
||||
$result = array();
|
||||
|
||||
if (isset($xml->LastModified)) {
|
||||
$result[] = $xml->LastModified;
|
||||
}
|
||||
if (isset($xml->ETag)) {
|
||||
$result[] = $xml->ETag;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
27
addons/alioss/library/OSS/Result/DeleteObjectsResult.php
Normal file
27
addons/alioss/library/OSS/Result/DeleteObjectsResult.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
|
||||
/**
|
||||
* Class DeleteObjectsResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class DeleteObjectsResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return array()
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$body = $this->rawResponse->body;
|
||||
$xml = simplexml_load_string($body);
|
||||
$objects = array();
|
||||
|
||||
if (isset($xml->Deleted)) {
|
||||
foreach($xml->Deleted as $deleteKey)
|
||||
$objects[] = $deleteKey->Key;
|
||||
}
|
||||
return $objects;
|
||||
}
|
||||
}
|
||||
35
addons/alioss/library/OSS/Result/ExistResult.php
Normal file
35
addons/alioss/library/OSS/Result/ExistResult.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
/**
|
||||
* Class ExistResult 检查bucket和object是否存在的返回结果,
|
||||
* 根据返回response的http status判断
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class ExistResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
return intval($this->rawResponse->status) === 200 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据返回http状态码判断,[200-299]即认为是OK, 判断是否存在的接口,404也认为是一种
|
||||
* 有效响应
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isResponseOk()
|
||||
{
|
||||
$status = $this->rawResponse->status;
|
||||
if ((int)(intval($status) / 100) == 2 || (int)(intval($status)) === 404) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
19
addons/alioss/library/OSS/Result/GetCnameResult.php
Normal file
19
addons/alioss/library/OSS/Result/GetCnameResult.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\CnameConfig;
|
||||
|
||||
class GetCnameResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return CnameConfig
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$config = new CnameConfig();
|
||||
$config->parseFromXml($content);
|
||||
return $config;
|
||||
}
|
||||
}
|
||||
35
addons/alioss/library/OSS/Result/GetCorsResult.php
Normal file
35
addons/alioss/library/OSS/Result/GetCorsResult.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\CorsConfig;
|
||||
|
||||
class GetCorsResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return CorsConfig
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$config = new CorsConfig();
|
||||
$config->parseFromXml($content);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据返回http状态码判断,[200-299]即认为是OK, 获取bucket相关配置的接口,404也认为是一种
|
||||
* 有效响应
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isResponseOk()
|
||||
{
|
||||
$status = $this->rawResponse->status;
|
||||
if ((int)(intval($status) / 100) == 2 || (int)(intval($status)) === 404) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
41
addons/alioss/library/OSS/Result/GetLifecycleResult.php
Normal file
41
addons/alioss/library/OSS/Result/GetLifecycleResult.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
|
||||
use OSS\Model\LifecycleConfig;
|
||||
|
||||
/**
|
||||
* Class GetLifecycleResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class GetLifecycleResult extends Result
|
||||
{
|
||||
/**
|
||||
* 解析Lifestyle数据
|
||||
*
|
||||
* @return LifecycleConfig
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$config = new LifecycleConfig();
|
||||
$config->parseFromXml($content);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据返回http状态码判断,[200-299]即认为是OK, 获取bucket相关配置的接口,404也认为是一种
|
||||
* 有效响应
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isResponseOk()
|
||||
{
|
||||
$status = $this->rawResponse->status;
|
||||
if ((int)(intval($status) / 100) == 2 || (int)(intval($status)) === 404) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\GetLiveChannelHistory;
|
||||
|
||||
class GetLiveChannelHistoryResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$channelList = new GetLiveChannelHistory();
|
||||
$channelList->parseFromXml($content);
|
||||
return $channelList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\GetLiveChannelInfo;
|
||||
|
||||
class GetLiveChannelInfoResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$channelList = new GetLiveChannelInfo();
|
||||
$channelList->parseFromXml($content);
|
||||
return $channelList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\GetLiveChannelStatus;
|
||||
|
||||
class GetLiveChannelStatusResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$channelList = new GetLiveChannelStatus();
|
||||
$channelList->parseFromXml($content);
|
||||
return $channelList;
|
||||
}
|
||||
}
|
||||
30
addons/alioss/library/OSS/Result/GetLocationResult.php
Normal file
30
addons/alioss/library/OSS/Result/GetLocationResult.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* Class GetLocationResult getBucketLocation接口返回结果类,封装了
|
||||
* 返回的xml数据的解析
|
||||
*
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class GetLocationResult extends Result
|
||||
{
|
||||
|
||||
/**
|
||||
* Parse data from response
|
||||
*
|
||||
* @return string
|
||||
* @throws OssException
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
if (empty($content)) {
|
||||
throw new OssException("body is null");
|
||||
}
|
||||
$xml = simplexml_load_string($content);
|
||||
return $xml;
|
||||
}
|
||||
}
|
||||
41
addons/alioss/library/OSS/Result/GetLoggingResult.php
Normal file
41
addons/alioss/library/OSS/Result/GetLoggingResult.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\LoggingConfig;
|
||||
|
||||
|
||||
/**
|
||||
* Class GetLoggingResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class GetLoggingResult extends Result
|
||||
{
|
||||
/**
|
||||
* 解析LoggingConfig数据
|
||||
*
|
||||
* @return LoggingConfig
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$config = new LoggingConfig();
|
||||
$config->parseFromXml($content);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据返回http状态码判断,[200-299]即认为是OK, 获取bucket相关配置的接口,404也认为是一种
|
||||
* 有效响应
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isResponseOk()
|
||||
{
|
||||
$status = $this->rawResponse->status;
|
||||
if ((int)(intval($status) / 100) == 2 || (int)(intval($status)) === 404) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
41
addons/alioss/library/OSS/Result/GetRefererResult.php
Normal file
41
addons/alioss/library/OSS/Result/GetRefererResult.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
|
||||
use OSS\Model\RefererConfig;
|
||||
|
||||
/**
|
||||
* Class GetRefererResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class GetRefererResult extends Result
|
||||
{
|
||||
/**
|
||||
* 解析RefererConfig数据
|
||||
*
|
||||
* @return RefererConfig
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$config = new RefererConfig();
|
||||
$config->parseFromXml($content);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据返回http状态码判断,[200-299]即认为是OK, 获取bucket相关配置的接口,404也认为是一种
|
||||
* 有效响应
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isResponseOk()
|
||||
{
|
||||
$status = $this->rawResponse->status;
|
||||
if ((int)(intval($status) / 100) == 2 || (int)(intval($status)) === 404) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* Class AclResult getBucketAcl接口返回结果类,封装了
|
||||
* 返回的xml数据的解析
|
||||
*
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class GetStorageCapacityResult extends Result
|
||||
{
|
||||
/**
|
||||
* Parse data from response
|
||||
*
|
||||
* @return string
|
||||
* @throws OssException
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
if (empty($content)) {
|
||||
throw new OssException("body is null");
|
||||
}
|
||||
$xml = simplexml_load_string($content);
|
||||
if (isset($xml->StorageCapacity)) {
|
||||
return intval($xml->StorageCapacity);
|
||||
} else {
|
||||
throw new OssException("xml format exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
40
addons/alioss/library/OSS/Result/GetWebsiteResult.php
Normal file
40
addons/alioss/library/OSS/Result/GetWebsiteResult.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\WebsiteConfig;
|
||||
|
||||
/**
|
||||
* Class GetWebsiteResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class GetWebsiteResult extends Result
|
||||
{
|
||||
/**
|
||||
* 解析WebsiteConfig数据
|
||||
*
|
||||
* @return WebsiteConfig
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$config = new WebsiteConfig();
|
||||
$config->parseFromXml($content);
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据返回http状态码判断,[200-299]即认为是OK, 获取bucket相关配置的接口,404也认为是一种
|
||||
* 有效响应
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isResponseOk()
|
||||
{
|
||||
$status = $this->rawResponse->status;
|
||||
if ((int)(intval($status) / 100) == 2 || (int)(intval($status)) === 404) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
23
addons/alioss/library/OSS/Result/HeaderResult.php
Normal file
23
addons/alioss/library/OSS/Result/HeaderResult.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
|
||||
/**
|
||||
* Class HeaderResult
|
||||
* @package OSS\Result
|
||||
* @link https://docs.aliyun.com/?spm=5176.383663.13.7.HgUIqL#/pub/oss/api-reference/object&GetObjectMeta
|
||||
*/
|
||||
class HeaderResult extends Result
|
||||
{
|
||||
/**
|
||||
* 把返回的ResponseCore中的header作为返回数据
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
return empty($this->rawResponse->header) ? array() : $this->rawResponse->header;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
|
||||
/**
|
||||
* Class initiateMultipartUploadResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class InitiateMultipartUploadResult extends Result
|
||||
{
|
||||
/**
|
||||
* 结果中获取uploadId并返回
|
||||
*
|
||||
* @throws OssException
|
||||
* @return string
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$xml = simplexml_load_string($content);
|
||||
if (isset($xml->UploadId)) {
|
||||
return strval($xml->UploadId);
|
||||
}
|
||||
throw new OssException("cannot get UploadId");
|
||||
}
|
||||
}
|
||||
33
addons/alioss/library/OSS/Result/ListBucketsResult.php
Normal file
33
addons/alioss/library/OSS/Result/ListBucketsResult.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\BucketInfo;
|
||||
use OSS\Model\BucketListInfo;
|
||||
|
||||
/**
|
||||
* Class ListBucketsResult
|
||||
*
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class ListBucketsResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return BucketListInfo
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$bucketList = array();
|
||||
$content = $this->rawResponse->body;
|
||||
$xml = new \SimpleXMLElement($content);
|
||||
if (isset($xml->Buckets) && isset($xml->Buckets->Bucket)) {
|
||||
foreach ($xml->Buckets->Bucket as $bucket) {
|
||||
$bucketInfo = new BucketInfo(strval($bucket->Location),
|
||||
strval($bucket->Name),
|
||||
strval($bucket->CreationDate));
|
||||
$bucketList[] = $bucketInfo;
|
||||
}
|
||||
}
|
||||
return new BucketListInfo($bucketList);
|
||||
}
|
||||
}
|
||||
16
addons/alioss/library/OSS/Result/ListLiveChannelResult.php
Normal file
16
addons/alioss/library/OSS/Result/ListLiveChannelResult.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\LiveChannelListInfo;
|
||||
|
||||
class ListLiveChannelResult extends Result
|
||||
{
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$channelList = new LiveChannelListInfo();
|
||||
$channelList->parseFromXml($content);
|
||||
return $channelList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssUtil;
|
||||
use OSS\Model\ListMultipartUploadInfo;
|
||||
use OSS\Model\UploadInfo;
|
||||
|
||||
|
||||
/**
|
||||
* Class ListMultipartUploadResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class ListMultipartUploadResult extends Result
|
||||
{
|
||||
/**
|
||||
* 解析从ListMultipartUpload接口的返回数据
|
||||
*
|
||||
* @return ListMultipartUploadInfo
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$xml = simplexml_load_string($content);
|
||||
|
||||
$encodingType = isset($xml->EncodingType) ? strval($xml->EncodingType) : "";
|
||||
$bucket = isset($xml->Bucket) ? strval($xml->Bucket) : "";
|
||||
$keyMarker = isset($xml->KeyMarker) ? strval($xml->KeyMarker) : "";
|
||||
$keyMarker = OssUtil::decodeKey($keyMarker, $encodingType);
|
||||
$uploadIdMarker = isset($xml->UploadIdMarker) ? strval($xml->UploadIdMarker) : "";
|
||||
$nextKeyMarker = isset($xml->NextKeyMarker) ? strval($xml->NextKeyMarker) : "";
|
||||
$nextKeyMarker = OssUtil::decodeKey($nextKeyMarker, $encodingType);
|
||||
$nextUploadIdMarker = isset($xml->NextUploadIdMarker) ? strval($xml->NextUploadIdMarker) : "";
|
||||
$delimiter = isset($xml->Delimiter) ? strval($xml->Delimiter) : "";
|
||||
$delimiter = OssUtil::decodeKey($delimiter, $encodingType);
|
||||
$prefix = isset($xml->Prefix) ? strval($xml->Prefix) : "";
|
||||
$prefix = OssUtil::decodeKey($prefix, $encodingType);
|
||||
$maxUploads = isset($xml->MaxUploads) ? intval($xml->MaxUploads) : 0;
|
||||
$isTruncated = isset($xml->IsTruncated) ? strval($xml->IsTruncated) : "";
|
||||
$listUpload = array();
|
||||
|
||||
if (isset($xml->Upload)) {
|
||||
foreach ($xml->Upload as $upload) {
|
||||
$key = isset($upload->Key) ? strval($upload->Key) : "";
|
||||
$key = OssUtil::decodeKey($key, $encodingType);
|
||||
$uploadId = isset($upload->UploadId) ? strval($upload->UploadId) : "";
|
||||
$initiated = isset($upload->Initiated) ? strval($upload->Initiated) : "";
|
||||
$listUpload[] = new UploadInfo($key, $uploadId, $initiated);
|
||||
}
|
||||
}
|
||||
return new ListMultipartUploadInfo($bucket, $keyMarker, $uploadIdMarker,
|
||||
$nextKeyMarker, $nextUploadIdMarker,
|
||||
$delimiter, $prefix, $maxUploads, $isTruncated, $listUpload);
|
||||
}
|
||||
}
|
||||
71
addons/alioss/library/OSS/Result/ListObjectsResult.php
Normal file
71
addons/alioss/library/OSS/Result/ListObjectsResult.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssUtil;
|
||||
use OSS\Model\ObjectInfo;
|
||||
use OSS\Model\ObjectListInfo;
|
||||
use OSS\Model\PrefixInfo;
|
||||
|
||||
/**
|
||||
* Class ListObjectsResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class ListObjectsResult extends Result
|
||||
{
|
||||
/**
|
||||
* 解析ListObjects接口返回的xml数据
|
||||
*
|
||||
* return ObjectListInfo
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$xml = new \SimpleXMLElement($this->rawResponse->body);
|
||||
$encodingType = isset($xml->EncodingType) ? strval($xml->EncodingType) : "";
|
||||
$objectList = $this->parseObjectList($xml, $encodingType);
|
||||
$prefixList = $this->parsePrefixList($xml, $encodingType);
|
||||
$bucketName = isset($xml->Name) ? strval($xml->Name) : "";
|
||||
$prefix = isset($xml->Prefix) ? strval($xml->Prefix) : "";
|
||||
$prefix = OssUtil::decodeKey($prefix, $encodingType);
|
||||
$marker = isset($xml->Marker) ? strval($xml->Marker) : "";
|
||||
$marker = OssUtil::decodeKey($marker, $encodingType);
|
||||
$maxKeys = isset($xml->MaxKeys) ? intval($xml->MaxKeys) : 0;
|
||||
$delimiter = isset($xml->Delimiter) ? strval($xml->Delimiter) : "";
|
||||
$delimiter = OssUtil::decodeKey($delimiter, $encodingType);
|
||||
$isTruncated = isset($xml->IsTruncated) ? strval($xml->IsTruncated) : "";
|
||||
$nextMarker = isset($xml->NextMarker) ? strval($xml->NextMarker) : "";
|
||||
$nextMarker = OssUtil::decodeKey($nextMarker, $encodingType);
|
||||
return new ObjectListInfo($bucketName, $prefix, $marker, $nextMarker, $maxKeys, $delimiter, $isTruncated, $objectList, $prefixList);
|
||||
}
|
||||
|
||||
private function parseObjectList($xml, $encodingType)
|
||||
{
|
||||
$retList = array();
|
||||
if (isset($xml->Contents)) {
|
||||
foreach ($xml->Contents as $content) {
|
||||
$key = isset($content->Key) ? strval($content->Key) : "";
|
||||
$key = OssUtil::decodeKey($key, $encodingType);
|
||||
$lastModified = isset($content->LastModified) ? strval($content->LastModified) : "";
|
||||
$eTag = isset($content->ETag) ? strval($content->ETag) : "";
|
||||
$type = isset($content->Type) ? strval($content->Type) : "";
|
||||
$size = isset($content->Size) ? intval($content->Size) : 0;
|
||||
$storageClass = isset($content->StorageClass) ? strval($content->StorageClass) : "";
|
||||
$retList[] = new ObjectInfo($key, $lastModified, $eTag, $type, $size, $storageClass);
|
||||
}
|
||||
}
|
||||
return $retList;
|
||||
}
|
||||
|
||||
private function parsePrefixList($xml, $encodingType)
|
||||
{
|
||||
$retList = array();
|
||||
if (isset($xml->CommonPrefixes)) {
|
||||
foreach ($xml->CommonPrefixes as $commonPrefix) {
|
||||
$prefix = isset($commonPrefix->Prefix) ? strval($commonPrefix->Prefix) : "";
|
||||
$prefix = OssUtil::decodeKey($prefix, $encodingType);
|
||||
$retList[] = new PrefixInfo($prefix);
|
||||
}
|
||||
}
|
||||
return $retList;
|
||||
}
|
||||
}
|
||||
42
addons/alioss/library/OSS/Result/ListPartsResult.php
Normal file
42
addons/alioss/library/OSS/Result/ListPartsResult.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\ListPartsInfo;
|
||||
use OSS\Model\PartInfo;
|
||||
|
||||
|
||||
/**
|
||||
* Class ListPartsResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class ListPartsResult extends Result
|
||||
{
|
||||
/**
|
||||
* 解析ListParts接口返回的xml数据
|
||||
*
|
||||
* @return ListPartsInfo
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$xml = simplexml_load_string($content);
|
||||
$bucket = isset($xml->Bucket) ? strval($xml->Bucket) : "";
|
||||
$key = isset($xml->Key) ? strval($xml->Key) : "";
|
||||
$uploadId = isset($xml->UploadId) ? strval($xml->UploadId) : "";
|
||||
$nextPartNumberMarker = isset($xml->NextPartNumberMarker) ? intval($xml->NextPartNumberMarker) : "";
|
||||
$maxParts = isset($xml->MaxParts) ? intval($xml->MaxParts) : "";
|
||||
$isTruncated = isset($xml->IsTruncated) ? strval($xml->IsTruncated) : "";
|
||||
$partList = array();
|
||||
if (isset($xml->Part)) {
|
||||
foreach ($xml->Part as $part) {
|
||||
$partNumber = isset($part->PartNumber) ? intval($part->PartNumber) : "";
|
||||
$lastModified = isset($part->LastModified) ? strval($part->LastModified) : "";
|
||||
$eTag = isset($part->ETag) ? strval($part->ETag) : "";
|
||||
$size = isset($part->Size) ? intval($part->Size) : "";
|
||||
$partList[] = new PartInfo($partNumber, $lastModified, $eTag, $size);
|
||||
}
|
||||
}
|
||||
return new ListPartsInfo($bucket, $key, $uploadId, $nextPartNumberMarker, $maxParts, $isTruncated, $partList);
|
||||
}
|
||||
}
|
||||
16
addons/alioss/library/OSS/Result/PutLiveChannelResult.php
Normal file
16
addons/alioss/library/OSS/Result/PutLiveChannelResult.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Model\LiveChannelInfo;
|
||||
|
||||
class PutLiveChannelResult extends Result
|
||||
{
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$content = $this->rawResponse->body;
|
||||
$channel = new LiveChannelInfo();
|
||||
$channel->parseFromXml($content);
|
||||
return $channel;
|
||||
}
|
||||
}
|
||||
20
addons/alioss/library/OSS/Result/PutSetDeleteResult.php
Normal file
20
addons/alioss/library/OSS/Result/PutSetDeleteResult.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
|
||||
/**
|
||||
* Class PutSetDeleteResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class PutSetDeleteResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return array()
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$body = array('body' => $this->rawResponse->body);
|
||||
return array_merge($this->rawResponse->header, $body);
|
||||
}
|
||||
}
|
||||
175
addons/alioss/library/OSS/Result/Result.php
Normal file
175
addons/alioss/library/OSS/Result/Result.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\Http\ResponseCore;
|
||||
|
||||
|
||||
/**
|
||||
* Class Result, 操作结果类的基类,不同的请求在处理返回数据的时候有不同的逻辑,
|
||||
* 具体的解析逻辑推迟到子类实现
|
||||
*
|
||||
* @package OSS\Model
|
||||
*/
|
||||
abstract class Result
|
||||
{
|
||||
/**
|
||||
* Result constructor.
|
||||
* @param $response ResponseCore
|
||||
* @throws OssException
|
||||
*/
|
||||
public function __construct($response)
|
||||
{
|
||||
if ($response === null) {
|
||||
throw new OssException("raw response is null");
|
||||
}
|
||||
$this->rawResponse = $response;
|
||||
$this->parseResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取requestId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestId()
|
||||
{
|
||||
if (isset($this->rawResponse) &&
|
||||
isset($this->rawResponse->header) &&
|
||||
isset($this->rawResponse->header['x-oss-request-id'])
|
||||
) {
|
||||
return $this->rawResponse->header['x-oss-request-id'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到返回数据,不同的请求返回数据格式不同
|
||||
*
|
||||
* $return mixed
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->parsedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 由子类实现,不同的请求返回数据有不同的解析逻辑,由子类实现
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function parseDataFromResponse();
|
||||
|
||||
/**
|
||||
* 操作是否成功
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function isOK()
|
||||
{
|
||||
return $this->isOk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws OssException
|
||||
*/
|
||||
public function parseResponse()
|
||||
{
|
||||
$this->isOk = $this->isResponseOk();
|
||||
if ($this->isOk) {
|
||||
$this->parsedData = $this->parseDataFromResponse();
|
||||
} else {
|
||||
$httpStatus = strval($this->rawResponse->status);
|
||||
$requestId = strval($this->getRequestId());
|
||||
$code = $this->retrieveErrorCode($this->rawResponse->body);
|
||||
$message = $this->retrieveErrorMessage($this->rawResponse->body);
|
||||
$body = $this->rawResponse->body;
|
||||
|
||||
$details = array(
|
||||
'status' => $httpStatus,
|
||||
'request-id' => $requestId,
|
||||
'code' => $code,
|
||||
'message' => $message,
|
||||
'body' => $body
|
||||
);
|
||||
throw new OssException($details);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试从body中获取错误Message
|
||||
*
|
||||
* @param $body
|
||||
* @return string
|
||||
*/
|
||||
private function retrieveErrorMessage($body)
|
||||
{
|
||||
if (empty($body) || false === strpos($body, '<?xml')) {
|
||||
return '';
|
||||
}
|
||||
$xml = simplexml_load_string($body);
|
||||
if (isset($xml->Message)) {
|
||||
return strval($xml->Message);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试从body中获取错误Code
|
||||
*
|
||||
* @param $body
|
||||
* @return string
|
||||
*/
|
||||
private function retrieveErrorCode($body)
|
||||
{
|
||||
if (empty($body) || false === strpos($body, '<?xml')) {
|
||||
return '';
|
||||
}
|
||||
$xml = simplexml_load_string($body);
|
||||
if (isset($xml->Code)) {
|
||||
return strval($xml->Code);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据返回http状态码判断,[200-299]即认为是OK
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isResponseOk()
|
||||
{
|
||||
$status = $this->rawResponse->status;
|
||||
if ((int)(intval($status) / 100) == 2) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回原始的返回数据
|
||||
*
|
||||
* @return ResponseCore
|
||||
*/
|
||||
public function getRawResponse()
|
||||
{
|
||||
return $this->rawResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标示请求是否成功
|
||||
*/
|
||||
protected $isOk = false;
|
||||
/**
|
||||
* 由子类解析过的数据
|
||||
*/
|
||||
protected $parsedData = null;
|
||||
/**
|
||||
* 存放auth函数返回的原始Response
|
||||
*
|
||||
* @var ResponseCore
|
||||
*/
|
||||
protected $rawResponse;
|
||||
}
|
||||
24
addons/alioss/library/OSS/Result/SymlinkResult.php
Normal file
24
addons/alioss/library/OSS/Result/SymlinkResult.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
use OSS\OssClient;
|
||||
|
||||
/**
|
||||
*
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class SymlinkResult extends Result
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @throws OssException
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$this->rawResponse->header[OssClient::OSS_SYMLINK_TARGET] = rawurldecode($this->rawResponse->header[OssClient::OSS_SYMLINK_TARGET]);
|
||||
return $this->rawResponse->header;
|
||||
}
|
||||
}
|
||||
|
||||
28
addons/alioss/library/OSS/Result/UploadPartResult.php
Normal file
28
addons/alioss/library/OSS/Result/UploadPartResult.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace OSS\Result;
|
||||
|
||||
use OSS\Core\OssException;
|
||||
|
||||
/**
|
||||
* Class UploadPartResult
|
||||
* @package OSS\Result
|
||||
*/
|
||||
class UploadPartResult extends Result
|
||||
{
|
||||
/**
|
||||
* 结果中part的ETag
|
||||
*
|
||||
* @return string
|
||||
* @throws OssException
|
||||
*/
|
||||
protected function parseDataFromResponse()
|
||||
{
|
||||
$header = $this->rawResponse->header;
|
||||
if (isset($header["etag"])) {
|
||||
return $header["etag"];
|
||||
}
|
||||
throw new OssException("cannot get ETag");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user