src/Site/BaseSiteSelector.php
protected function getPreferredSite(array $sites, Request $request)
    {
        if (0 === \count($sites)) {
            return;
        }

        $sitesLocales = array_map(static function (SiteInterface $site) {
            return $site->getLocale();
        }, $sites);

        $language = $request->getPreferredLanguage($sitesLocales);
        $host = $request->getHost();

        foreach ($sites as $site) {
            if (\in_array($site->getHost(), ['localhost', $host], true) && $language === $site->getLocale()) {
                return $site;
            }
        }

        return reset($sites);
    }
protected function getPreferredSite(array $sites, Request $request)
    {
        if (0 === \count($sites)) {
            return;
        }

        $sitesLocales = array_map(static function (SiteInterface $site) {
            return $site->getLocale();
        }, $sites);

        $language = $request->getPreferredLanguage($sitesLocales);
        $host = $request->getHost();

        foreach ($sites as $site) {
            if (\in_array($site->getHost(), ['localhost', $host], true) && $language === $site->getLocale()) {
                return $site;
            }
        }

        return reset($sites);
    }
protected function getPreferredSite ( array $ sites , Request $ request ) { if ( 0 === \ count ( $ sites ) ) { return ; } $ sitesLocales = array_map ( static function ( SiteInterface $ site ) { return $ site -> getLocale ( ) ; } , $ sites ) ; $ language = $ request -> getPreferredLanguage ( $ sitesLocales ) ; $ host = $ request -> getHost ( ) ; foreach ( $ sites as $ site ) { if ( \ in_array ( $ site -> getHost ( ) , [ 'localhost' , $ host ] , true ) && $ language === $ site -> getLocale ( ) ) { return $ site ; } } return reset ( $ sites ) ; }
Gets the preferred site based on the given request.

@param array   $sites   An array of enabled sites
@param Request $request A request instance

@return SiteInterface|null
Gets the preferred site based on the given request .