public function getHost() : string
    {
        $host = null;

        if ($this->isUsingTrustedProxy() && $this->headers->has(self::$trustedHeaderNames[RequestHeaders::CLIENT_HOST])) {
            $hosts = explode(',', $this->headers->get(self::$trustedHeaderNames[RequestHeaders::CLIENT_HOST]));
            $host = trim(end($hosts));
        }

        if ($host === null) {
            $host = $this->headers->get('HOST');
        }

        if ($host === null) {
            $host = $this->server->get('SERVER_NAME');
        }

        if ($host === null) {
            // Return an empty string by default so we can do string operations on it later
            $host = $this->server->get('SERVER_ADDR', '');
        }

        // Remove the port number
        $host = strtolower(preg_replace("/:\d+$/", '', trim($host)));

        // Check for forbidden characters
        // Credit: Symfony HTTPFoundation
        if (!empty($host) && !empty(preg_replace("/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/", '', $host))) {
            throw new InvalidArgumentException("Invalid host \"$host\"");
        }

        return $host;
    }
public function getHost() : string
    {
        $host = null;

        if ($this->isUsingTrustedProxy() && $this->headers->has(self::$trustedHeaderNames[RequestHeaders::CLIENT_HOST])) {
            $hosts = explode(',', $this->headers->get(self::$trustedHeaderNames[RequestHeaders::CLIENT_HOST]));
            $host = trim(end($hosts));
        }

        if ($host === null) {
            $host = $this->headers->get('HOST');
        }

        if ($host === null) {
            $host = $this->server->get('SERVER_NAME');
        }

        if ($host === null) {
            // Return an empty string by default so we can do string operations on it later
            $host = $this->server->get('SERVER_ADDR', '');
        }

        // Remove the port number
        $host = strtolower(preg_replace("/:\d+$/", '', trim($host)));

        // Check for forbidden characters
        // Credit: Symfony HTTPFoundation
        if (!empty($host) && !empty(preg_replace("/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/", '', $host))) {
            throw new InvalidArgumentException("Invalid host \"$host\"");
        }

        return $host;
    }
public function getHost ( ) : string { $ host = null ; if ( $ this -> isUsingTrustedProxy ( ) && $ this -> headers -> has ( self :: $ trustedHeaderNames [ RequestHeaders :: CLIENT_HOST ] ) ) { $ hosts = explode ( ',' , $ this -> headers -> get ( self :: $ trustedHeaderNames [ RequestHeaders :: CLIENT_HOST ] ) ) ; $ host = trim ( end ( $ hosts ) ) ; } if ( $ host === null ) { $ host = $ this -> headers -> get ( 'HOST' ) ; } if ( $ host === null ) { $ host = $ this -> server -> get ( 'SERVER_NAME' ) ; } if ( $ host === null ) { // Return an empty string by default so we can do string operations on it later $ host = $ this -> server -> get ( 'SERVER_ADDR' , '' ) ; } // Remove the port number $ host = strtolower ( preg_replace ( "/:\d+$/" , '' , trim ( $ host ) ) ) ; // Check for forbidden characters // Credit: Symfony HTTPFoundation if ( ! empty ( $ host ) && ! empty ( preg_replace ( "/(?:^\[)?[a-zA-Z0-9-:\]_]+\.?/" , '' , $ host ) ) ) { throw new InvalidArgumentException ( "Invalid host \"$host\"" ) ; } return $ host ; }
Gets the host name

@return string The host
@throws InvalidArgumentException Thrown if the host was invalid
Gets the host name