更新oss-php sdk 从2.3.1 到 2.4.3 ,目的是为了兼容php8。

This commit is contained in:
minghao.hu 2022-01-03 21:21:13 +08:00
parent dcbeef008c
commit cf8c55d750
193 changed files with 6466 additions and 378 deletions

View File

@ -1,6 +1,6 @@
<?php
require_once 'aliyun-oss-php-sdk-2.3.1/autoload.php';
require_once 'aliyun-oss-php-sdk-2.4.3/autoload.php';
use OSS\OssClient;
use OSS\Core\OssException;

View File

@ -1,78 +0,0 @@
<?php
namespace OSS\Model;
/**
* Bucket information class. This is the type of element in BucketListInfo's
*
* Class BucketInfo
* @package OSS\Model
*/
class BucketInfo
{
/**
* BucketInfo constructor.
*
* @param string $location
* @param string $name
* @param string $createDate
*/
public function __construct($location, $name, $createDate)
{
$this->location = $location;
$this->name = $name;
$this->createDate = $createDate;
}
/**
* Get bucket location
*
* @return string
*/
public function getLocation()
{
return $this->location;
}
/**
* Get bucket name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get bucket creation time.
*
* @return string
*/
public function getCreateDate()
{
return $this->createDate;
}
/**
* bucket region
*
* @var string
*/
private $location;
/**
* bucket name
*
* @var string
*/
private $name;
/**
* bucket creation time
*
* @var string
*/
private $createDate;
}

View File

@ -1,97 +0,0 @@
<?php
namespace OSS\Tests;
use OSS\Core\OssException;
use OSS\Http\ResponseCore;
use OSS\Result\ListBucketsResult;
class ListBucketsResultTest extends \PHPUnit_Framework_TestCase
{
private $validXml = <<<BBBB
<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult>
<Owner>
<ID>ut_test_put_bucket</ID>
<DisplayName>ut_test_put_bucket</DisplayName>
</Owner>
<Buckets>
<Bucket>
<Location>oss-cn-hangzhou-a</Location>
<Name>xz02tphky6fjfiuc0</Name>
<CreationDate>2014-05-15T11:18:32.000Z</CreationDate>
</Bucket>
<Bucket>
<Location>oss-cn-hangzhou-a</Location>
<Name>xz02tphky6fjfiuc1</Name>
<CreationDate>2014-05-15T11:18:32.000Z</CreationDate>
</Bucket>
</Buckets>
</ListAllMyBucketsResult>
BBBB;
private $nullXml = <<<BBBB
<?xml version="1.0" encoding="UTF-8"?>
<ListAllMyBucketsResult>
<Owner>
<ID>ut_test_put_bucket</ID>
<DisplayName>ut_test_put_bucket</DisplayName>
</Owner>
<Buckets>
</Buckets>
</ListAllMyBucketsResult>
BBBB;
public function testParseValidXml()
{
$response = new ResponseCore(array(), $this->validXml, 200);
$result = new ListBucketsResult($response);
$this->assertTrue($result->isOK());
$this->assertNotNull($result->getData());
$this->assertNotNull($result->getRawResponse());
$bucketListInfo = $result->getData();
$this->assertEquals(2, count($bucketListInfo->getBucketList()));
}
public function testParseNullXml()
{
$response = new ResponseCore(array(), $this->nullXml, 200);
$result = new ListBucketsResult($response);
$this->assertTrue($result->isOK());
$this->assertNotNull($result->getData());
$this->assertNotNull($result->getRawResponse());
$bucketListInfo = $result->getData();
$this->assertEquals(0, count($bucketListInfo->getBucketList()));
}
public function test403()
{
$errorHeader = array(
'x-oss-request-id' => '1a2b-3c4d'
);
$errorBody = <<< BBBB
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist.</Message>
<RequestId>566B870D207FB3044302EB0A</RequestId>
<HostId>hello.oss-test.aliyun-inc.com</HostId>
<BucketName>hello</BucketName>
</Error>
BBBB;
$response = new ResponseCore($errorHeader, $errorBody, 403);
try {
new ListBucketsResult($response);
} catch (OssException $e) {
$this->assertEquals(
$e->getMessage(),
'NoSuchBucket: The specified bucket does not exist. RequestId: 1a2b-3c4d');
$this->assertEquals($e->getHTTPStatus(), '403');
$this->assertEquals($e->getRequestId(), '1a2b-3c4d');
$this->assertEquals($e->getErrorCode(), 'NoSuchBucket');
$this->assertEquals($e->getErrorMessage(), 'The specified bucket does not exist.');
$this->assertEquals($e->getDetails(), $errorBody);
}
}
}

View File

View File

@ -1,6 +1,41 @@
# ChangeLog - Aliyun OSS SDK for PHP
## v2.3.1 / 2019-011-15
## v2.4.3 / 2021-08-25
* Fixed: integer overflow in PHP5.x.
## v2.4.2 / 2021-06-04
* Compatible with PHP8.
* Fixed: compatible with PHP5.4.
* Fixed: the signature is incorrect in some scenarios
* Update: change $requestUrl from a member variable to a local variable.
## v2.4.1 / 2020-09-29
* Fixed: the getBucketPolicy bug.
## v2.4.0 / 2020-08-31
* Added: disable Expect: 100-continue
* Added: support getBucketInfo
* Added: support getBucketStat
* Added: support bucket policy
* Added: support bucket encryption
* Added: support bucket tagging
* Added: support bucket worm
* Added: support versioning
* Added: support request payment
* Added: support object tagging
* Added: support code archive
* Added: support process object
* Added: support traffic limit paramter
* Added: support upload object from file handle
* Added: support getSimplifiedObjectMeta
* Fixed: the object name can not be '0' stirng.
* Update: endpoint validity check
* Update: add new pre-signed url api
## v2.3.1 / 2019-01-15
* translate chinese comments into english
* Added: endpoint validity check

View File

@ -111,7 +111,7 @@ OssClient提供的接口返回返回数据分为两种
$bucketListInfo = $ossClient->listBuckets();
$bucketList = $bucketListInfo->getBucketList();
foreach($bucketList as $bucket) {
print($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreatedate() . "\n");
print($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreateDate() . "\n");
}
```
上面代码中的$bucketListInfo的数据类型是 `OSS\Model\BucketListInfo`

View File

@ -1,4 +1,4 @@
# Alibaba Cloud OSS SDK for PHP
# Alibaba Cloud OSS SDK for PHP
[![Latest Stable Version](https://poser.pugx.org/aliyuncs/oss-sdk-php/v/stable)](https://packagist.org/packages/aliyuncs/oss-sdk-php)
[![Build Status](https://travis-ci.org/aliyun/aliyun-oss-php-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-oss-php-sdk)
@ -50,12 +50,12 @@ Tips:
| Class | Explanation |
|:------------------|:------------------------------------|
|OSS\OSSClient | OSS client class. An OSSClient instance can be used to call the interface. |
|OSS\Core\OSSException |OSS Exception class . You only need to pay attention to this exception when you use the OSSClient. |
|OSS\OssClient | OSS client class. An OssClient instance can be used to call the interface. |
|OSS\Core\OssException |OSS Exception class . You only need to pay attention to this exception when you use the OssClient. |
### Initialize an OSSClient
### Initialize an OssClient
The SDK's operations for the OSS are performed through the OSSClient class. The code below creates an OSSClient object:
The SDK's operations for the OSS are performed through the OssClient class. The code below creates an OssClient object:
```php
<?php
@ -101,7 +101,7 @@ try {
### Handle returned results
The OSSClient provides the following two types of returned data from interfaces:
The OssClient provides the following two types of returned data from interfaces:
- Put and Delete interfaces: The *PUT* and *DELETE* operations are deemed successful if *null* is returned by the interfaces without *OSSException*.
- Get and List interfaces: The *GET* and *LIST* operations are deemed successful if the desired data is returned by the interfaces without *OSSException*. For example,
@ -111,7 +111,7 @@ The OSSClient provides the following two types of returned data from interfaces:
$bucketListInfo = $ossClient->listBuckets();
$bucketList = $bucketListInfo->getBucketList();
foreach($bucketList as $bucket) {
print($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreatedate() . "\n");
print($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreateDate() . "\n");
}
```
In the above code, $bucketListInfo falls into the 'OSS\Model\BucketListInfo' data type.

View File

@ -14,8 +14,8 @@
"php":">=5.3"
},
"require-dev" : {
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~1.0"
"phpunit/phpunit": "*",
"satooshi/php-coveralls": "*"
},
"minimum-stability": "stable",
"autoload": {

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -83,5 +83,5 @@ function printImage($func, $imageFile)
Common::println("$func, image width: " . $array[0]);
Common::println("$func, image height: " . $array[1]);
Common::println("$func, image type: " . ($array[2] === 2 ? 'jpg' : 'png'));
Common::println("$func, image size: " . ceil(filesize($imageFile)));
Common::println("$func, image size: " . ceil(sprintf('%u',filesize($imageFile))));
}

View File

@ -85,7 +85,7 @@ function putObjectByRawApis($ossClient, $bucket)
*/
$partSize = 10 * 1024 * 1024;
$uploadFile = __FILE__;
$uploadFileSize = filesize($uploadFile);
$uploadFileSize = sprintf('%u',filesize($uploadFile));
$pieces = $ossClient->generateMultiuploadParts($uploadFileSize, $partSize);
$responseUploadPart = array();
$uploadPosition = 0;

View File

@ -130,7 +130,7 @@ function getSignedUrlForPuttingObjectFromFile($ossClient, $bucket)
$request->set_method('PUT');
$request->add_header('Content-Type', 'txt');
$request->set_read_file($file);
$request->set_read_stream_size(filesize($file));
$request->set_read_stream_size(sprintf('%u',filesize($file)));
$request->send_request();
$res = new ResponseCore($request->get_response_header(),
$request->get_response_body(), $request->get_response_code());

View File

@ -145,7 +145,7 @@ class OssUtil
public static function validateObject($object)
{
$pattern = '/^.{1,1023}$/';
if (empty($object) || !preg_match($pattern, $object) ||
if (!preg_match($pattern, $object) ||
self::startsWith($object, '/') || self::startsWith($object, '\\')
) {
return false;
@ -223,6 +223,8 @@ class OssUtil
public static function throwOssExceptionWithMessageIfEmpty($name, $errMsg)
{
if (empty($name)) {
if (is_string($name) && $name == '0')
return;
throw new OssException($errMsg);
}
}
@ -235,7 +237,7 @@ class OssUtil
*/
public static function generateFile($filename, $size)
{
if (file_exists($filename) && $size == filesize($filename)) {
if (file_exists($filename) && $size == sprintf('%u',filesize($filename))) {
echo $filename . " already exists, no need to create again. ";
return;
}
@ -282,7 +284,7 @@ BBB;
if (($to_pos - $from_pos) > self::OSS_MAX_PART_SIZE) {
return $content_md5;
}
$filesize = filesize($filename);
$filesize = sprintf('%u',filesize($filename));
if ($from_pos >= $filesize || $to_pos >= $filesize || $from_pos < 0 || $to_pos < 0) {
return $content_md5;
}
@ -395,7 +397,11 @@ BBB;
if ($pos !== false) {
$str = substr($str, $pos+1);
}
if (!preg_match('/^[\w.-]+(:[0-9]+)?$/', $str)) {
throw new OssException("endpoint is invalid:" . $endpoint);
}
return $str;
}
@ -418,6 +424,29 @@ BBB;
return $xml->asXML();
}
/**
* Generate the xml message of DeleteMultiObjects.
*
* @param DeleteObjectInfo[] $objects
* @param bool $quiet
* @return string
*/
public static function createDeleteObjectVersionsXmlBody($objects, $quiet)
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><Delete></Delete>');
$xml->addChild('Quiet', $quiet);
foreach ($objects as $object) {
$sub_object = $xml->addChild('Object');
$key = OssUtil::sReplace($object->getKey());
$sub_object->addChild('Key', $key);
$versionId = $object->getVersionId();
if (!empty($versionId)) {
$sub_object->addChild('VersionId', $object->getVersionId());
}
}
return $xml->asXML();
}
/**
* Generate the xml message of CompleteMultipartUpload.
*

View File

@ -713,6 +713,8 @@ class RequestCore
$temp_headers[] = $k . ': ' . $v;
}
// fix "Expect: 100-continue"
$temp_headers[] = 'Expect:';
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $temp_headers);
}
@ -775,7 +777,7 @@ class RequestCore
* data stored in the `curl_handle` and `response` properties unless replacement data is passed in via
* parameters.
*
* @param resource $curl_handle (Optional) The reference to the already executed cURL request.
* @param resource|\CurlHandle|null|false $curl_handle (Optional) The reference to the already executed cURL request. Receive CurlHandle instance from PHP8.0
* @param string $response (Optional) The actual response content itself that needs to be parsed.
* @return ResponseCore A <ResponseCore> object containing a parsed HTTP response.
*/
@ -786,8 +788,8 @@ class RequestCore
$this->response = $response;
}
// As long as this came back as a valid resource...
if (is_resource($curl_handle)) {
// As long as this came back as a valid resource or CurlHandle instance...
if (is_resource($curl_handle) || (is_object($curl_handle) && get_class($curl_handle) === 'CurlHandle')) {
// Determine what's what.
$header_size = curl_getinfo($curl_handle, CURLINFO_HEADER_SIZE);
$this->response_headers = substr($this->response, 0, $header_size);
@ -842,12 +844,13 @@ class RequestCore
$this->response = curl_exec($curl_handle);
if ($this->response === false) {
throw new RequestCore_Exception('cURL resource: ' . (string)$curl_handle . '; cURL error: ' . curl_error($curl_handle) . ' (' . curl_errno($curl_handle) . ')');
throw new RequestCore_Exception('cURL error: ' . curl_error($curl_handle) . ' (' . curl_errno($curl_handle) . ')');
}
$parsed_response = $this->process_response($curl_handle, $this->response);
curl_close($curl_handle);
unset($curl_handle);
if ($parse) {
return $parsed_response;

View File

@ -0,0 +1,181 @@
<?php
namespace OSS\Model;
/**
* Bucket information class. This is the type of element in BucketListInfo's
*
* Class BucketInfo
* @package OSS\Model
*/
class BucketInfo
{
/**
* BucketInfo constructor.
*
* @param string $location
* @param string $name
* @param string $createDate
*/
public function __construct($location = '', $name = '', $createDate = '')
{
$this->location = $location;
$this->createDate = $createDate;
$this->name = $name;
}
/**
* Get bucket location
*
* @return string
*/
public function getLocation()
{
return $this->location;
}
/**
* Get bucket name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get bucket creation time.
*
* @return string
*/
public function getCreateDate()
{
return $this->createDate;
}
/**
* Get bucket storage class.
*
* @return string
*/
public function getStorageClass()
{
return $this->storageClass;
}
/**
* Get bucket extranet endpoint.
*
* @return string
*/
public function getExtranetEndpoint()
{
return $this->extranetEndpoint;
}
/**
* Get bucket intranet endpoint.
*
* @return string
*/
public function getIntranetEndpoint()
{
return $this->intranetEndpoint;
}
/**
* Get bucket intranet endpoint.
*
* @return string
*/
public function getRegion()
{
return $this->region;
}
/**
* Parse bucket information from node.
*
* @param xml $xml
* @throws OssException
* @return null
*/
public function parseFromXmlNode($xml)
{
if (isset($xml->Location)) {
$this->location = strval($xml->Location);
}
if (isset($xml->Name)) {
$this->name = strval($xml->Name);
}
if (isset($xml->CreationDate)) {
$this->createDate = strval($xml->CreationDate);
}
if (isset($xml->StorageClass)) {
$this->storageClass = strval($xml->StorageClass);
}
if (isset($xml->ExtranetEndpoint)) {
$this->extranetEndpoint = strval($xml->ExtranetEndpoint);
}
if (isset($xml->IntranetEndpoint)) {
$this->intranetEndpoint = strval($xml->IntranetEndpoint);
}
if (isset($xml->IntranetEndpoint)) {
$this->intranetEndpoint = strval($xml->IntranetEndpoint);
}
if (isset($xml->Region)) {
$this->region = strval($xml->Region);
}
}
/**
* bucket region
*
* @var string
*/
private $location;
/**
* bucket name
*
* @var string
*/
private $name;
/**
* bucket creation time
*
* @var string
*/
private $createDate;
/**
* bucket storage class
*
* @var string
*/
private $storageClass;
/**
* bucket extranet endpoint
*
* @var string
*/
private $extranetEndpoint;
/**
* bucket intranet endpoint
*
* @var string
*/
private $intranetEndpoint;
/**
* bucket region
*
* @var string
*/
private $region;
}

View File

@ -0,0 +1,85 @@
<?php
namespace OSS\Model;
/**
* Bucket stat class.
*
* Class BucketStat
* @package OSS\Model
*/
class BucketStat
{
/**
* Get storage
*
* @return int
*/
public function getStorage()
{
return $this->storage;
}
/**
* Get object count
*
* @return int
*/
public function getObjectCount()
{
return $this->objectCount;
}
/**
* Get multipart upload count.
*
* @return int
*/
public function getMultipartUploadCount()
{
return $this->multipartUploadCount;
}
/**
* Parse stat from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);
if (isset($xml->Storage) ) {
$this->storage = intval($xml->Storage);
}
if (isset($xml->ObjectCount) ) {
$this->objectCount = intval($xml->ObjectCount);
}
if (isset($xml->MultipartUploadCount) ) {
$this->multipartUploadCount = intval($xml->MultipartUploadCount);
}
}
/**
* current storage
*
* @var int
*/
private $storage;
/**
* object count
*
* @var int
*/
private $objectCount;
/**
* multipart upload count
*
* @var int
*/
private $multipartUploadCount;
}

View File

@ -0,0 +1,65 @@
<?php
namespace OSS\Model;
/**
*
* Class DeleteMarkerInfo
*
* @package OSS\Model
*/
class DeleteMarkerInfo
{
/**
* DeleteMarkerInfo constructor.
*
* @param string $key
* @param string $versionId
* @param string $lastModified
* @param string $isLatest
*/
public function __construct($key, $versionId, $lastModified, $isLatest)
{
$this->key = $key;
$this->versionId = $versionId;
$this->lastModified = $lastModified;
$this->isLatest = $isLatest;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @return string
*/
public function getVersionId()
{
return $this->versionId;
}
/**
* @return string
*/
public function getLastModified()
{
return $this->lastModified;
}
/**
* @return string
*/
public function getIsLatest()
{
return $this->isLatest;
}
private $key = "";
private $versionId = "";
private $lastModified = "";
private $isLatest = "";
}

View File

@ -0,0 +1,41 @@
<?php
namespace OSS\Model;
/**
* Class DeleteObjectInfo
* @package OSS\Model
*/
class DeleteObjectInfo
{
/**
* DeleteObjectInfo constructor.
*
* @param string $key
* @param string $versionId
*/
public function __construct($key, $versionId = '')
{
$this->key = $key;
$this->versionId = $versionId;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @return string
*/
public function getVersionId()
{
return $this->versionId;
}
private $key = "";
private $versionId = "";
}

View File

@ -0,0 +1,63 @@
<?php
namespace OSS\Model;
/**
* Class DeletedObjectInfo
* @package OSS\Model
*/
class DeletedObjectInfo
{
/**
* DeletedObjectInfo constructor.
*
* @param string $key
* @param string $versionId
* @param string $deleteMarker
* @param string $deleteMarkerVersionId
*/
public function __construct($key, $versionId, $deleteMarker, $deleteMarkerVersionId)
{
$this->key = $key;
$this->versionId = $versionId;
$this->deleteMarker = $deleteMarker;
$this->deleteMarkerVersionId = $deleteMarkerVersionId;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @return string
*/
public function getVersionId()
{
return $this->versionId;
}
/**
* @return string
*/
public function getDeleteMarker()
{
return $this->deleteMarker;
}
/**
* @return string
*/
public function getDeleteMarkerVersionId()
{
return $this->deleteMarkerVersionId;
}
private $key = "";
private $versionId = "";
private $deleteMarker = "";
private $deleteMarkerVersionId = "";
}

View File

@ -0,0 +1,64 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class ExtendWormConfig
* @package OSS\Model
*
*/
class ExtendWormConfig implements XmlConfig
{
/**
* ExtendWormConfig constructor.
* @param null $day
*/
public function __construct($day = null)
{
$this->day = $day;
}
/**
* Parse ExtendWormConfig from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
throw new OssException("Not implemented.");
}
/**
* Serialize the object into xml string.
*
* @return string
*/
public function serializeToXml()
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><ExtendWormConfiguration></ExtendWormConfiguration>');
if (isset($this->day)) {
$xml->addChild('RetentionPeriodInDays', $this->day);
}
return $xml->asXML();
}
public function __toString()
{
return $this->serializeToXml();
}
/**
* @return int
*/
public function getDay()
{
return $this->day;
}
private $day = 0;
}

View File

@ -1,6 +1,9 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class GetLiveChannelHistory
* @package OSS\Model

View File

@ -0,0 +1,64 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class InitiateWormConfig
* @package OSS\Model
*
*/
class InitiateWormConfig implements XmlConfig
{
/**
* InitiateWormConfig constructor.
* @param null $day
*/
public function __construct($day = null)
{
$this->day = $day;
}
/**
* Parse InitiateWormConfig from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
throw new OssException("Not implemented.");
}
/**
* Serialize the object into xml string.
*
* @return string
*/
public function serializeToXml()
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><InitiateWormConfiguration></InitiateWormConfiguration>');
if (isset($this->day)) {
$xml->addChild('RetentionPeriodInDays', $this->day);
}
return $xml->asXML();
}
public function __toString()
{
return $this->serializeToXml();
}
/**
* @return int
*/
public function getDay()
{
return $this->day;
}
private $day = 0;
}

View File

@ -23,7 +23,7 @@ class ObjectInfo
* @param string $lastModified
* @param string $eTag
* @param string $type
* @param int $size
* @param string $size
* @param string $storageClass
*/
public function __construct($key, $lastModified, $eTag, $type, $size, $storageClass)
@ -67,15 +67,26 @@ class ObjectInfo
{
return $this->type;
}
/**
* @return int
*/
public function getSize()
{
return $this->size;
}
/**
* php7 && 64bit can use it
* @return int
*/
public function getSize()
{
return (int)$this->size;
}
/**
* php5.x or 32bit must use it
* @return string
*/
public function getSizeStr()
{
return $this->size;
}
/**
* @return string
*/
@ -88,6 +99,6 @@ class ObjectInfo
private $lastModified = "";
private $eTag = "";
private $type = "";
private $size = 0;
private $size = "0";
private $storageClass = "";
}

View File

@ -0,0 +1,125 @@
<?php
namespace OSS\Model;
/**
*
* Class ObjectVersionInfo
*
* The element type of ObjectVersionListInfo, which is the return value type of listObjectVersions
*
* The return value of listObjectVersions includes three arrays
* One is the returned ObjectVersionListInfo, which is similar to a file list in a file system.
* The other is the returned prefix list, which is similar to a folder list in a file system.
*
* @package OSS\Model
*/
class ObjectVersionInfo
{
/**
* ObjectVersionInfo constructor.
*
* @param string $key
* @param string $lastModified
* @param string $eTag
* @param string $type
* @param string $size
* @param string $storageClass
* @param string $isLatest
*/
public function __construct($key, $versionId, $lastModified, $eTag, $type, $size, $storageClass, $isLatest)
{
$this->key = $key;
$this->versionId = $versionId;
$this->lastModified = $lastModified;
$this->eTag = $eTag;
$this->type = $type;
$this->size = $size;
$this->storageClass = $storageClass;
$this->isLatest = $isLatest;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @return string
*/
public function getVersionId()
{
return $this->versionId;
}
/**
* @return string
*/
public function getLastModified()
{
return $this->lastModified;
}
/**
* @return string
*/
public function getETag()
{
return $this->eTag;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* php7 && 64bit can use it
* @return int
*/
public function getSize()
{
return (int)$this->size;
}
/**
* php5.x or 32bit must use it
* @return string
*/
public function getSizeStr()
{
return $this->size;
}
/**
* @return string
*/
public function getStorageClass()
{
return $this->storageClass;
}
/**
* @return string
*/
public function getIsLatest()
{
return $this->isLatest;
}
private $key = "";
private $versionId = "";
private $lastModified = "";
private $eTag = "";
private $type = "";
private $size = "0";
private $storageClass = "";
private $isLatest = "";
}

View File

@ -0,0 +1,162 @@
<?php
namespace OSS\Model;
/**
* Class ObjectVersionListInfo
*
* The class of return value of ListObjectVersions
*
* @package OSS\Model
*/
class ObjectVersionListInfo
{
/**
* ObjectVersionListInfo constructor.
*
* @param string $bucketName
* @param string $prefix
* @param string $keyMarker
* @param string $nextKeyMarker
* @param string $versionIdMarker
* @param string $nextVersionIdMarker
* @param string $maxKeys
* @param string $delimiter
* @param null $isTruncated
* @param array $objectversionList
* @param array $deleteMarkerList
* @param array $prefixList
*/
public function __construct($bucketName, $prefix, $keyMarker, $nextKeyMarker, $versionIdMarker, $nextVersionIdMarker
, $maxKeys, $delimiter, $isTruncated
, array $objectversionList, array $deleteMarkerList, array $prefixList)
{
$this->bucketName = $bucketName;
$this->prefix = $prefix;
$this->keyMarker = $keyMarker;
$this->nextKeyMarker = $nextKeyMarker;
$this->versionIdMarker = $versionIdMarker;
$this->nextVersionIdMarker = $nextVersionIdMarker;
$this->maxKeys = $maxKeys;
$this->delimiter = $delimiter;
$this->isTruncated = $isTruncated;
$this->objectVersionList = $objectversionList;
$this->deleteMarkerList = $deleteMarkerList;
$this->prefixList = $prefixList;
}
/**
* @return string
*/
public function getBucketName()
{
return $this->bucketName;
}
/**
* @return string
*/
public function getPrefix()
{
return $this->prefix;
}
/**
* @return string
*/
public function getKeyMarker()
{
return $this->keyMarker;
}
/**
* @return string
*/
public function getNextKeyMarker()
{
return $this->nextKeyMarker;
}
/**
* @return string
*/
public function getVersionIdMarker()
{
return $this->versionIdMarker;
}
/**
* @return string
*/
public function getNextVersionIdMarker()
{
return $this->nextVersionIdMarker;
}
/**
* @return int
*/
public function getMaxKeys()
{
return $this->maxKeys;
}
/**
* @return string
*/
public function getDelimiter()
{
return $this->delimiter;
}
/**
* @return mixed
*/
public function getIsTruncated()
{
return $this->isTruncated;
}
/**
* Get the ObjectVersionInfo list.
*
* @return ObjectVersionInfo[]
*/
public function getObjectVersionList()
{
return $this->objectVersionList;
}
/**
* Get the DeleteMarkerInfo list.
*
* @return DeleteMarkerInfo[]
*/
public function getDeleteMarkerList()
{
return $this->deleteMarkerList;
}
/**
* Get the PrefixInfo list
*
* @return PrefixInfo[]
*/
public function getPrefixList()
{
return $this->prefixList;
}
private $bucketName = "";
private $prefix = "";
private $keyMarker = "";
private $nextKeyMarker = "";
private $versionIdmarker = "";
private $nextVersionIdMarker = "";
private $maxKeys = 0;
private $delimiter = "";
private $isTruncated = null;
private $objectVersionList = array();
private $deleteMarkerList = array();
private $prefixList = array();
}

View File

@ -14,7 +14,7 @@ class PartInfo
* @param int $partNumber
* @param string $lastModified
* @param string $eTag
* @param int $size
* @param string $size
*/
public function __construct($partNumber, $lastModified, $eTag, $size)
{
@ -49,15 +49,26 @@ class PartInfo
}
/**
* php7 && 64bit can use it
* @return int
*/
public function getSize()
{
return $this->size;
return (int)$this->size;
}
/**
* php5.x or 32bit must use it
* @return string
*/
public function getSizeStr()
{
return $this->size;
}
private $partNumber = 0;
private $lastModified = "";
private $eTag = "";
private $size = 0;
private $size = "0";
}

View File

@ -0,0 +1,68 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class RequestPaymentConfig
* @package OSS\Model
*
* @link https://help.aliyun.com/document_detail/117914.htm
*/
class RequestPaymentConfig implements XmlConfig
{
/**
* RequestPaymentConfig constructor.
* @param null $payer
*/
public function __construct($payer = null)
{
$this->payer = $payer;
}
/**
* Parse ServerSideEncryptionConfig from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);
if (isset($xml->Payer)) {
$this->payer = strval($xml->Payer);
}
}
/**
* Serialize the object into xml string.
*
* @return string
*/
public function serializeToXml()
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><RequestPaymentConfiguration></RequestPaymentConfiguration>');
if (isset($this->payer)) {
$xml->addChild('Payer', $this->payer);
}
return $xml->asXML();
}
public function __toString()
{
return $this->serializeToXml();
}
/**
* @return string
*/
public function getPayer()
{
return $this->payer;
}
private $payer = "";
}

View File

@ -0,0 +1,77 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class RestoreConfig
* @package OSS\Model
*
*/
class RestoreConfig implements XmlConfig
{
/**
* RestoreConfig constructor.
* @param int $day
* @param null $tier
*/
public function __construct($day, $tier = null)
{
$this->day = $day;
$this->tier = $tier;
}
/**
* Parse RestoreConfig from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
throw new OssException("Not implemented.");
}
/**
* Serialize the object into xml string.
*
* @return string
*/
public function serializeToXml()
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><RestoreRequest></RestoreRequest>');
$xml->addChild('Days', strval($this->day));
if (isset($this->tier)) {
$xml_param = $xml->addChild('JobParameters');
$xml_param->addChild('Tier', $this->tier);
}
return $xml->asXML();
}
public function __toString()
{
return $this->serializeToXml();
}
/**
* @return int
*/
public function getDay()
{
return $this->day;
}
/**
* @return string
*/
public function getTier()
{
return $this->tier;
}
private $day = 1;
private $tier = 'Standard';
}

View File

@ -0,0 +1,91 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class ServerSideEncryptionConfig
* @package OSS\Model
*
* @link https://help.aliyun.com/document_detail/117914.htm
*/
class ServerSideEncryptionConfig implements XmlConfig
{
/**
* ServerSideEncryptionConfig constructor.
* @param null $sseAlgorithm
* @param null $kmsMasterKeyID
*/
public function __construct($sseAlgorithm = null, $kmsMasterKeyID = null)
{
$this->sseAlgorithm = $sseAlgorithm;
$this->kmsMasterKeyID = $kmsMasterKeyID;
}
/**
* Parse ServerSideEncryptionConfig from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);
if (!isset($xml->ApplyServerSideEncryptionByDefault)) return;
foreach ($xml->ApplyServerSideEncryptionByDefault as $default) {
foreach ($default as $key => $value) {
if ($key === 'SSEAlgorithm') {
$this->sseAlgorithm = strval($value);
} elseif ($key === 'KMSMasterKeyID') {
$this->kmsMasterKeyID = strval($value);
}
}
break;
}
}
/**
* Serialize the object into xml string.
*
* @return string
*/
public function serializeToXml()
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><ServerSideEncryptionRule></ServerSideEncryptionRule>');
$default = $xml->addChild('ApplyServerSideEncryptionByDefault');
if (isset($this->sseAlgorithm)) {
$default->addChild('SSEAlgorithm', $this->sseAlgorithm);
}
if (isset($this->kmsMasterKeyID)) {
$default->addChild('KMSMasterKeyID', $this->kmsMasterKeyID);
}
return $xml->asXML();
}
public function __toString()
{
return $this->serializeToXml();
}
/**
* @return string
*/
public function getSSEAlgorithm()
{
return $this->sseAlgorithm;
}
/**
* @return string
*/
public function getKMSMasterKeyID()
{
return $this->kmsMasterKeyID;
}
private $sseAlgorithm = "";
private $kmsMasterKeyID = "";
}

View File

@ -2,6 +2,8 @@
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class StorageCapacityConfig
*

View File

@ -0,0 +1,41 @@
<?php
namespace OSS\Model;
/**
* Class Tag
* @package OSS\Model
*/
class Tag
{
/**
* Tag constructor.
*
* @param string $key
* @param string $value
*/
public function __construct($key, $value)
{
$this->key = $key;
$this->value = $value;
}
/**
* @return string
*/
public function getKey()
{
return $this->key;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
private $key = "";
private $value = "";
}

View File

@ -0,0 +1,89 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class TaggingConfig
* @package OSS\Model
*
*/
class TaggingConfig implements XmlConfig
{
/**
* TaggingConfig constructor.
*/
public function __construct()
{
$this->tags = array();
}
/**
* Get Tag list
*
* @return Tag[]
*/
public function getTags()
{
return $this->tags;
}
/**
* Add a new Tag
*
* @param Tag $tag
* @throws OssException
*/
public function addTag($tag)
{
$this->tags[] = $tag;
}
/**
* Parse TaggingConfig from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);
if (!isset($xml->TagSet) || !isset($xml->TagSet->Tag)) return;
foreach ($xml->TagSet->Tag as $tag) {
$this->addTag(new Tag($tag->Key, $tag->Value));
}
}
/**
* Serialize the object into xml string.
*
* @return string
*/
public function serializeToXml()
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><Tagging></Tagging>');
$xmlTagSet = $xml->addChild('TagSet');
foreach ($this->tags as $tag) {
$xmlTag = $xmlTagSet->addChild('Tag');
$xmlTag->addChild('Key', strval($tag->getKey()));
$xmlTag->addChild('Value', strval($tag->getValue()));
}
return $xml->asXML();
}
public function __toString()
{
return $this->serializeToXml();
}
/**
* Tag list
*
* @var Tag[]
*/
private $tags = array();
}

View File

@ -0,0 +1,67 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class VersioningConfig
* @package OSS\Model
*
*/
class VersioningConfig implements XmlConfig
{
/**
* VersioningConfig constructor.
* @param null $status
*/
public function __construct($status = null)
{
$this->status = $status;
}
/**
* Parse VersioningConfig from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);
if (isset($xml->Status)) {
$this->status = strval($xml->Status);
}
}
/**
* Serialize the object into xml string.
*
* @return string
*/
public function serializeToXml()
{
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><VersioningConfiguration></VersioningConfiguration>');
if (isset($this->status)) {
$xml->addChild('Status', $this->status);
}
return $xml->asXML();
}
public function __toString()
{
return $this->serializeToXml();
}
/**
* @return string
*/
public function getStatus()
{
return $this->status;
}
private $status = "";
}

View File

@ -0,0 +1,90 @@
<?php
namespace OSS\Model;
use OSS\Core\OssException;
/**
* Class WormConfig
* @package OSS\Model
*
*/
class WormConfig implements XmlConfig
{
/**
* Parse WormConfig from the xml.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
$xml = simplexml_load_string($strXml);
if (isset($xml->WormId)) {
$this->wormId = strval($xml->WormId);
}
if (isset($xml->State)) {
$this->state = strval($xml->State);
}
if (isset($xml->RetentionPeriodInDays)) {
$this->day = intval($xml->RetentionPeriodInDays);
}
if (isset($xml->CreationDate)) {
$this->creationDate = strval($xml->CreationDate);
}
}
/**
* Serialize the object into xml string.
*
* @return string
*/
public function serializeToXml()
{
throw new OssException("Not implemented.");
}
public function __toString()
{
return $this->serializeToXml();
}
/**
* @return string
*/
public function getWormId()
{
return $this->wormId;
}
/**
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* @return int
*/
public function getDay()
{
return $this->day;
}
/**
* @return string
*/
public function getCreationDate()
{
return $this->creationDate;
}
private $wormId = '';
private $state = '';
private $creationDate = '';
private $day = 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,6 @@ class CopyObjectResult extends Result
$result[] = $xml->ETag;
}
return $result;
return array_merge($result, $this->rawResponse->header);
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace OSS\Result;
use OSS\Core\OssUtil;
use OSS\Model\DeletedObjectInfo;
/**
* Class DeleteObjectVersionsResult
* @package OSS\Result
*/
class DeleteObjectVersionsResult extends Result
{
/**
* @return DeletedObjectInfo[]
*/
protected function parseDataFromResponse()
{
$xml = simplexml_load_string($this->rawResponse->body);
$encodingType = isset($xml->EncodingType) ? strval($xml->EncodingType) : "";
return $this->parseDeletedList($xml, $encodingType);
}
private function parseDeletedList($xml, $encodingType)
{
$retList = array();
if (isset($xml->Deleted)) {
foreach ($xml->Deleted as $content) {
$key = isset($content->Key) ? strval($content->Key) : "";
$key = OssUtil::decodeKey($key, $encodingType);
$versionId = isset($content->VersionId) ? strval($content->VersionId) : "";
$deleteMarker = isset($content->DeleteMarker) ? strval($content->DeleteMarker) : "";
$deleteMarkerVersionId = isset($content->DeleteMarkerVersionId) ? strval($content->DeleteMarkerVersionId) : "";
$retList[] = new DeletedObjectInfo($key, $versionId, $deleteMarker, $deleteMarkerVersionId);
}
}
return $retList;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace OSS\Result;
use OSS\Model\ServerSideEncryptionConfig;
/**
* Class GetBucketEncryptionResult
* @package OSS\Result
*/
class GetBucketEncryptionResult extends Result
{
/**
* Parse the ServerSideEncryptionConfig object from the response
*
* @return ServerSideEncryptionConfig
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
$config = new ServerSideEncryptionConfig();
$config->parseFromXml($content);
return $config;
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace OSS\Result;
use OSS\Core\OssException;
use OSS\Model\BucketInfo;
/**
* Class GetBucketResult interface returns the result class, encapsulated
* The returned xml data is parsed
*
* @package OSS\Result
*/
class GetBucketInfoResult 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->Bucket)) {
$info = new BucketInfo();
$info->parseFromXmlNode($xml->Bucket);
return $info;
} else {
throw new OssException("xml format exception");
}
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace OSS\Result;
use OSS\Model\RequestPaymentConfig;
/**
* Class GetBucketRequestPaymentResult
* @package OSS\Result
*/
class GetBucketRequestPaymentResult extends Result
{
/**
* Parse the RequestPaymentConfig object from the response
*
* @return RequestPaymentConfig
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
$config = new RequestPaymentConfig();
$config->parseFromXml($content);
return $config->getPayer();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace OSS\Result;
use OSS\Model\BucketStat;
/**
* Class GetRefererResult
* @package OSS\Result
*/
class GetBucketStatResult extends Result
{
/**
* Parse bucket stat data
*
* @return BucketStat
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
$stat = new BucketStat();
$stat->parseFromXml($content);
return $stat;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace OSS\Result;
use OSS\Model\TaggingConfig;
/**
* Class GetBucketTagsResult
* @package OSS\Result
*/
class GetBucketTagsResult extends Result
{
/**
* Parse the TaggingConfig object from the response
*
* @return TaggingConfig
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
$config = new TaggingConfig();
$config->parseFromXml($content);
return $config;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace OSS\Result;
use OSS\Model\VersioningConfig;
/**
* Class GetBucketVersioningResult
* @package OSS\Result
*/
class GetBucketVersioningResult extends Result
{
/**
* Parse the VersioningConfig object from the response
*
* @return VersioningConfig
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
$config = new VersioningConfig();
$config->parseFromXml($content);
return $config->getStatus();
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace OSS\Result;
use OSS\Model\WormConfig;
/**
* Class GetBucketWormResult
* @package OSS\Result
*/
class GetBucketWormResult extends Result
{
/**
* Parse bucket stat data
*
* @return WormConfig
*/
protected function parseDataFromResponse()
{
$content = $this->rawResponse->body;
$config = new WormConfig();
$config->parseFromXml($content);
return $config;
}
}

Some files were not shown because too many files have changed in this diff Show More