Uri::createUriString( $scheme,  $authority,  $path,  $query,  $fragment )

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Create a URI string from its various parts.

Source

private static function createUriString(string $scheme, string $authority, string $path, string $query, string $fragment): string
{
    $uri = '';
    if ('' !== $scheme) {
        $uri .= $scheme . ':';
    }
    if ('' !== $authority) {
        $uri .= '//' . $authority;
    }
    if ('' !== $path) {
        if ('/' !== $path[0]) {
            if ('' !== $authority) {
                // If the path is rootless and an authority is present, the path MUST be prefixed by "/"
                $path = '/' . $path;
            }
        } elseif (isset($path[1]) && '/' === $path[1]) {
            if ('' === $authority) {
                // If the path is starting with more than one "/" and no authority is present, the
                // starting slashes MUST be reduced to one.
                $path = '/' . \ltrim($path, '/');
            }
        }
        $uri .= $path;
    }
    if ('' !== $query) {
        $uri .= '?' . $query;
    }
    if ('' !== $fragment) {
        $uri .= '#' . $fragment;
    }
    return $uri;
}

User Contributed Notes

You must log in before being able to contribute a note or feedback.