-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from aliyun/dev-head-bucket
support wj poc
- Loading branch information
Showing
7 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace OSS\Model; | ||
|
||
/** | ||
* Class StorageCapacityConfig | ||
* | ||
* @package OSS\Model | ||
* @link http://docs.alibaba-inc.com/pages/viewpage.action?pageId=271614763 | ||
*/ | ||
class StorageCapacityConfig implements XmlConfig | ||
{ | ||
/** | ||
* StorageCapacityConfig constructor. | ||
* | ||
* @param int $storageCapacity | ||
*/ | ||
public function __construct($storageCapacity) | ||
{ | ||
$this->storageCapacity = $storageCapacity; | ||
} | ||
|
||
/** | ||
* Not implemented | ||
*/ | ||
public function parseFromXml($strXml) | ||
{ | ||
throw new OssException("Not implemented."); | ||
} | ||
|
||
/** | ||
* 把StorageCapacityConfig序列化成xml | ||
* | ||
* @return string | ||
*/ | ||
public function serializeToXml() | ||
{ | ||
$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><BucketUserQos></BucketUserQos>'); | ||
$xml->addChild('StorageCapacity', strval($this->storageCapacity)); | ||
return $xml->asXML(); | ||
} | ||
|
||
/** | ||
* To string | ||
* | ||
* @return string | ||
*/ | ||
function __toString() | ||
{ | ||
return $this->serializeToXml(); | ||
} | ||
|
||
/** | ||
* Set storage capacity | ||
* | ||
* @param int $storageCapacity | ||
*/ | ||
public function setStorageCapacity($storageCapacity) | ||
{ | ||
$this->storageCapacity = $storageCapacity; | ||
} | ||
|
||
/** | ||
* Get storage capacity | ||
* | ||
* @return int | ||
*/ | ||
public function getStorageCapacity() | ||
{ | ||
return $this->storageCapacity; | ||
} | ||
|
||
private $storageCapacity = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
namespace OSS\Tests; | ||
|
||
use OSS\Core\OssException; | ||
|
||
require_once __DIR__ . DIRECTORY_SEPARATOR . 'TestOssClientBase.php'; | ||
|
||
class OssClientBucketStorageCapacityTest extends TestOssClientBase | ||
{ | ||
public function testBucket() | ||
{ | ||
try { | ||
$storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket); | ||
$this->assertEquals($storageCapacity, - 1); | ||
} catch (OssException $e) { | ||
$this->assertTrue(false); | ||
} | ||
|
||
try { | ||
$this->ossClient->putBucketStorageCapacity($this->bucket, 1000); | ||
} catch (OssException $e) { | ||
$this->assertTrue(false); | ||
} | ||
|
||
try { | ||
Common::waitMetaSync(); | ||
$storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket); | ||
$this->assertEquals($storageCapacity, 1000); | ||
} catch (OssException $e) { | ||
$this->assertTrue(false); | ||
} | ||
|
||
try { | ||
$this->ossClient->putBucketStorageCapacity($this->bucket, 0); | ||
|
||
Common::waitMetaSync(); | ||
|
||
$storageCapacity = $this->ossClient->getBucketStorageCapacity($this->bucket); | ||
$this->assertEquals($storageCapacity, 0); | ||
|
||
$this->ossClient->putObject($this->bucket, 'test-storage-capacity','test-content'); | ||
$this->assertTrue(false); | ||
} catch (OssException $e) { | ||
$this->assertEquals('Bucket storage exceed max storage capacity.',$e->getErrorMessage()); | ||
} | ||
|
||
try { | ||
$this->ossClient->putBucketStorageCapacity($this->bucket, - 2); | ||
$this->assertTrue(false); | ||
} catch (OssException $e) { | ||
$this->assertEquals(400, $e->getHTTPStatus()); | ||
$this->assertEquals('InvalidArgument', $e->getErrorCode()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.