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);
}