create_lifecycle_config ( $bucket, $opt )

Enables the ability to specify a configuration that relates to the object’s lifecycle.

**NOTE:*In cases where the lifecycle configuration dictates that an object should be deleted, Amazon S3 guarantees that the object will be deleted when the expiration time is passed.

Access

public

Parameters

Parameter

Type

Required

Description

$bucket

string

Required

The name of the bucket to use.

$opt

array

Optional

An associative array of parameters that can have the following keys:

  • rules - string - Required - The object expiration rule-sets to apply to the bucket.
    • x - array - Required - This represents a simple array index.
      • id - string - Optional - Unique identifier for the rule. The value cannot be longer than 255 characters.
      • prefix - string - Required - The Amazon S3 object prefix which targets the file(s) for expiration.
      • expiration - array - Optional - The container for the unit of measurement by which the expiration time is calculated. At least one action (either transition or expiration) is required within one lifecycle rule.
        • date - string - Conditionally Required - The timestamp for when the targetted objects are to be moved or expired from the bucket. Should be in ISO 8601 Format. HH:MM:SS will be enforced as midnight GMT/UTC.
        • days - integer - Conditionally Required - The number of days until the targetted objects are to be moved or expired from the bucket. Must be a positive integer.
      • transition - array - Optional - The container for the element that describes a transition action. At least one action (either transition or expiration) is required within one lifecycle rule.
        • date - string - Conditionally Required - The timestamp for when the targetted objects are to be moved or expired from the bucket. Should be in ISO 8601 Format. HH:MM:SS will be enforced as midnight GMT/UTC.
        • days - integer - Conditionally Required - The number of days until the targetted objects are to be moved or expired from the bucket. Must be a positive integer.
        • storage - string - Required - The storage setting of an object. [Allowed values: AmazonS3::STORAGE_STANDARD, AmazonS3::STORAGE_REDUCED, STORAGE_GLACIER]. The default value is STORAGE_STANDARD.
      • enabled - boolean - Optional - Whether or not to enable this rule-set. A value of true enables the rule-set. A value of false disables the rule-set. The default value is true.
  • curlopts - array - Optional - A set of values to pass directly into curl_setopt(), where the key is a pre-defined CURLOPT_* constant.
  • returnCurlHandle - boolean - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.

Returns

Type

Description

CFResponse

A CFResponse object containing a parsed HTTP response.

Source

Method defined in services/s3.class.php | Toggle source view (105 lines) | View on GitHub

public function create_lifecycle_config($bucket, $opt = null)
{
    if (!$opt) $opt = array();
    $opt['verb'] = 'PUT';
    $opt['sub_resource'] = 'lifecycle';
    $opt['headers'] = array(
        'Content-Type' => 'application/xml'
    );

    $xml = simplexml_load_string($this->object_expiration_xml, $this->parser_class);

    if (isset($opt['rules']) && is_array($opt['rules']) && count($opt['rules']))
    {
        foreach ($opt['rules'] as $rule)
        {
            $xrule = $xml->addChild('Rule');

            // ID
            if (isset($rule['id']))
            {
                if (strlen($rule['id']) > 255)
                {
                    throw new S3_Exception('The "id" for a rule must not be more than 255 characters in the ' . __FUNCTION__ . ' method.');
                }

                $xrule->addChild('ID', $rule['id']);
            }

            // Prefix
            if (isset($rule['prefix']))
            {
                $xrule->addChild('Prefix', $rule['prefix']);
            }
            else
            {
                throw new S3_Exception('Each rule requires a "prefix" in the ' . __FUNCTION__ . ' method.');
            }

            // Status
            $enabled = 'Enabled';
            if (isset($rule['enabled']))
            {
                if (is_bool($rule['enabled'])) // Boolean
                {
                    $enabled = $rule['enabled'] ? 'Enabled' : 'Disabled';
                }
                elseif (is_string($rule['enabled'])) // String
                {
                    $enabled = (strtolower($rule['enabled']) === 'true') ? 'Enabled' : 'Disabled';
                }

                $xrule->addChild('Status', $enabled);
            }
            else
            {
                $xrule->addChild('Status', 'Enabled');
            }

            // Expiration
            if (isset($rule['expiration']))
            {
                $xexpiration = $xrule->addChild('Expiration');

                if (isset($rule['expiration']['date']))
                {
                    $xexpiration->addChild('Date', $rule['expiration']['date']);
                }
                elseif (isset($rule['expiration']['days']))
                {
                    $xexpiration->addChild('Days', $rule['expiration']['days']);
                }
            }

            // Transition
            if (isset($rule['transition']))
            {
                $xtransition = $xrule->addChild('Transition');

                if (isset($rule['transition']['date']))
                {
                    $xtransition->addChild('Date', $rule['transition']['date']);
                }
                elseif (isset($rule['transition']['days']))
                {
                    $xtransition->addChild('Days', $rule['transition']['days']);
                }

                if (isset($rule['transition']['storage']))
                {
                    $xtransition->addChild('StorageClass', $rule['transition']['storage']);
                }
            }

            if (!isset($rule['expiration']) && !isset($rule['transition']))
            {
                throw new S3_Exception('Each rule requires a either a "transition" or "expiration" entry in the ' . __FUNCTION__ . ' method.');
            }
        }
    }

    $opt['body'] = $xml->asXML();

    // Authenticate to S3
    return $this->authenticate($bucket, $opt);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback