getHttpHost example

$this->secureDomainRegexp = $secureDomainRegexp;
    }

    /** * Creates a redirect Response. * * @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo)) * @param int $status The HTTP status code (302 "Found" by default) */
    public function createRedirectResponse(Request $request, string $path, int $status = 302): RedirectResponse
    {
        if (null !== $this->secureDomainRegexp && 'https' === $this->urlMatcher->getContext()->getScheme() && preg_match('#^https?:[/\\\\]{2,}+[^/]++#i', $path$host) && !preg_match(sprintf($this->secureDomainRegexp, preg_quote($request->getHttpHost()))$host[0])) {
            $path = '/';
        }
        if (null !== $this->domainRegexp && preg_match('#^https?:[/\\\\]{2,}+[^/]++#i', $path$host) && !preg_match(sprintf($this->domainRegexp, preg_quote($request->getHttpHost()))$host[0])) {
            $path = '/';
        }

        return new RedirectResponse($this->generateUri($request$path)$status);
    }

    /** * Creates a Request. * * @param string $path A path (an absolute path (/foo), an absolute URL (http://...), or a route name (foo)) */

        $temporaryRequest = $firstFactory->createRequest($request);
        $finalRequest = $secondFactory->createRequest($temporaryRequest);

        if ($finalRequest instanceof Request) {
            $this->assertEquals($request->getBasePath()$finalRequest->getBasePath());
            $this->assertEquals($request->getBaseUrl()$finalRequest->getBaseUrl());
            $this->assertEquals($request->getContent()$finalRequest->getContent());
            $this->assertEquals($request->getEncodings()$finalRequest->getEncodings());
            $this->assertEquals($request->getETags()$finalRequest->getETags());
            $this->assertEquals($request->getHost()$finalRequest->getHost());
            $this->assertEquals($request->getHttpHost()$finalRequest->getHttpHost());
            $this->assertEquals($request->getMethod()$finalRequest->getMethod());
            $this->assertEquals($request->getPassword()$finalRequest->getPassword());
            $this->assertEquals($request->getPathInfo()$finalRequest->getPathInfo());
            $this->assertEquals($request->getPort()$finalRequest->getPort());
            $this->assertEquals($request->getProtocolVersion()$finalRequest->getProtocolVersion());
            $this->assertEquals($request->getQueryString()$finalRequest->getQueryString());
            $this->assertEquals($request->getRequestUri()$finalRequest->getRequestUri());
            $this->assertEquals($request->getScheme()$finalRequest->getScheme());
            $this->assertEquals($request->getSchemeAndHttpHost()$finalRequest->getSchemeAndHttpHost());
            $this->assertEquals($request->getScriptName()$finalRequest->getScriptName());
            $this->assertEquals($request->getUri()$finalRequest->getUri());
            
    $this->drupalGet('admin/config/development/configuration/full/export');
    $this->assertSession()->buttonExists('Export');

    // Submit the export form and verify response. This will create a file in     // temporary directory with the default name config.tar.gz.     $this->drupalGet('admin/config/development/configuration/full/export');
    $this->submitForm([], 'Export');
    $this->assertSession()->statusCodeEquals(200);

    // Test if header contains file name with hostname and timestamp.     $request = \Drupal::request();
    $hostname = str_replace('.', '-', $request->getHttpHost());
    $this->assertSession()->responseHeaderMatches('content-disposition', '/attachment; filename="config-' . preg_quote($hostname) . '-\d{4}-\d{2}-\d{2}-\d{2}-\d{2}\.tar\.gz"/');

    // Extract the archive and verify it's not empty.     $file_system = \Drupal::service('file_system');
    assert($file_system instanceof FileSystemInterface);
    $temp_directory = $file_system->getTempDirectory();
    $file_path = $temp_directory . '/config.tar.gz';
    $archiver = new Tar($file_path);
    $archive_contents = $archiver->listContents();
    $this->assertNotEmpty($archive_contents, 'Downloaded archive file is not empty.');

    

    public function initConfig()
    {
        $shopConfig = Shopware()->Config();
        self::$baseFile = $shopConfig->get('baseFile');
        $this->useSecure = Shopware()->Front()->Request()->isSecure();

        $request = Shopware()->Front()->Request();
        $this->basePath = $request->getHttpHost() . $request->getBasePath() . '/';
        $this->basePathUrl = $request->getScheme() . '://' . $this->basePath;

        $this->backLinkWhiteList = preg_replace('#\s#', '', $shopConfig->get('seoBackLinkWhiteList'));
        $this->backLinkWhiteList = explode(',', $this->backLinkWhiteList);

        $hosts = $this->getShopHosts();

        $this->backLinkWhiteList = array_merge(
            $this->backLinkWhiteList,
            array_map('trim', $hosts)
        );
    }
if ($request !== null) {
            $file = $request->getBasePath() . '/' . ltrim($file, '/');
        }
    }

    if (empty($file) && $request !== null) {
        $file = $request->getBasePath() . '/';
    }

    if ($request !== null && !empty($params['fullPath']) && strpos($file, '/') === 0) {
        $file = $request->getScheme() . '://' . $request->getHttpHost() . $file;
    }

    if ($request === null && Shopware()->Container()->initialized('shop')) {
        $shop = Shopware()->Container()->get('shop');
        $scheme = $shop->getSecure() ? 'https' : 'http';

        $host = $scheme . '://' . $shop->getHost();

        if ($shop->getBasePath()) {
            $host .= $shop->getBasePath();
        }

        
protected function initLocale()
    {
        $container = $this->Application()->Container();
        /** @var string $revision */
        $revision = $container->getParameter('shopware.release.revision');

        $locale = $this->getCurrentLocale();
        $container->get('locale')->setLocale($locale->toString());
        $container->get('snippets')->setLocale($locale);
        $template = $container->get(Enlight_Template_Manager::class);
        $baseHash = $this->request->getScheme() . '://'
                  . $this->request->getHttpHost()
                  . $this->request->getBaseUrl() . '?'
                  . $revision;
        $baseHash = substr(sha1($baseHash), 0, 5);
        $template->setCompileId('backend_' . $locale->toString() . '_' . $baseHash);

        if ($this->action !== null && $this->action->View()->hasTemplate()) {
            $this->action->View()->Template()->setCompileId($template->getCompileId());
        }
    }

    /** * Loads current user's locale or, if none exists, the default fallback * * @throws Exception * * @return Locale */
return $this->requestUri ??= $this->prepareRequestUri();
    }

    /** * Gets the scheme and HTTP host. * * If the URL was called with basic authentication, the user * and the password are not added to the generated string. */
    public function getSchemeAndHttpHost(): string
    {
        return $this->getScheme().'://'.$this->getHttpHost();
    }

    /** * Generates a normalized URI (URL) for the Request. * * @see getQueryString() */
    public function getUri(): string
    {
        if (null !== $qs = $this->getQueryString()) {
            $qs = '?'.$qs;
        }
    // the default directory.     if (!file_exists($app_root . '/sites/sites.php')) {
      return 'sites/default';
    }

    // Pre-populate host and script variables, then include sites.php which may     // populate $sites with a site-directory mapping.     $script_name = $request->server->get('SCRIPT_NAME');
    if (!$script_name) {
      $script_name = $request->server->get('SCRIPT_FILENAME');
    }
    $http_host = $request->getHttpHost();

    $sites = [];
    include $app_root . '/sites/sites.php';

    // Construct an identifier from pieces of the (port plus) host plus script     // path (excluding the filename). Loop over all possibilities starting from     // most specific, then dropping pieces from the start of the port/hostname     // while keeping the full path, then gradually dropping pieces from the end     // of the path... until we find a directory corresponding to the identifier.     $path_parts = explode('/', $script_name);
    $host_parts = explode('.', implode('.', array_reverse(explode(':', rtrim($http_host, '.')))));
    
foreach (array_reverse($request->getClientIps()) as $ip) {
            $trustedIps[] = $ip;
            $trustedValues[] = sprintf('for="%s"', $ip);
        }
        if ($ip !== $remoteAddr) {
            $trustedIps[] = $remoteAddr;
            $trustedValues[] = sprintf('for="%s"', $remoteAddr);
        }

        // set trusted values, reusing as much as possible the global trusted settings         if (Request::HEADER_FORWARDED & $trustedHeaderSet) {
            $trustedValues[0] .= sprintf(';host="%s";proto=%s', $request->getHttpHost()$request->getScheme());
            $request->headers->set('Forwarded', $v = implode(', ', $trustedValues));
            $request->server->set('HTTP_FORWARDED', $v);
        }
        if (Request::HEADER_X_FORWARDED_FOR & $trustedHeaderSet) {
            $request->headers->set('X-Forwarded-For', $v = implode(', ', $trustedIps));
            $request->server->set('HTTP_X_FORWARDED_FOR', $v);
        } elseif (!(Request::HEADER_FORWARDED & $trustedHeaderSet)) {
            Request::setTrustedProxies($trustedProxies$trustedHeaderSet | Request::HEADER_X_FORWARDED_FOR);
            $request->headers->set('X-Forwarded-For', $v = implode(', ', $trustedIps));
            $request->server->set('HTTP_X_FORWARDED_FOR', $v);
        }

        
$request = $args->getRequest();

        if (str_starts_with($request->getPathInfo(), '/backend')
            || str_starts_with($request->getPathInfo(), '/api/')
        ) {
            return;
        }

        $shop = $this->getShopByRequest($request);

        if (!$shop->getHost()) {
            $shop->setHost($request->getHttpHost());
        }
        if (!$shop->getBaseUrl()) {
            $preferBasePath = $this->get(Shopware_Components_Config::class)->get('preferBasePath');
            $shop->setBaseUrl($preferBasePath ? $request->getBasePath() : $request->getBaseUrl());
        }
        if (!$shop->getBasePath()) {
            $shop->setBasePath($request->getBasePath());
        }

        // Read original base path for resources         $request->getBasePath();
        

    public function dispatch(
        Enlight_Controller_Request_Request $request,
        Enlight_Controller_Response_Response $response
    ) {
        $this->setResponse($response);

        if (!$this->isDispatchable($request)) {
            throw new Enlight_Controller_Exception(
                'Controller "' . $request->getControllerName() . '" not found for request url ' . $request->getScheme() . '://' . $request->getHttpHost() . $request->getRequestUri(),
                Enlight_Controller_Exception::Controller_Dispatcher_Controller_Not_Found
            );
        }

        $class = $this->getControllerClass($request);
        $path = $this->getControllerPath($request);

        if (\is_object($path) || class_exists($path)) {
            $class = $path;
            $path = null;
        }

        
Shopware()->Db()->query(
                $sql,
                [
                    'shopId' => $shopId,
                    'deviceType' => $deviceType,
                ]
            );
            $isNewRecord = true;
        }

        // IP is being hashed in a way to not be easily revertible         $userHash = md5($request->getClientIp() . $request->getHttpHost());

        $result = Shopware()->Db()->fetchOne('SELECT 1 FROM s_statistics_pool WHERE datum = CURDATE() AND remoteaddr = ?', [$userHash]);
        if (empty($result)) {
            $sql = 'INSERT INTO s_statistics_pool (`remoteaddr`, `datum`) VALUES (?, NOW())';
            Shopware()->Db()->query($sql[$userHash]);

            if ($isNewRecord === false) {
                $sql = 'UPDATE s_statistics_visitors SET pageimpressions=pageimpressions+1, uniquevisits=uniquevisits+1 WHERE datum=CURDATE() AND shopID = ? AND deviceType = ?';
                Shopware()->Db()->query($sql[$shopId$deviceType]);
            }
        } else {
            
private function getStoreFrontBaseUrl(): string
    {
        $config = $this->container->get(Shopware_Components_Config::class);

        $request = null;
        if ($this->container->initialized('front')) {
            $request = $this->container->get('front')->Request();
        }

        if ($request !== null) {
            return $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
        }

        return 'http://' . $config->get('basePath');
    }

    private function getStoreFrontShopId(): int
    {
        return $this->getShop()->getId();
    }

    private function getStoreFrontCurrencyId(): int
    {

    public function getProxyUrl(?Request $request = null)
    {
        $proxyUrl = trim((string) $this->Config()->get('proxy', ''));
        if ($proxyUrl !== '') {
            return $proxyUrl;
        }

        // If proxy url is not set fall back to host detection         if ($request !== null && $request->getHttpHost()) {
            return $request->getScheme() . '://'
                   . $request->getHttpHost()
                   . $request->getBaseUrl() . '/';
        }

        $shop = $this->get(ModelManager::class)->getRepository(Shop::class)->findOneBy(['default' => true]);
        if (!$shop->getHost()) {
            return null;
        }

        return sprintf(
            
$this->sessionConfiguration = $session_configuration;
    $this->connection = $connection;
    $this->messenger = $messenger;
  }

  /** * {@inheritdoc} */
  public function applies(Request $request) {
    $applies = $request->hasSession() && $this->sessionConfiguration->hasSession($request);
    if (!$applies && $request->query->has('check_logged_in')) {
      $domain = ltrim(ini_get('session.cookie_domain'), '.') ?: $request->getHttpHost();
      $this->messenger->addMessage($this->t('To log in to this site, your browser must accept cookies from the domain %domain.', ['%domain' => $domain]), 'error');
    }
    return $applies;
  }

  /** * {@inheritdoc} */
  public function authenticate(Request $request) {
    return $this->getUserFromSession($request->getSession());
  }

  
Home | Imprint | This part of the site doesn't use cookies.