Bin will be removed on June 1, 2014 in favor of http://gist.github.com. Please save all your pastes before then. So long, and thanks for all the fish!×
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public function tree($path) {
        return array_merge_recursive($this->generateTree($path), $this->generateTree($path, true));
    }
   
    private function generateTree($path, $files = false) {
        $folder = new Folder();
        $tree = $folder->tree($path, true, $files ? 'file' : 'dir');
        $offset = strlen($path . DS);
        $t = array();
        foreach ($tree as $current_path) {
            if ($current_path == $path) continue;
            $t = array_merge_recursive($this->nest(explode(DS, substr($current_path, $offset)), $files), $t);
        }
        return $t;
    }
   
    private function nest($paths, $files) {
        $count = count($paths);
        if ($count > 1) {
            return array(current($paths) => $this->nest(array_slice($paths, 1, $count), $files));
        } else {
            return $files ? array(current($paths)) : array(current($paths) => array());
        }
    }