DmitryDulepov\Realurl\Utility::getCurrentHost PHP Method

getCurrentHost() public method

Obtains the current host.
public getCurrentHost ( ) : string
return string
    public function getCurrentHost()
    {
        static $cachedHost = null;
        if ($cachedHost === null) {
            $currentHost = (string) GeneralUtility::getIndpEnv('HTTP_HOST');
            // Call user hooks
            if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['getHost'])) {
                foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']['getHost'] as $userFunc) {
                    $hookParams = array('host' => $currentHost);
                    $newHost = GeneralUtility::callUserFunction($userFunc, $hookParams, $this);
                    if (!empty($newHost) && is_string($newHost)) {
                        $currentHost = $newHost;
                    }
                }
            }
            $cachedHost = $currentHost;
        }
        return $cachedHost;
    }

Usage Example

Example #1
0
 /**
  * Sets the root page id from the top level pages.
  *
  * @return bool
  * @throws \Exception
  */
 protected function setRootPageIdFromTopLevelPages()
 {
     /** @noinspection PhpUndefinedMethodInspection */
     $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'pid=0 AND doktype IN (1,2,4) AND deleted=0 AND hidden=0');
     if (count($rows) !== 1) {
         // Cannot be done: too many of them!
         throw new \Exception('RealURL was not able to find the root page id for the domain "' . $this->utility->getCurrentHost() . '"', 1420480982);
     }
     $this->configuration['pagePath']['rootpage_id'] = (int) $rows[0]['uid'];
     return TRUE;
 }