Skip to content

Commit

Permalink
新增bucket tag操作
Browse files Browse the repository at this point in the history
  • Loading branch information
tioncico committed Jul 30, 2020
1 parent 9a5d8cd commit 54341e7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 7 deletions.
39 changes: 39 additions & 0 deletions src/AliYun/OssClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,45 @@ public function deleteBucketCname($bucket, $cname, $options = NULL)
return $result->getData();
}

public function putBucketTags($bucket,$tags){
$options = array();
$this->preCheckCommon($bucket, NULL, $options, false);
$options[OssConst::OSS_BUCKET] = $bucket;
$options[OssConst::OSS_METHOD] = OssConst::OSS_HTTP_PUT;
$options[OssConst::OSS_OBJECT] = '/';
$options[OssConst::OSS_SUB_RESOURCE] = 'tagging';
$taggingConfig = new TaggingConfig($tags);
$options[OssConst::OSS_CONTENT] = $taggingConfig->serializeToXml();
$response = $this->auth($options);
$result = new PutSetDeleteResult($response);
return $result->getData();
}

public function getBucketTags($bucket){
$options = array();
$this->preCheckCommon($bucket, NULL, $options, false);
$options[OssConst::OSS_BUCKET] = $bucket;
$options[OssConst::OSS_METHOD] = OssConst::OSS_HTTP_GET;
$options[OssConst::OSS_OBJECT] = '/';
$options[OssConst::OSS_SUB_RESOURCE] = 'tagging';
$response = $this->auth($options);
$result = new TaggingResult($response);
return $result->getData();
}

public function deleteBucketTags($bucket){
$options = array();
$this->preCheckCommon($bucket, NULL, $options, false);
$options[OssConst::OSS_METHOD] = OssConst::OSS_HTTP_DELETE;
$options[OssConst::OSS_BUCKET] = $bucket;
$options[OssConst::OSS_OBJECT] = '/';
$options[OssConst::OSS_SUB_RESOURCE] = 'tagging';
$options[OssConst::OSS_CONTENT] = '';
$response = $this->auth($options);
$result = new DeleteObjectsResult($response);
return $result->getData();
}

###########################buket请求#################################

###########################object请求#################################
Expand Down
60 changes: 60 additions & 0 deletions tests/AliYun/BucketTagTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Created by PhpStorm.
* User: Tioncico
* Date: 2019/11/18 0018
* Time: 15:02
*/

namespace EasySwoole\Oss\Tests\AliYun;

use EasySwoole\Oss\AliYun\Core\OssException;
use EasySwoole\Oss\AliYun\Model\WebsiteConfig;
use EasySwoole\Oss\AliYun\OssConst;
use PHPUnit\Framework\TestCase;

class BucketTagTest extends AliYunBaseTestCase
{
protected $bucketName = 'tioncicoxyz';

function setUp()
{
parent::setUp(); // TODO: Change the autogenerated stub
$this->addTestBucketName();
}

protected function addTestBucketName()
{
$bucketName = $this->bucketName;
// $data = $this->ossClient->doesBucketExist($bucketName);
$data = $this->client->doesBucketExist($bucketName);
if ($data === false) {
$data = $this->client->createBucket($bucketName);
}
}

public function testGetSet()
{
$bucket = $this->bucketName;
$client = Common::getOssClient();
try {
$tagArr = ['a' => 1, 'b' => 2];
$response = $client->putBucketTags($bucket, $tagArr);
// var_dump($response);
$this->assertTrue(!!$response);
$response = $client->getBucketTags($bucket);
// var_dump($response);
$this->assertTrue(!!$response);
$response = $client->deleteBucketTags($bucket);
// var_dump($response);
$this->assertEquals($response, []);
$response = $client->getBucketTags($bucket);
// var_dump($response);
$this->assertEquals($response, []);

} catch (OssException $e) {
$this->assertFalse(True, $e->getMessage());
}
}

}
7 changes: 0 additions & 7 deletions tests/AliYun/ObjectTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,5 @@ public function testGetSet()
} catch (OssException $e) {
$this->assertFalse(True, $e->getMessage());
}
//
// $client->putObjectAcl($bucket, $object, 'public-read');
// $acl = $client->getObjectAcl($bucket, $object);
// $this->assertEquals('public-read', $acl);
//
// $content = $client->getObject($bucket, $object);
// $this->assertEquals('hello world', $content);
}
}

0 comments on commit 54341e7

Please sign in to comment.