public function resolvePath($path)
    {
        if ($path[0] == '/') {
            throw new \InvalidArgumentException('Cannot resolve absolute path.');
        }

        $segments = $this->getPathSegments();
        if (!empty($segments)) {
            // Remove the last segment for relative paths.
            array_pop($segments);
        }
        $path = trim($path, '/');
        foreach (explode('/', trim($path, '/')) as $segment) {
            if ($segment == '.') {
                continue;
            }
            elseif ($segment == '..' && !empty($segments) && end($segments) != '..') {
                array_pop($segments);
            }
            else {
                $segments[] = $segment;
            }
        }

        return implode('/', $segments);
    }