Jelix\Routing\ClientRequest::getPort PHP Method

getPort() public method

return the server port of the application
Since: 1.2.4
public getPort ( $forceHttps = null ) : string
return string the ":port" or empty string
    function getPort($forceHttps = null)
    {
        $isHttps = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] != 'off';
        if ($forceHttps === null) {
            $https = $isHttps;
        } else {
            $https = $forceHttps;
        }
        $forcePort = $https ? App::config()->forceHTTPSPort : App::config()->forceHTTPPort;
        if ($forcePort === true) {
            return '';
        } else {
            if ($forcePort) {
                // a number
                $port = $forcePort;
            } else {
                if ($isHttps != $https || !isset($_SERVER['SERVER_PORT'])) {
                    // the asked protocol is different from the current protocol
                    // we use the standard port for the asked protocol
                    return '';
                } else {
                    $port = $_SERVER['SERVER_PORT'];
                }
            }
        }
        if ($port === NULL || $port == '' || $https && $port == '443' || !$https && $port == '80') {
            return '';
        }
        return ':' . $port;
    }