protected function buildTree(\DirectoryIterator $it)
    {
        $result = [];

        foreach ($it as $key => $child) {
            if ($child->isDot()) {
                continue;
            }

            $name = $child->getBasename();

            if ($child->isDir()) {
                $subdir = new \DirectoryIterator($child->getPathname());
                $result[DIRECTORY_SEPARATOR . $name] = $this->buildTree($subdir);
            } else {
                $result[] = $name;
            }
        }

        return $result;
    }
protected function buildTree(\DirectoryIterator $it)
    {
        $result = [];

        foreach ($it as $key => $child) {
            if ($child->isDot()) {
                continue;
            }

            $name = $child->getBasename();

            if ($child->isDir()) {
                $subdir = new \DirectoryIterator($child->getPathname());
                $result[DIRECTORY_SEPARATOR . $name] = $this->buildTree($subdir);
            } else {
                $result[] = $name;
            }
        }

        return $result;
    }
protected function buildTree ( \ DirectoryIterator $ it ) { $ result = [ ] ; foreach ( $ it as $ key => $ child ) { if ( $ child -> isDot ( ) ) { continue ; } $ name = $ child -> getBasename ( ) ; if ( $ child -> isDir ( ) ) { $ subdir = new \ DirectoryIterator ( $ child -> getPathname ( ) ) ; $ result [ DIRECTORY_SEPARATOR . $ name ] = $ this -> buildTree ( $ subdir ) ; } else { $ result [ ] = $ name ; } } return $ result ; }
Build the directory tree

@param  \DirectoryIterator $it
@return array
Build the directory tree