public static function joinPaths($path1, $path2)
    {
        $abspath = $path1[0] == '/';

        $paths = array_filter(func_get_args());

        $paths = array_map(function($path) {
                $path = preg_replace('%^/%', '', $path);
                $path = preg_replace('%/$%', '', $path);
                return $path;
            },
            $paths);

        $path = implode('/', $paths);

        if($abspath) {
            return '/' . $path;
        } else {
            return $path;
        }
    }