Back to Uri class

Method root

public static string
root
(mixed $pathonly = false, mixed $path = null)
Returns the root URI for the request.
Parameters
  • bool $pathonly If false, prepend the scheme, host and port information. Default is false.
  • string $path The path
Returns
  • string The root URI string.
Since
  • 1.7.0
Class: Uri
Project: Joomla

Method root - Source code

/**
 * Returns the root URI for the request.
 *
 * @param   boolean  $pathonly  If false, prepend the scheme, host and port information. Default is false.
 * @param   string   $path      The path
 *
 * @return  string  The root URI string.
 *
 * @since   1.7.0
 */
public static function root($pathonly = false, $path = null)
{
    // Get the scheme
    if (empty(static::$root)) {
        $uri = static::getInstance(static::base());
        static::$root['prefix'] = $uri->toString(array('scheme', 'host', 'port'));
        static::$root['path'] = rtrim($uri->toString(array('path')), '/\\');
    }
    // Get the scheme
    if (isset($path)) {
        static::$root['path'] = $path;
    }
    return $pathonly === false ? static::$root['prefix'] . static::$root['path'] . '/' : static::$root['path'];
}