src/File/Path.php
/**
	 * Join path parts together into a canonical path.
	 *
	 * @author https://github.com/symfony/symfony/blob/6.0/src/Symfony/Component/Filesystem/Path.php
	 * @param string ...$paths
	 * @return string
	 */
Join path parts together into a canonical path.
Join path parts together into a canonical path .
public static function join(string ...$paths): string
	{
		$finalPath = null;
		$wasScheme = false;
		foreach ($paths as $path) {
			if ('' === $path) {
				continue;
			}
			if (null === $finalPath) {
				$finalPath = $path;
				$wasScheme = (false !== mb_strpos($path, '://'));
				continue;
			}
			if (!\in_array(mb_substr($finalPath, -1), ['/', '\\'])) {
				$finalPath .= '/';
			}
			$finalPath .= $wasScheme ? $path : ltrim($path, '/');
			$wasScheme = false;
		}
		if (null === $finalPath) {
			return '';
		}
		return $finalPath;
	}
public static function join ( string ... $ paths ) : string { $ finalPath = null ; $ wasScheme = false ; foreach ( $ paths as $ path ) { if ( '' === $ path ) { continue ; } if ( null === $ finalPath ) { $ finalPath = $ path ; $ wasScheme = ( false !== mb_strpos ( $ path , '://' ) ) ; continue ; } if ( ! \ in_array ( mb_substr ( $ finalPath , - 1 ) , [ '/' , '\\' ] ) ) { $ finalPath .= '/' ; } $ finalPath .= $ wasScheme ? $ path : ltrim ( $ path , '/' ) ; $ wasScheme = false ; } if ( null === $ finalPath ) { return '' ; } return $ finalPath ; }
Join path parts together into a canonical path.
Join path parts together into a canonical path .
// For first part we keep slashes, like '/top', 'C:\' or 'phar://' // Only add slash if previous part didn't end with '/' or '\' // If first part included a scheme like 'phar://' we allow \current part to start with '/', otherwise trim