public function getTree()
{
$tree = array();
$contents = $this->getBucketContents();
if ($contents === null) {
return null;
}
foreach ($contents as $key => $data) {
$isFolder = false;
// S3Hub and S3Fox append this suffix to folders
if (substr($key, -9) == '_$folder$') {
$key = substr($key, 0, -9);
$isFolder = true;
} else {
if (substr($key, -1) == '/') {
$key = substr($key, 0, -1);
$isFolder = true;
}
}
$parts = explode('/', $key);
// add to tree
$cur =& $tree;
$numParts = count($parts);
for ($i = 0; $i < $numParts; $i++) {
$part = $parts[$i];
// file
if (!$isFolder && $i == $numParts - 1 && !isset($cur[$part])) {
$cur[$part] = $data;
$cur[$part]['hsize'] = self::formatSize($data['size']);
$cur[$part]['path'] = $cur[$part]['name'];
$cur[$part]['name'] = $part;
} else {
if (!isset($cur[$part])) {
$path = implode('/', array_slice($parts, 0, $i + 1));
$cur[$part] = array('path' => $path, 'name' => $part, 'files' => array());
}
$cur =& $cur[$part]['files'];
}
}
}
return $tree;
}