public function testParseNullXml()
 {
     $lifecycleConfig = new LifecycleConfig();
     $lifecycleConfig->parseFromXml($this->nullLifecycle);
     $this->assertEquals($this->cleanXml($lifecycleConfig->serializeToXml()), $this->cleanXml($this->nullLifecycle));
     $this->assertEquals(0, count($lifecycleConfig->getRules()));
 }
 /**
  *  解析Lifestyle数据
  *
  * @return LifecycleConfig
  */
 protected function parseDataFromResponse()
 {
     $content = $this->rawResponse->body;
     $config = new LifecycleConfig();
     $config->parseFromXml($content);
     return $config;
 }
/**
 * 设置bucket的生命周期配置
 *
 * @param OssClient $ossClient OssClient实例
 * @param string $bucket 存储空间名称
 * @return null
 */
function putBucketLifecycle($ossClient, $bucket)
{
    $lifecycleConfig = new LifecycleConfig();
    $actions = array();
    $actions[] = new LifecycleAction(OssClient::OSS_LIFECYCLE_EXPIRATION, OssClient::OSS_LIFECYCLE_TIMING_DAYS, 3);
    $lifecycleRule = new LifecycleRule("delete obsoleted files", "obsoleted/", "Enabled", $actions);
    $lifecycleConfig->addRule($lifecycleRule);
    $actions = array();
    $actions[] = new LifecycleAction(OssClient::OSS_LIFECYCLE_EXPIRATION, OssClient::OSS_LIFECYCLE_TIMING_DATE, '2022-10-12T00:00:00.000Z');
    $lifecycleRule = new LifecycleRule("delete temporary files", "temporary/", "Enabled", $actions);
    $lifecycleConfig->addRule($lifecycleRule);
    try {
        $ossClient->putBucketLifecycle($bucket, $lifecycleConfig);
    } catch (OssException $e) {
        printf(__FUNCTION__ . ": FAILED\n");
        printf($e->getMessage() . "\n");
        return;
    }
    print __FUNCTION__ . ": OK" . "\n";
}
Ejemplo n.º 4
0
 public function testBucket()
 {
     $lifecycleConfig = new LifecycleConfig();
     $actions = array();
     $actions[] = new LifecycleAction("Expiration", "Days", 3);
     $lifecycleRule = new LifecycleRule("delete obsoleted files", "obsoleted/", "Enabled", $actions);
     $lifecycleConfig->addRule($lifecycleRule);
     $actions = array();
     $actions[] = new LifecycleAction("Expiration", "Date", '2022-10-12T00:00:00.000Z');
     $lifecycleRule = new LifecycleRule("delete temporary files", "temporary/", "Enabled", $actions);
     $lifecycleConfig->addRule($lifecycleRule);
     try {
         $this->ossClient->putBucketLifecycle($this->bucket, $lifecycleConfig);
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $lifecycleConfig2 = $this->ossClient->getBucketLifecycle($this->bucket);
         $this->assertEquals($lifecycleConfig->serializeToXml(), $lifecycleConfig2->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $this->ossClient->deleteBucketLifecycle($this->bucket);
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
     try {
         Common::waitMetaSync();
         $lifecycleConfig3 = $this->ossClient->getBucketLifecycle($this->bucket);
         $this->assertNotEquals($lifecycleConfig->serializeToXml(), $lifecycleConfig3->serializeToXml());
     } catch (OssException $e) {
         $this->assertTrue(false);
     }
 }
Ejemplo n.º 5
0
 /**
  * 设置Bucket的Lifecycle配置
  *
  * @param string $bucket bucket名称
  * @param LifecycleConfig $lifecycleConfig Lifecycle配置类
  * @param array $options
  * @throws OssException
  * @return null
  */
 public function putBucketLifecycle($bucket, $lifecycleConfig, $options = NULL)
 {
     $this->precheckCommon($bucket, NULL, $options, false);
     $options[self::OSS_BUCKET] = $bucket;
     $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
     $options[self::OSS_OBJECT] = '/';
     $options[self::OSS_SUB_RESOURCE] = 'lifecycle';
     $options[self::OSS_CONTENT_TYPE] = 'application/xml';
     $options[self::OSS_CONTENT] = $lifecycleConfig->serializeToXml();
     $response = $this->auth($options);
     $result = new PutSetDeleteResult($response);
     return $result->getData();
 }