Returns the port component of the URI.

If no port is present or the port is the default port of the scheme null is returned.

@return int|null
960680
public function getPort()
    {
        return $this->port === null || $this->isDefaultPort($this->scheme, $this->port) ? null : $this->port;
    }
212677
public function getConnectionPort()
    {
        $port = 80;
        $host = $this->server()->httpHost();
        if (empty($host)) {
            return $port;
        }

        $host = $this->str($host);

        if ($host->contains(':')) {
            $port = $host->explode(':')->last();
        }

        return $port;
    }
1155937
public function getAbsolute(){
		if( empty( $this->parts->scheme ) )
			throw new RuntimeException( 'HTTP scheme not set' );
		if( empty( $this->parts->host ) )
			throw new RuntimeException( 'HTTP host not set' );
		$buffer	= array();
		if( $this->parts->scheme )
			$buffer[]	= $this->parts->scheme.'://';
		if( $this->parts->user ){
			$buffer[]	= $this->parts->user;
			if( $this->parts->pass )
				$buffer[]	= ':'.$this->parts->pass;
			$buffer[]	= '@';
		}
		if( $this->parts->host )
			$buffer[]	= $this->parts->host;
		if( $this->parts->port )
			$buffer[]	= ':'.$this->parts->port;
		if( $this->parts->path )
			$buffer[]	= $this->parts->path;
		if( $this->parts->query )
			$buffer[]	= '?'.$this->parts->query;
		if( $this->parts->fragment )
			$buffer[]	= '#'.$this->parts->fragment;
		return join( '', $buffer );
	}
264993
public function isDefaultPort(): bool
    {
        return $this->getPort() === null || (isset(self::$defaultPorts[$this->getScheme()]) && $this->getPort() === self::$defaultPorts[$this->getScheme()]);
    }
1361801
protected function getCurrentURI()
	{
		$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
		$current_uri = $protocol.$_SERVER['HTTP_HOST'].$this->getRequestURI();
		$parts = parse_url($current_uri);

		$query = '';
		if(!empty($parts['query']))
		{
			$params = array();
			parse_str($parts['query'], $params);
			$params = array_filter($params);
			if(!empty($params))
			{
				$query = '?'.http_build_query($params, '', '&');
			}
		}

		// Use port if non default.
		$port = isset($parts['port']) &&
			(($protocol === 'http://' && $parts['port'] !== 80) || ($protocol === 'https://' && $parts['port'] !== 443)) ? ':'.$parts['port']
				: '';

		// Rebuild.
		return $protocol.$parts['host'].$port.$parts['path'].$query;
	}
99552
public int getPort() {
    if (port != null && port != 0) {
      return port;
    }
    return urlParser != null ? urlParser.getHostAddresses().get(0).port : 3306;
  }
335719
public function getPort()
    {
        $port = parent::getPort();

        if (JUri::getInstance()->isSsl() || ($this->isSecure() && in_array($port, ['80', '8080']))) {
            $port = '443';
        }

        return $port;
    }
855660
public function getUri(): string
    {
        $uri = '';

        if ( null !== $this->scheme ) {
            $uri .= $this->scheme.':';
        }

        $authority = $this->getAuthority();

        if ( null !== $authority || $this->scheme === 'file' ) {
            $uri .= '//'.$authority;
        }

        $uri .= $this->path;

        if ( null !== $this->query ) {
            $uri .= '?'.$this->query;
        }

        if ( null !== $this->fragment ) {
            $uri .= '#'.$this->fragment;
        }

        return $uri;
    }
588058
protected function filterPort($port)
    {
        if (is_null($port) || (is_integer($port) && ($port >= 1 && $port <= 65535))) {
            return $port;
        }

        throw new InvalidArgumentException('Uri port must be null or an integer between 1 and 65535 (inclusive)');
    }
213805
public function getDefaultPort()
    {
        if (!$this->hasDefaultPort()) throw new UrlException(sprintf(
            "No default port for URL '%s'",
            $this->_inputString
        ));

        $scheme = $this->getScheme();
        if ($scheme == 'http') return 80;
        elseif ($scheme == 'https') return 443;
        else throw new UrlException("No default port for scheme '$scheme'");
    }
910721
public function isDefaultPort(int $port = null)
	{
		$port = $port ?: $this->port;
		return $port === null || $port === (self::$allowedSchemes[$this->_scheme] ?? null);
	}
1163554
public function getHostAndPort(): string
    {
        if ($this->myPort !== $this->myScheme->getDefaultPort()) {
            return $this->myHost . ':' . $this->myPort;
        }

        return $this->myHost->__toString();
    }
589990
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'])) {
            list($host, $port) = self::extractHostAndPortFromAuthority($_SERVER['HTTP_HOST']);
            if ($host !== null) {
                $uri = $uri->withHost($host);
            }

            if ($port !== null) {
                $hasPort = true;
                $uri = $uri->withPort($port);
            }
        } 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'], 2);
            $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;
    }
183714
protected static function normalizePort(?int $port, ?string $scheme): ?int
    {
        if ($port === null) {
            return null;
        }

        if ($scheme && isset(static::$defaultPorts[$scheme]) && ($port == static::$defaultPorts[$scheme])) {
            return null;
        }

        return $port;
    }
80931
private function getNormalizedDefaultPort(): string {
        if ($this->port === 0) {
            return "";
        }

        if (isset($this->defaultPortMap[$this->scheme])) {
            $defaultPort = $this->defaultPortMap[$this->scheme];

            if ($defaultPort === $this->port) {
                return "";
            }
        }

        return ":" . $this->port;
    }
344973
public function port(int $defaultPort = null): int
    {

        if ($this->isHttp()) {
            return parent::port(Http::PORT);
        }

        return parent::port(Http::PORT_SSL);
    }
769964
protected function get_current_url()
    {
        // When running from commandline the REQUEST_URI is missing.
        if (!isset($_SERVER['REQUEST_URI'])) {
            return null;
        }

        // HTTP_HOST is a client-supplied header that is optional in HTTP 1.0
        $host = (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']
            : (!empty($_SERVER['LOCAL_ADDR'])  ? $_SERVER['LOCAL_ADDR']
            : (!empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '')));

        $httpS = $this->isHttps() ? 's' : '';
        return "http{$httpS}://{$host}{$_SERVER['REQUEST_URI']}";
    }