public function baseURL($path = '')
    {
        if (is_null($this->baseURL)) {
            $self = $_SERVER['PHP_SELF'];
            $server = $_SERVER['HTTP_HOST']
                      . rtrim(str_replace(strstr($self, 'index.php'), '', $self), '/');

            if ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off')
                || !empty($_SERVER['HTTP_X_FORWARDED_PROTO'])
                && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https'
            ) {
                $protocol = 'https://';
            } else {
                $protocol = 'http://';
            }

            $this->baseURL = $protocol . $server;
        }

        $url = $this->baseURL;

        if ($path !== '') {
            $url .= '/' . $path;
        }

        return $url;
    }