public static function resolve(string $path, bool $absolute = false)
    {
        $path = static::normalize($path);
        if (strpos($path, DIRECTORY_SEPARATOR) === 0) {
            // This was an absolute string, so keep it that way.
            $absolute = true;
        }
        /** @noinspection SpellCheckingInspection */
        $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
        $absolutes = array();
        foreach ($parts as $part) {
            if ('.' == $part) {
                continue;
            }
            if ('..' == $part) {
                array_pop($absolutes);
            } else {
                $absolutes[] = $part;
            }
        }
        $newPath = implode(DIRECTORY_SEPARATOR, $absolutes);

        if ($absolute === true) {
            $newPath = sprintf("%s%s", DIRECTORY_SEPARATOR, $newPath);
        }

        return $newPath;
    }
public static function resolve(string $path, bool $absolute = false)
    {
        $path = static::normalize($path);
        if (strpos($path, DIRECTORY_SEPARATOR) === 0) {
            // This was an absolute string, so keep it that way.
            $absolute = true;
        }
        /** @noinspection SpellCheckingInspection */
        $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
        $absolutes = array();
        foreach ($parts as $part) {
            if ('.' == $part) {
                continue;
            }
            if ('..' == $part) {
                array_pop($absolutes);
            } else {
                $absolutes[] = $part;
            }
        }
        $newPath = implode(DIRECTORY_SEPARATOR, $absolutes);

        if ($absolute === true) {
            $newPath = sprintf("%s%s", DIRECTORY_SEPARATOR, $newPath);
        }

        return $newPath;
    }
public static function resolve ( string $ path , bool $ absolute = false ) { $ path = static :: normalize ( $ path ) ; if ( strpos ( $ path , DIRECTORY_SEPARATOR ) === 0 ) { // This was an absolute string, so keep it that way. $ absolute = true ; } /** @noinspection SpellCheckingInspection */ $ parts = array_filter ( explode ( DIRECTORY_SEPARATOR , $ path ) , 'strlen' ) ; $ absolutes = array ( ) ; foreach ( $ parts as $ part ) { if ( '.' == $ part ) { continue ; } if ( '..' == $ part ) { array_pop ( $ absolutes ) ; } else { $ absolutes [ ] = $ part ; } } $ newPath = implode ( DIRECTORY_SEPARATOR , $ absolutes ) ; if ( $ absolute === true ) { $ newPath = sprintf ( "%s%s" , DIRECTORY_SEPARATOR , $ newPath ) ; } return $ newPath ; }
Naively resolve paths.

This attempts to discern the correct directory path from something that
contains relative indicators (i.e. `../`). It does not touch the actual
filesystem, so do not assume that these paths are accurate, or that they
even exist.

Notably, this means that you can use this to deal with symlinks
(Specifically you can look at their locations without resolving their
targets.)

@link http://www.php.net/manual/en/function.realpath.php#84012

@param string $path
@param boolean $absolute     Set to `true` to prepend a directory
separator.
@return string
Naively resolve paths .