public function parseRawList(array $rawlist)
{
$items = array();
$path = '';
foreach ($rawlist as $key => $child) {
$chunks = preg_split("/\\s+/", $child);
if (isset($chunks[8]) && ($chunks[8] == '.' or $chunks[8] == '..')) {
continue;
}
if (count($chunks) === 1) {
$len = strlen($chunks[0]);
if ($len && $chunks[0][$len - 1] == ':') {
$path = substr($chunks[0], 0, -1);
}
continue;
}
$item = ['permissions' => $chunks[0], 'number' => $chunks[1], 'owner' => $chunks[2], 'group' => $chunks[3], 'size' => $chunks[4], 'month' => $chunks[5], 'day' => $chunks[6], 'time' => $chunks[7], 'name' => $chunks[8], 'type' => $this->rawToType($chunks[0])];
if ($item['type'] == 'link') {
$item['target'] = $chunks[10];
// 9 is "->"
}
// if the key is not the path, behavior of ftp_rawlist() PHP function
if (is_int($key) || false === strpos($key, $item['name'])) {
array_splice($chunks, 0, 8);
$key = $item['type'] . '#' . ($path ? $path . '/' : '') . implode(" ", $chunks);
if ($item['type'] == 'link') {
// get the first part of 'link#the-link.ext -> /path/of/the/source.ext'
$exp = explode(' ->', $key);
$key = rtrim($exp[0]);
}
$items[$key] = $item;
} else {
// the key is the path, behavior of FtpClient::rawlist() method()
$items[$key] = $item;
}
}
return $items;
}