• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (PHP SDK)
  4. Lifecycle Management
  5. Viewing Lifecycle Rules

Viewing Lifecycle Rules

You can call ObsClient->getBucketLifecycleConfiguration to view lifecycle rules of a bucket. Sample code is as follows:

// Import the third-party open source libraries.
require 'vendor/autoload.php';
// Import the SDK code library.
require 'obs-autoloader.php';
// Declare the namespace.
use Obs\S3\ObsClient;
// Create an instance of ObsClient.
$obsClient = new ObsClient ( [ 
       'key' => '*** Provide your Access Key ***',
       'secret' => '*** Provide your Secret Key ***',
       'endpoint' => 'https://yourdomainname'
] );

$resp = $obsClient->getBucketLifecycleConfiguration ( [ 
       'Bucket' => 'bucketname' 
] );
printf ( "RequestId:%s\n", $resp ['RequestId'] );
foreach ($resp['Rules'] as $index => $rule) {
    printf("Rules[%d]\n", $index + 1);
    printf("ID:%s\n", $rule['ID']);
    printf("Prefix:%s\n", $rule['Prefix']);
    printf("Status:%s\n", $rule['Status']);
    foreach ($rule['Transitions'] as $i => $transition) {
        printf("[Transitions][$i][Date]:%s,[Transitions][$i][StorageClass]:%s\n", $transition['Date'], $transition['StorageClass']);
    }
    printf("Expiration[Days]:%s\n", $rule['Expiration']['Days']);
    printf("Expiration[Date]:%s\n", $rule['Expiration']['Date']);
    foreach ($rule['NoncurrentVersionTransitions'] as $i => $noncurrentVersionTransition) {
        printf("[NoncurrentVersionTransitions][$i][NoncurrentDays]:%d,[NoncurrentVersionTransitions][$i][StorageClass]:%s\n", $noncurrentVersionTransition['NoncurrentDays'], $noncurrentVersionTransition['StorageClass']);
    }
    printf("NoncurrentVersionExpiration[NoncurrentDays]:%s\n", $rule['NoncurrentVersionExpiration']['NoncurrentDays']);
}