Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replication related APIs, demos, and unit tests #206

Open
wants to merge 1 commit into
base: dev-2111
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
396 changes: 396 additions & 0 deletions samples/BucketReplication.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions samples/RunAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require_once __DIR__ . '/BucketReferer.php';
require_once __DIR__ . '/BucketLogging.php';
require_once __DIR__ . '/BucketWebsite.php';
require_once __DIR__ . '/BucketReplication.php';
require_once __DIR__ . '/Signature.php';
require_once __DIR__ . '/Object1.php';
require_once __DIR__ . '/MultipartUpload.php';
177 changes: 177 additions & 0 deletions src/OSS/Model/ReplicationConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<?php

namespace OSS\Model;

use OSS\Core\OssException;


/**
* Class ReplicationConfig
* @package OSS\Model
* @link https://help.aliyun.com/document_detail/177800.htm
*/
class ReplicationConfig implements XmlConfig
{

/**
* @var ReplicationRule[]
*/
private $rule;

/**
* @param $rule ReplicationRule
*/
public function addRule($rule){
$this->rule[] = $rule;
}

/**
* @return ReplicationRule[]
*/
public function getRules(){
return $this->rule;
}

/**
* Parse the xml into this object.
*
* @param string $strXml
* @throws OssException
* @return null
*/
public function parseFromXml($strXml)
{
$this->rule = array();
$xml = simplexml_load_string($strXml);
if (!isset($xml->Rule)) return;
$this->parseRule($xml->Rule);
}

/**
* @param $rules
*/
private function parseRule($rules)
{
if(isset($rules)){
foreach ($rules as $rule){
$replicationRule = new ReplicationRule();
if (isset($rule->ID)){
$replicationRule->setId(strval($rule->ID));
}
if (isset($rule->PrefixSet)){
foreach ($rule->PrefixSet->Prefix as $prefix){
$replicationRule->setPrefixSet(strval($prefix));
}
}
if (isset($rule->Action)){
$replicationRule->setAction(strval($rule->Action));
}
if (isset($rule->Destination)){
$this->parseDestination($rule->Destination,$replicationRule);
}
if (isset($rule->Status)){
$replicationRule->setStatus(strval($rule->Status));
}
if (isset($rule->HistoricalObjectReplication)){
$replicationRule->setHistoricalObjectReplication(strval($rule->HistoricalObjectReplication));
}
if (isset($rule->SyncRole)){
$replicationRule->setSyncRole(strval($rule->SyncRole));
}
if (isset($rule->SourceSelectionCriteria)){
$this->parseSourceSelectionCriteria($rule->SourceSelectionCriteria,$replicationRule);
}
if (isset($rule->EncryptionConfiguration)){
$this->parseEncryptionConfiguration($rule->EncryptionConfiguration,$replicationRule);
}
if (isset($rule->RTC->Status)){
$replicationRule->setRTC(strval($rule->RTC->Status));
}
$this->addRule($replicationRule);
}
}

}

/**
* @param $destination array
* @param $replicationRule ReplicationRule
*/
private function parseDestination($destination,&$replicationRule)
{
if(isset($destination)){
$replicationDestination = new ReplicationDestination();
if (isset($destination->Bucket)){
$replicationDestination->setBucket(strval($destination->Bucket));
}
if (isset($destination->Location)){
$replicationDestination->setLocation(strval($destination->Location));
}
if (isset($destination->TransferType)){
$replicationDestination->setTransferType(strval($destination->TransferType));
}
$replicationRule->addDestination($replicationDestination);
}

}

/**
* @param $sourceSelectionCriteria array
* @param $replicationRule ReplicationRule
*/
private function parseSourceSelectionCriteria($sourceSelectionCriteria,&$replicationRule)
{
if(isset($sourceSelectionCriteria)){
$replicationSourceSelectionCriteria = new ReplicationSourceSelectionCriteria();
if (isset($sourceSelectionCriteria->SseKmsEncryptedObjects->Status)){
$replicationSourceSelectionCriteria->setStatus(strval($sourceSelectionCriteria->SseKmsEncryptedObjects->Status));
}
$replicationRule->addSourceSelectionCriteria($replicationSourceSelectionCriteria);
}

}

/**
* @param $encryptionConfiguration array
* @param $replicationRule ReplicationRule
*/
private function parseEncryptionConfiguration($encryptionConfiguration,&$replicationRule)
{
if(isset($encryptionConfiguration)){
$replicationEncryptionConfiguration = new ReplicationEncryptionConfiguration();
if (isset($encryptionConfiguration->ReplicaKmsKeyID)){
$replicationEncryptionConfiguration->setReplicaKmsKeyID(strval($encryptionConfiguration->ReplicaKmsKeyID));
}
$replicationRule->addEncryptionConfiguration($replicationEncryptionConfiguration);
}
}

/**
* Serialize the object to xml
*
* @return string
*/
public function serializeToXml()
{

$xml = new \SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><ReplicationConfiguration></ReplicationConfiguration>');
foreach ($this->rule as $rule) {
$xmlRule = $xml->addChild('Rule');
$rule->appendToXml($xmlRule);
}
return $xml->asXML();
}

/**
* Serialize the object into xml string.
*
* @return string
*/
public function __toString()
{
return $this->serializeToXml();
}

}


82 changes: 82 additions & 0 deletions src/OSS/Model/ReplicationDestination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace OSS\Model;

/**
* Class ReplicationDestination
* @package OSS\Model
* @link https://help.aliyun.com/document_detail/181408.htm
*/
class ReplicationDestination
{
private $bucket;

private $location;

private $transferType;

/**
* @param $bucket string bucket name
*/
public function setBucket($bucket)
{
$this->bucket = $bucket;
}

/**
* @return string |null
*/
public function getBucket(){
return $this->bucket;
}

/**
* @param $location string
*/
public function setLocation($location)
{
$this->location = $location;
}

/**
* @return string |null
*/
public function getLocation(){
return $this->location;
}
/**
* @param $transferType string
*/
public function setTransferType($transferType)
{
$this->transferType = $transferType;
}

/**
* @return string |null
*/
public function getTransferType(){
return $this->transferType;
}

/**
* @param \SimpleXMLElement $xmlRule
*/
public function appendToXml(&$xmlRule)
{
if (isset($this->bucket) || isset($this->location) || isset($this->transferType)){
$xmlDestination = $xmlRule->addChild('Destination');
}
if (isset($this->bucket)){
$xmlDestination->addChild('Bucket', $this->bucket);
}
if (isset($this->location)){
$xmlDestination->addChild('Location', $this->location);
}
if (isset($this->transferType)){
$xmlDestination->addChild('TransferType', $this->transferType);
}
}
}


35 changes: 35 additions & 0 deletions src/OSS/Model/ReplicationEncryptionConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace OSS\Model;

/**
* Class ReplicationEncryptionConfiguration
* @package OSS\Model
* @link https://help.aliyun.com/document_detail/181408.htm
*/
class ReplicationEncryptionConfiguration
{
/**
* @var string
*/
private $replicaKmsKeyID;

/**
* @param $kmsId string
*/
public function setReplicaKmsKeyID($kmsId)
{
$this->replicaKmsKeyID = $kmsId;
}


/**
* @return string
*/
public function getReplicaKmsKeyID(){
return $this->replicaKmsKeyID;
}

}


Loading