Create a new Uri form $_SERVER
199447
public function createUriFromServer(array $server)
    {
        if (isset($server['HTTPS'])) {
            if (!empty($server['HTTPS']) && $server['HTTPS'] !== 'off') {
                $scheme = 'https';
            }
        }
        if (!isset($scheme)) {
            $scheme = 'http';
        }

        $username = isset($server['PHP_AUTH_USER']) ? $server['PHP_AUTH_USER'] : '';
        $password = isset($server['PHP_AUTH_PW']) ? $server['PHP_AUTH_PW'] : '';

        $host = isset($server['HTTP_HOST']) ? $server['HTTP_HOST'] : $server['SERVER_NAME'];

        $port = isset($server['SERVER_PORT']) ? (int)$server['SERVER_PORT'] : 80;
        if (preg_match('/^(\[[a-fA-F0-9:.]+\])(:\d+)?\z/', $host, $matches)) {
            $host = $matches[1];

            if ($matches[2]) {
                $port = (int) substr($matches[2], 1);
            }
        } else {
            $pos = strpos($host, ':');
            if ($pos !== false) {
                $port = (int) substr($host, $pos + 1);
                $host = strstr($host, ':', true);
            }
        }

        $requestScriptName = parse_url($server['SCRIPT_NAME'], PHP_URL_PATH);
        $requestScriptDir = dirname($requestScriptName);

        $requestUri = parse_url('http://example.com' . $server['REQUEST_URI'], PHP_URL_PATH);

        $basePath = '';
        $virtualPath = $requestUri;
        if (stripos($requestUri, $requestScriptName) === 0) {
            $basePath = $requestScriptName;
        } elseif ($requestScriptDir !== '/' && stripos($requestUri, $requestScriptDir) === 0) {
            $basePath = $requestScriptDir;
        }

        if ($basePath) {
            $virtualPath = ltrim(substr($requestUri, strlen($basePath)), '/');
        }

        $queryString = isset($server['QUERY_STRING']) ? $server['QUERY_STRING'] : '';
        if ($queryString === '') {
            $queryString = parse_url('http://example.com' . $server['REQUEST_URI'], PHP_URL_QUERY);
        }

        $fragment = '';

        $uri = new Uri($scheme, $host, $port, $virtualPath, $queryString, $fragment, $username, $password);
        if ($basePath) {
            $uri = $uri->withBasePath($basePath);
        }

        return $uri;
    }
361942
public static function URI()
    {
        $REDIRECT_QUERY_STRING =
            isset($_SERVER['QUERY_STRING'])
            ? $_SERVER['QUERY_STRING']
            : '';

        $REDIRECT_URL = '';

        if (isset($_SERVER['REQUEST_URI'])) {
            $url_parts = parse_url($_SERVER['REQUEST_URI']);
            $REDIRECT_URL = $url_parts['path'];
        }

        $URI = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/');

        if (substr($REDIRECT_URL, 0, strlen($URI)) == $URI) {
            $URI = substr($REDIRECT_URL, strlen($URI));
        }

        $URI = urldecode($URI) . '/';

        $URI = trim($URI, '/');

        $parameters = [];

        //Extract parameters from QUERY string
        parse_str($REDIRECT_QUERY_STRING, $parameters);

        return [$URI, $parameters];
    }
733345
def build_url_query(current_path, datum = nil)
      unless datum.nil?
        current_path += '?'
        current_path += URI.encode_www_form datum
      end
      current_path
    end
956439
private function resolveBaseUriVar() {
        $envName = 'APP_BASE_URI';
        $envValue = null;

        if (!isset($_SERVER[$envName]))
            $envName = 'REDIRECT_'.$envName;

        while (isset($_SERVER[$envName])) {
            $envValue = $_SERVER[$envName];
            $envName = 'REDIRECT_'.$envName;
        }
        return $envValue;
    }
945945
public static function init() {
		if ( php_sapi_name() == 'cli' ) {
			self::$BasePath = str_replace( '/', DIRECTORY_SEPARATOR, dirname( __FILE__ ) . '/' );
		} else {
			self::$BasePath = str_replace( '/', DIRECTORY_SEPARATOR, realpath( dirname( __FILE__ ) ) . "/" );
		}

		if ( isset( $_SERVER['HTTPS'] ) ||
		     ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] == 443 ) ||
		     ( isset( $_SERVER['HTTP_X_FORWARDED_PORT'] ) && $_SERVER['HTTP_X_FORWARDED_PORT'] == 443 )
		) {
			self::$protocol = "https://";
		} else {
			self::$protocol = "http://";
		}

		$PathInfo = pathinfo( $_SERVER['PHP_SELF'] );

		$index = basename( $_SERVER["SCRIPT_FILENAME"], '.php' ) . '.php';
		Config::set( 'index', $index );

		if ( strpos( $PathInfo['dirname'], '/' . $index ) > 0 ) {
			$StrLimit = strpos( $PathInfo['dirname'], '/' . $index );
		} elseif ( $PathInfo['dirname'] == '/' . $index ) {
			$StrLimit = 0;
		} else {
			$StrLimit = strlen( $PathInfo['dirname'] );
		}

		if ( php_sapi_name() == 'cli-server' ) {
			self::$BaseUrl = self::$protocol . $_SERVER['HTTP_HOST'] . '/';
		} else if ( php_sapi_name() == 'cli' ) {
			self::$params = $_SERVER['argv'];
			chdir( self::$BasePath );
			self::$BaseUrl = self::$BasePath;
		} else {

			/**
			 * ID: Terkadang terdapat masalah bagian base url, kamu dapat mengedit bagian ini. Biasanya masalah pada
			 *     $PathInfo['dirname']
			 * EN: Sometimes have a problem in base url section, you can editi this section. normally at
			 *     $PathInfo['dirname']
			 */
			self::$BaseUrl = self::$protocol . $_SERVER['HTTP_HOST'] . substr( $PathInfo['dirname'], 0, $StrLimit );

			if ( substr( self::$BaseUrl, - 1, 1 ) != '/' ) {
				self::$BaseUrl .= '/';
			}

		}

		if ( php_sapi_name() == 'cli' ) {
			$ResultSegment = $_SERVER['argv'];
			array_shift( $ResultSegment );

			self::$params     = $ResultSegment;
			self::$RealParams = self::$params;
			self::$ParamsStr  = implode( '/', $ResultSegment );
		} else {
            $path = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);

            if (substr($path, 0, 1) == '/' && strlen($path) > 1) {
                $path = substr($path, 1);
            }

			$segments = explode( '/', $path );

			if ( $segments[ count( $segments ) - 1 ] == '' && count( $segments ) > 1 ) {
				unset( $segments[ count( $segments ) - 1 ] );
			}

			$ResultSegment = array();

			while ( list( $key, $seg ) = each( $segments ) ) {

				if ( $segments[ $key ] != $index && $seg != '' ) {
					array_push( $ResultSegment, urldecode( $seg ) );
				}
			}

			self::$ParamsStr  = implode( '/', $ResultSegment );
			self::$params     = $ResultSegment;
			self::$RealParams = self::$params;
		}

		unset( $StrLimit );
		unset( $PathInfo );

	}
807715
public function create($uri = null)
    {
        if (empty($uri)) {

            // Empty uri means baseurl
            return $this->baseUrl
                . (($this->urlType == self::URL_APPEND)
                    ? "/$this->scriptName"
                    : null);

        } elseif (substr($uri, 0, 7) == "http://" || substr($uri, 0, 2) == "//") {

            // Fully qualified, just leave as is.
            return rtrim($uri, '/');

        } elseif ($uri[0] == '/') {

            // Absolute url, prepend with siteUrl
            return rtrim($this->siteUrl . rtrim($uri, '/'), '/');

        }

        $uri = rtrim($uri, '/');
        if ($this->urlType == self::URL_CLEAN) {
            return $this->baseUrl . '/' . $uri;
        } else {
            return $this->baseUrl . '/' . $this->scriptName . '/' . $uri;
        }
    }
931062
public function resolveUriPath()
    {
        if(!$this->server)
            return;

        list($requestUri) = explode('?', $this->server['REQUEST_URI']);

        if(strpos($requestUri, $this->server['SCRIPT_NAME']) === 0)
        {
            $basePath = $this->server['SCRIPT_NAME'];
        }
        else
        {
            $basePath = explode('/', $this->server['SCRIPT_NAME']);
            array_pop($basePath);
            $basePath = implode('/', $basePath);
        }

        $requestUri = trim($requestUri, '/');

        $requestUri = '/'.trim(substr($requestUri, strlen(trim($basePath, '/'))), '/');

        $this->uri->setPath($requestUri);
    }
418275
protected function prepareUri($server)
    {
        $uri = new Uri('');

        if ((isset($server['HTTPS']) && $server['HTTPS'] != 'off') ||
            (isset($server['HTTP_X_FORWARDED_PROTO']) && $server['HTTP_X_FORWARDED_PROTO'] == 'https')
        ) {
            $schema = 'https';
        } else {
            $schema = 'http';
        }

        $parsedUrl = parse_url($server['REQUEST_URI']);
        $username = isset($server['PHP_AUTH_USER']) ? $server['PHP_AUTH_USER'] : null;
        $password = isset($server['PHP_AUTH_PW']) ? $server['PHP_AUTH_PW'] : null;

        return $uri->withScheme($schema)
            ->withHost($server['HTTP_HOST'])
            ->withPort($server['SERVER_PORT'])
            ->withPath(isset($parsedUrl['path']) ? $parsedUrl['path'] : '/')
            ->withUserInfo($username, $password)
            ->withQuery(isset($parsedUrl['query']) ? $parsedUrl['query'] : '');
    }
1357495
private function _buildServerURI($path = 'challenge')
	{
	  	// Scheme
		$uri  = ( TRUE === $this->_ssl ) ? 'https://' : 'http://';
	  	// Host
		$uri .= self::RECAPTCHA_API_SERVER;
	  	// Path
		$uri .= ($path !== 'challenge') ? 'noscript' : $path;
	  	// Query
		$uri .= '?k=' . $this->_publicKey;
		$uri .= ($this->_error) ? '&error=' . $this->_error : NULL;
		$uri .= ( isset($this->_recaptchaOptions['lang']) ) ? '&hl=' . $this->_recaptchaOptions['lang'] : '&hl=' .$this->clientLang();

		return $uri;
	}
694001
private function getURI()
    {
        if (!empty($_SERVER['PATH_INFO'])) {
            $uri = $_SERVER['PATH_INFO'];
        } elseif (!empty($_SERVER['REQUEST_URI'])) {
            $uri = $_SERVER['REQUEST_URI'];
        } else {
            $uri = false;
        }

        if ($uri === '/') {
            $uri = false;
        }

        return trim(preg_replace('/\?.*/', '', $uri), '/');
    }
1077174
protected function createFromGlobals() {
    if(php_sapi_name() === 'cli') {
      throw new InvalidStateException('Requests can not be instantiated from globals in CLI mode');
    }
    
    $method  = HttpMethod::memberByKey($_SERVER['REQUEST_METHOD'], false);
    $uri     = strtok($_SERVER['REQUEST_URI'], '?');
    $host    = $_SERVER['HTTP_HOST'];
    $headers = getallheaders();
    
    $this->create($method, $uri, $host, $headers, $_COOKIE, $_GET, $_POST);
  }
94688
def new_mountpoint(self, name):
        """"""
        url = posixpath.join(self.path, name)
        r = self._jfs.post(url, extra_headers={'content-type': 'application/x-www-form-urlencoded'})
        return r
544428
public function createUri($page)
    {
        $queryString   = $this->query;
        $queryString[] = "page={$page}";
        $queryString   = implode('&', $queryString);

        return Request::pathInfo() . "?{$queryString}";
    }
1367025
static function createUriString($scheme, $authority, $path, $query, $fragment) {
        $uri = '';
        if (!empty($scheme)) {
            $uri .= $scheme . ':';
        }
        $hierPart = '';
        if (!empty($authority)) {
            if (!empty($scheme)) {
                $hierPart .= '//';
            }
            $hierPart .= $authority;
        }
        if ($path != null) {
            // Add a leading slash if necessary.
            if ($hierPart && substr($path, 0, 1) !== '/') {
                $hierPart .= '/';
            }
            $hierPart .= $path;
        }
        $uri .= $hierPart;
        if ($query != null) {
            $uri .= '?' . $query;
        }
        if ($fragment != null) {
            $uri .= '#' . $fragment;
        }
        return $uri;
    }
1222902
public static function getUriFromGlobals() {
        $uri = new Uri('');

        $uri = $uri->withScheme(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http');

        $hasPort = false;
        if (isset($_SERVER['HTTP_HOST'])) {
            $hostHeaderParts = explode(':', $_SERVER['HTTP_HOST']);
            $uri = $uri->withHost($hostHeaderParts[0]);
            if (isset($hostHeaderParts[1])) {
                $hasPort = true;
                $uri = $uri->withPort($hostHeaderParts[1]);
            }
        } elseif (isset($_SERVER['SERVER_NAME'])) {
            $uri = $uri->withHost($_SERVER['SERVER_NAME']);
        } elseif (isset($_SERVER['SERVER_ADDR'])) {
            $uri = $uri->withHost($_SERVER['SERVER_ADDR']);
        }

        if (!$hasPort && isset($_SERVER['SERVER_PORT'])) {
            $uri = $uri->withPort($_SERVER['SERVER_PORT']);
        }

        $hasQuery = false;
        if (isset($_SERVER['REQUEST_URI'])) {
            $requestUriParts = explode('?', $_SERVER['REQUEST_URI']);
            $uri = $uri->withPath($requestUriParts[0]);
            if (isset($requestUriParts[1])) {
                $hasQuery = true;
                $uri = $uri->withQuery($requestUriParts[1]);
            }
        }

        if (!$hasQuery && isset($_SERVER['QUERY_STRING'])) {
            $uri = $uri->withQuery($_SERVER['QUERY_STRING']);
        }

        return $uri;
    }
1346155
public static function createGlobal()
    {
        $uri = new Uri(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '');
        $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
        $request = new self(
            $uri,
            $method,
            $_GET,
            $_POST,
            $_COOKIE,
            UploadedFile::convert($_FILES),
            $_SERVER
        );
        foreach ($_SERVER as $name => $value) {
            if (substr_compare($name, 'HTTP_', 0, 5) === 0) {
                $request->setHeader(str_replace('_', '-', substr($name, 5)), $value);
            }
        }
        return $request;
    }
865821
protected function determineUri()
    {
        $params = $this->getServerParams();
        
        $parts = $this->mapUriPartsFromServerParams($params);
        
        if (
            isset($params['SERVER_PROTOCOL']) &&
            \Jasny\str_starts_with(strtoupper($params['SERVER_PROTOCOL']), 'HTTP/')
        ) {
            $parts['scheme'] = !empty($params['HTTPS']) && $params['HTTPS'] !== 'off' ? 'https' : 'http';
        }
        
        if (isset($parts['host'])) {
            list($parts['host']) = explode(':', $parts['host'], 2); // May include the port
        }
        
        if (isset($parts['path'])) {
            $parts['path'] = parse_url($parts['path'], PHP_URL_PATH); // Includes the query string
        }

        return new UriObject($parts);
    }