Formatting the path to keep a valid URI

@param string $path

@return string
339680
protected function formatPath(string $path): string
    {
        if ('' === $path) {
            $base_path = $this->base_uri->getPath();
            return in_array($base_path, ['', '/'], true) ? $base_path : './';
        }

        if (false === ($colon_pos = strpos($path, ':'))) {
            return $path;
        }

        $slash_pos = strpos($path, '/');
        if (false === $slash_pos || $colon_pos < $slash_pos) {
            return "./$path";
        }

        return $path;
    }
324703
private function getCleanPath($path)
    {
        // remove the first slash for safety reasons [delimitor mapping] based on the web-server Rewrite
        if (mb_strpos($path, $this->delimiter) === 0) {
            $path = mb_substr($path, 1);
        }

        // if the last character is a delimiter remove it as well
        if (mb_strpos($path, $this->delimiter) == mb_strlen($path) - 1) {
            $path = mb_substr($path, 0, -1);
        }

        //remove the get parameter so it's clean
        if (($ppos = mb_strpos($path, '?')) && $ppos > 0) {
            $path = mb_substr($path, 0, $ppos);
        }

        unset($ppos);


        return $path;
    }
744582
protected static function normalizePath(string $path): string
    {
        static::init();
        return \rtrim(\str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path), DIRECTORY_SEPARATOR);
    }
321431
public static function normalize(string $path): string {
		if (!(false === strpos($path, '://'))) {
			$ex = explode("://", $path);

			return $ex[0] . "://" . "/" . ltrim(Util::normalizePath("/" . ltrim($ex[1], "/")));
		}

		return "/" . ltrim(Util::normalizePath($path), "/");
	}
227005
public static function url(string $path): string
    {
        return self::SCHEME . '://' . join(
                '/',
                array_map(
                        'rawurlencode',    // ensure singe path parts are correctly urlencoded
                        explode(
                                '/',
                                str_replace('\\', '/', $path)  // ensure correct directory separator
                        )
                )
        );
    }
869464
public static function normalizePath($path) : string
    {
        $path = self::fixDirectorySeparator($path);
        $path = preg_replace('|(?<=.)/+|', DIRECTORY_SEPARATOR, $path);
        if (':' === substr($path, 1, 1)) {
            $path = ucfirst($path);
        }

        if (Validator::isAbsolutePath($path) && strpos($path, '.')) {
            $explode = explode(DIRECTORY_SEPARATOR, $path);
            $array = [];
            foreach ($explode as $key => $value) {
                if ('.' == $value) {
                    continue;
                }
                if ('..' == $value) {
                    array_pop($array);
                } else {
                    $array[] = $value;
                }
            }

            $path = implode(DIRECTORY_SEPARATOR, $array);
        }

        return $path;
    }
147976
private function ensureUserPath(string $path): string
    {
        $userFolder = Str::normalizePath($this->package->config('user_folder'));
        if ($userFolder === '') {
            return $path;
        }

        if (starts_with($path, $userFolder)) {
            return $path;
        }

        return $userFolder . '/' . $path;
    }
1173086
private function normalizePath($path)
    {
        $path = rtrim($path, '/');

        if (empty($path) or '/' !== substr($path, 0, 1)) {
            $path = '/';
        }

        return $path;
    }
250816
public function getUrl($path)
    {
        $path = $this->applyPathPrefix($path);

        return implode('/', [$this->baseUrl, $path]);
    }
641961
public static function makeGoodPathHTTP($path)
    {

        $path = (string)$path;
        $path = str_replace('\\', '/', $path);
        $path = (string)$path;

        return $path;
    }
87538
static public function urlToPath($path)
    {
        $path = parse_url($path);
        return $path === null ? null : str_replace('/', DIRECTORY_SEPARATOR, $path['path']);
    }
1061021
public function urlFor($path)
    {
        $root = $this->options['api_root'][$this->options['mode']];
        return rtrim($root, '/') . '/' . ltrim($path, '/');
    }
998457
public function url($path)
    {
        $protocol = "http" . $this->isSecure();

        return $protocol . $_SERVER['HTTP_HOST'] .$this->getBaseUri() . $path;
    }
347461
public static function normalizeFullPath($path)
    {
        $to = Folder::correctSlashFor($path);
        $from = ($to == '/' ? '\\' : '/');

        return str_replace($from, $to, $path);
    }
1278019
public static function Normalize( string $path ) : string
   {
      $isWin = '\\' === DIRECTORY_SEPARATOR;
      if ( empty( static::$NoFolderSeparator ) )
      {
         static::$NoFolderSeparator = $isWin ? '/' : '\\';
      }
      $tmpPath = ( $isWin
         ? \trim(
            \str_replace(
               static::$NoFolderSeparator,
               \DIRECTORY_SEPARATOR,
               $path
            ),
            \DIRECTORY_SEPARATOR
         )
         : \rtrim(
            \str_replace(
               static::$NoFolderSeparator,
               \DIRECTORY_SEPARATOR,
               $path
            ),
            \DIRECTORY_SEPARATOR
         )
      );
      // return the resulting path and replace /./ or \.\ with a single directory separator
      return str_replace(
         \DIRECTORY_SEPARATOR . '.' . \DIRECTORY_SEPARATOR,
         \DIRECTORY_SEPARATOR,
         $tmpPath
      );
   }
787325
public function getPath(string $path = ''): string
    {
        return $this->dirPath.($path ? DIRECTORY_SEPARATOR.$path : $path);
    }
20630
public function normalizePath($path)
    {
        $path = trim($path);

        $path = str_replace(DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path);

        if (ends_with($path, DIRECTORY_SEPARATOR)) {
            $path = substr($path, 0, -1);
        }

        return $path;
    }