public static function getDirTree($dir, $self = false)
    {
        if (!is_dir($dir)) {
            throw new RuntimeException(sprintf(
                'Can not build directory tree because of invalid path "%s"', $dir
            ));
        }

        $target = array();
        $tree = array();

        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), 
            RecursiveIteratorIterator::SELF_FIRST
        );

        if ($self !== false) {
            array_push($target, $dir);
        }

        foreach ($iterator as $file) {
            array_push ($target, $file);
        }

        foreach ($target as $index => $file) {
            array_push($tree, (string) $file);
        }

        return $tree;
    }