Webiny\Component\Http\Request::getCurrentUrl PHP Method

getCurrentUrl() public method

You can get the result in a form of a string or as a url standard object.
public getCurrentUrl ( boolean $asUrlObject = false ) : string | UrlObject
$asUrlObject boolean In which format you want to get the result, url standard object or a string.
return string | Webiny\Component\StdLib\StdObject\UrlObject\UrlObject Current url.
    public function getCurrentUrl($asUrlObject = false)
    {
        if ($this->currentUrl == '') {
            // schema
            $pageURL = 'http';
            if ($this->isRequestSecured()) {
                $pageURL = 'https';
            }
            $pageURL .= "://";
            // port, server name and request uri
            $host = $this->getHostName();
            $port = $this->getConnectionPort();
            if ($port && $port != '80' && $port != '443') {
                $pageURL .= $host . ":" . $port . $this->server()->requestUri();
            } else {
                $pageURL .= $host . $this->server()->requestUri();
            }
            // query
            $query = $this->server()->queryString();
            if ($query && strpos($pageURL, '?') === false) {
                $pageURL .= '?' . $query;
            }
            $this->currentUrl = $pageURL;
        }
        if ($asUrlObject) {
            return $this->url($this->currentUrl);
        } else {
            return $this->currentUrl;
        }
    }