src/Path.php
/**
     * Return absolute path from a given path.
     *
     * This method is an alternative to `realpath()` function for non-existent paths.
     *
     * @param string $path      the path want to format
     * @param string $separator the directory separator want to use in the result
     *
     * @return string
     */
Return absolute path from a given path.
This method is an alternative to `realpath()` function for non-existent paths.

@param string $path      the path want to format
@param string $separator the directory separator want to use in the result

@return string
Return absolute path from a given path . This method is an alternative to ` realpath () ` function for non - existent paths . @param string $path the path want to format @param string $separator the directory separator want to use in the result @return string
public static function absolute($path, $separator = DIRECTORY_SEPARATOR)
    {
        $separator = $separator ?: DIRECTORY_SEPARATOR;
        $path      = static::normalize($path, $separator);
        $root = null;
        while (is_null($root)) {
            if (substr($path, 0, 1) === $separator) {
                $root = $separator;
                $path = substr($path, 1);
                break;
            }
            preg_match('/^[a-z]:' . preg_quote($separator, '/') . '/i', $path, $matches);
            if (isset($matches[0])) {
                $root = $matches[0];
                $path = substr($path, 2);
                break;
            }
            $path = static::normalize(getcwd(), $separator) . $separator . $path;
        }
        $subPaths  = array_filter(explode($separator, $path), 'strlen');
        $absolutes = [];
        foreach ($subPaths as $subPath) {
            if ('.' === $subPath) {
                continue;
            }
            if ('..' === $subPath) {
                array_pop($absolutes);
                continue;
            }
            $absolutes[] = $subPath;
        }
        return $root . implode($separator, $absolutes);
    }
public static function absolute ( $ path , $ separator = DIRECTORY_SEPARATOR ) { $ separator = $ separator ? : DIRECTORY_SEPARATOR ; $ path = static :: normalize ( $ path , $ separator ) ; $ root = null ; while ( is_null ( $ root ) ) { if ( substr ( $ path , 0 , 1 ) === $ separator ) { $ root = $ separator ; $ path = substr ( $ path , 1 ) ; break ; } preg_match ( '/^[a-z]:' . preg_quote ( $ separator , '/' ) . '/i' , $ path , $ matches ) ; if ( isset ( $ matches [ 0 ] ) ) { $ root = $ matches [ 0 ] ; $ path = substr ( $ path , 2 ) ; break ; } $ path = static :: normalize ( getcwd ( ) , $ separator ) . $ separator . $ path ; } $ subPaths = array_filter ( explode ( $ separator , $ path ) , 'strlen' ) ; $ absolutes = [ ] ; foreach ( $ subPaths as $ subPath ) { if ( '.' === $ subPath ) { continue ; } if ( '..' === $ subPath ) { array_pop ( $ absolutes ) ; continue ; } $ absolutes [ ] = $ subPath ; } return $ root . implode ( $ separator , $ absolutes ) ; }
Return absolute path from a given path.
Return absolute path from a given path .
// Normalize directory separators // Store root part of path // Check if path start with a separator (UNIX) // Check if path start with drive letter (WINDOWS OS) // Get and filter empty sub paths