public static function normalizePath($path)
    {
        // Resolve any streams
        /** @var UniformResourceLocator $locator */
        $locator = Grav::instance()['locator'];
        if ($locator->isStream($path)) {
            $path = $locator->findResource($path);
        }

        // Set root properly for any URLs
        $root = '';
        preg_match(self::ROOTURL_REGEX, $path, $matches);
        if ($matches) {
            $root = $matches[1];
            $path = $matches[2];
        }

        // Strip off leading / to ensure explode is accurate
        if (Utils::startsWith($path,'/')) {
            $root .= '/';
            $path = ltrim($path, '/');
        }

        // If there are any relative paths (..) handle those
        if (Utils::contains($path, '..')) {
            $segments = explode('/', trim($path, '/'));
            $ret = [];
            foreach ($segments as $segment) {
                if (($segment === '.') || $segment === '') {
                    continue;
                }
                if ($segment === '..') {
                    array_pop($ret);
                } else {
                    $ret[] = $segment;
                }
            }
            $path = implode('/', $ret);
        }

        // Stick everything back together
        $normalized = $root . $path;
        return $normalized;
    }
public static function normalizePath($path)
    {
        // Resolve any streams
        /** @var UniformResourceLocator $locator */
        $locator = Grav::instance()['locator'];
        if ($locator->isStream($path)) {
            $path = $locator->findResource($path);
        }

        // Set root properly for any URLs
        $root = '';
        preg_match(self::ROOTURL_REGEX, $path, $matches);
        if ($matches) {
            $root = $matches[1];
            $path = $matches[2];
        }

        // Strip off leading / to ensure explode is accurate
        if (Utils::startsWith($path,'/')) {
            $root .= '/';
            $path = ltrim($path, '/');
        }

        // If there are any relative paths (..) handle those
        if (Utils::contains($path, '..')) {
            $segments = explode('/', trim($path, '/'));
            $ret = [];
            foreach ($segments as $segment) {
                if (($segment === '.') || $segment === '') {
                    continue;
                }
                if ($segment === '..') {
                    array_pop($ret);
                } else {
                    $ret[] = $segment;
                }
            }
            $path = implode('/', $ret);
        }

        // Stick everything back together
        $normalized = $root . $path;
        return $normalized;
    }
public static function normalizePath ( $ path ) { // Resolve any streams /** @var UniformResourceLocator $locator */ $ locator = Grav :: instance ( ) [ 'locator' ] ; if ( $ locator -> isStream ( $ path ) ) { $ path = $ locator -> findResource ( $ path ) ; } // Set root properly for any URLs $ root = '' ; preg_match ( self :: ROOTURL_REGEX , $ path , $ matches ) ; if ( $ matches ) { $ root = $ matches [ 1 ] ; $ path = $ matches [ 2 ] ; } // Strip off leading / to ensure explode is accurate if ( Utils :: startsWith ( $ path , '/' ) ) { $ root .= '/' ; $ path = ltrim ( $ path , '/' ) ; } // If there are any relative paths (..) handle those if ( Utils :: contains ( $ path , '..' ) ) { $ segments = explode ( '/' , trim ( $ path , '/' ) ) ; $ ret = [ ] ; foreach ( $ segments as $ segment ) { if ( ( $ segment === '.' ) || $ segment === '' ) { continue ; } if ( $ segment === '..' ) { array_pop ( $ ret ) ; } else { $ ret [ ] = $ segment ; } } $ path = implode ( '/' , $ ret ) ; } // Stick everything back together $ normalized = $ root . $ path ; return $ normalized ; }
Normalize path by processing relative `.` and `..` syntax and merging path

@param string $path

@return string
Normalize path by processing relative . and .. syntax and merging path