Example #1
0
 /**
  * Retrieve current url
  *
  * @return string
  */
 public function getCurrentUrl()
 {
     $port = $this->_request->getServer('SERVER_PORT');
     if ($port) {
         $defaultPorts = [\Magento\Framework\App\Request\Http::DEFAULT_HTTP_PORT, \Magento\Framework\App\Request\Http::DEFAULT_HTTPS_PORT];
         $port = in_array($port, $defaultPorts) ? '' : ':' . $port;
     }
     $requestUri = $this->_request->getServer('REQUEST_URI');
     $url = $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . $port . $requestUri;
     return $url;
 }
Example #2
0
 /**
  * Retrieve current url
  *
  * @return string
  */
 public function getCurrentUrl()
 {
     $httpHostWithPort = $this->_request->getHttpHost(false);
     $httpHostWithPort = explode(':', $httpHostWithPort);
     $httpHost = isset($httpHostWithPort[0]) ? $httpHostWithPort[0] : '';
     $port = '';
     if (isset($httpHostWithPort[1])) {
         $defaultPorts = [\Magento\Framework\App\Request\Http::DEFAULT_HTTP_PORT, \Magento\Framework\App\Request\Http::DEFAULT_HTTPS_PORT];
         if (!in_array($httpHostWithPort[1], $defaultPorts)) {
             /** Custom port */
             $port = ':' . $httpHostWithPort[1];
         }
     }
     return $this->_request->getScheme() . '://' . $httpHost . $port . $this->_request->getRequestUri();
 }
Example #3
0
 /**
  * Compute the request Url from the Http request
  *
  * @param RequestInterface $httpRequest
  * @return string
  */
 public function getRequestUrl($httpRequest)
 {
     return $httpRequest->getScheme() . '://' . $httpRequest->getHttpHost(false) . $httpRequest->getRequestUri();
 }