protected function getCurrentUrl() {
        $isHttps = $this->getServerVar('HTTPS');
        $forwardedProto = $this->getServerVar('HTTP_X_FORWARDED_PROTO');
        if ($isHttps == 'on' || $forwardedProto === 'https') {
            $schema = 'https://';
        } else {
            $schema = 'http://';
        }

        $host = $this->getServerVar('HTTP_HOST');

        if (preg_match('#:(\d+)$#', $host, $match)) {
            $port = ':' . $match[1];
        } else {
            $port = '';
        }
        $urls = parse_url($this->getServerVar('REQUEST_URI'));

        $path = $urls['path'];
        $query = '';

        return $schema . $host . $port . $path . $query;
    }