public function read($id)
{
$result = '';
// Get the session data from DynamoDB (acquire a lock if locking is enabled)
if ($this->_session_locking)
{
$response = $this->_lock_and_read($id);
$node_name = 'Attributes';
}
else
{
$response = $this->_dynamodb->get_item(array(
'TableName' => $this->_table_name,
'Key' => array('HashKeyElement' => $this->_dynamodb->attribute($this->_id($id))),
'ConsistentRead' => $this->_consistent_reads,
));
$node_name = 'Item';
}
if ($response && $response->isOK())
{
$item = array();
// Get the data from the DynamoDB response
if ($response->body->{$node_name})
{
foreach ($response->body->{$node_name}->children() as $key => $value)
{
$type = $value->children()->getName();
$item[$key] = $value->{$type}->to_string();
}
}
if (isset($item['expires']) && isset($item['data']))
{
// Check the expiration date before using
if ($item['expires'] > time())
{
$result = $item['data'];
}
else
{
$this->destroy($id);
}
}
}
return $result;
}