src/SiteConfig/ConfigBuilder.php
public function loadSiteConfig($host, $exactHostMatch = false)
    {
        $host = strtolower($host);
        if ('www.' === substr($host, 0, 4)) {
            $host = substr($host, 4);
        }

        if (!$host || (\strlen($host) > 200) || !preg_match($this->config['hostname_regex'], ltrim($host, '.'))) {
            return false;
        }

        $try = [$host];
        // should we look for wildcard matches
        // will try to see for a host without the first subdomain (fr.example.org & .example.org)
        // @todo: should we look for all possible subdomain? (fr.m.example.org &.m.example.org & .example.org)
        if (!$exactHostMatch) {
            $split = explode('.', $host);

            if (\count($split) > 1) {
                // remove first subdomain
                array_shift($split);
                $try[] = '.' . implode('.', $split);
            }
        }

        $config = new SiteConfig();

        // look for site config file in primary folder
        $this->logger->info('. looking for site config for {host} in primary folder', ['host' => $host]);
        foreach ($try as $host) {
            if ($cachedConfig = $this->getCachedVersion($host)) {
                $this->logger->info('... site config for {host} already loaded in this request', ['host' => $host]);

                return $cachedConfig;
            }

            // if we found site config, process it
            if (isset($this->configFiles[$host . '.txt'])) {
                $this->logger->info('... found site config {host}', ['host' => $host . '.txt']);

                $configLines = file($this->configFiles[$host . '.txt'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
                // no lines ? we don't found config then
                if (empty($configLines) || !\is_array($configLines)) {
                    return false;
                }

                $config = $this->parseLines($configLines);
                $config->cache_key = $host;
                break;
            }
        }

        // append global config?
        if ('global' !== $host && $config->autodetect_on_failure() && isset($this->configFiles['global.txt'])) {
            $this->logger->info('Appending site config settings from global.txt');

            $configGlobal = $this->loadSiteConfig('global', true);
            if (false !== $configGlobal) {
                $config = $this->mergeConfig($config, $configGlobal);
            }
        }

        return $config;
    }
public function loadSiteConfig($host, $exactHostMatch = false)
    {
        $host = strtolower($host);
        if ('www.' === substr($host, 0, 4)) {
            $host = substr($host, 4);
        }

        if (!$host || (\strlen($host) > 200) || !preg_match($this->config['hostname_regex'], ltrim($host, '.'))) {
            return false;
        }

        $try = [$host];
        // should we look for wildcard matches
        // will try to see for a host without the first subdomain (fr.example.org & .example.org)
        // @todo: should we look for all possible subdomain? (fr.m.example.org &.m.example.org & .example.org)
        if (!$exactHostMatch) {
            $split = explode('.', $host);

            if (\count($split) > 1) {
                // remove first subdomain
                array_shift($split);
                $try[] = '.' . implode('.', $split);
            }
        }

        $config = new SiteConfig();

        // look for site config file in primary folder
        $this->logger->info('. looking for site config for {host} in primary folder', ['host' => $host]);
        foreach ($try as $host) {
            if ($cachedConfig = $this->getCachedVersion($host)) {
                $this->logger->info('... site config for {host} already loaded in this request', ['host' => $host]);

                return $cachedConfig;
            }

            // if we found site config, process it
            if (isset($this->configFiles[$host . '.txt'])) {
                $this->logger->info('... found site config {host}', ['host' => $host . '.txt']);

                $configLines = file($this->configFiles[$host . '.txt'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
                // no lines ? we don't found config then
                if (empty($configLines) || !\is_array($configLines)) {
                    return false;
                }

                $config = $this->parseLines($configLines);
                $config->cache_key = $host;
                break;
            }
        }

        // append global config?
        if ('global' !== $host && $config->autodetect_on_failure() && isset($this->configFiles['global.txt'])) {
            $this->logger->info('Appending site config settings from global.txt');

            $configGlobal = $this->loadSiteConfig('global', true);
            if (false !== $configGlobal) {
                $config = $this->mergeConfig($config, $configGlobal);
            }
        }

        return $config;
    }
public function loadSiteConfig ( $ host , $ exactHostMatch = false ) { $ host = strtolower ( $ host ) ; if ( 'www.' === substr ( $ host , 0 , 4 ) ) { $ host = substr ( $ host , 4 ) ; } if ( ! $ host || ( \ strlen ( $ host ) > 200 ) || ! preg_match ( $ this -> config [ 'hostname_regex' ] , ltrim ( $ host , '.' ) ) ) { return false ; } $ try = [ $ host ] ; // should we look for wildcard matches // will try to see for a host without the first subdomain (fr.example.org & .example.org) // @todo: should we look for all possible subdomain? (fr.m.example.org &.m.example.org & .example.org) if ( ! $ exactHostMatch ) { $ split = explode ( '.' , $ host ) ; if ( \ count ( $ split ) > 1 ) { // remove first subdomain array_shift ( $ split ) ; $ try [ ] = '.' . implode ( '.' , $ split ) ; } } $ config = new SiteConfig ( ) ; // look for site config file in primary folder $ this -> logger -> info ( '. looking for site config for {host} in primary folder' , [ 'host' => $ host ] ) ; foreach ( $ try as $ host ) { if ( $ cachedConfig = $ this -> getCachedVersion ( $ host ) ) { $ this -> logger -> info ( '... site config for {host} already loaded in this request' , [ 'host' => $ host ] ) ; return $ cachedConfig ; } // if we found site config, process it if ( isset ( $ this -> configFiles [ $ host . '.txt' ] ) ) { $ this -> logger -> info ( '... found site config {host}' , [ 'host' => $ host . '.txt' ] ) ; $ configLines = file ( $ this -> configFiles [ $ host . '.txt' ] , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ) ; // no lines ? we don't found config then if ( empty ( $ configLines ) || ! \ is_array ( $ configLines ) ) { return false ; } $ config = $ this -> parseLines ( $ configLines ) ; $ config -> cache_key = $ host ; break ; } } // append global config? if ( 'global' !== $ host && $ config -> autodetect_on_failure ( ) && isset ( $ this -> configFiles [ 'global.txt' ] ) ) { $ this -> logger -> info ( 'Appending site config settings from global.txt' ) ; $ configGlobal = $ this -> loadSiteConfig ( 'global' , true ) ; if ( false !== $ configGlobal ) { $ config = $ this -> mergeConfig ( $ config , $ configGlobal ) ; } } return $ config ; }
Returns SiteConfig instance if an appropriate one is found, false otherwise.
by default if host is 'test.example.org' we will look for and load '.example.org.txt' if it exists.

@param string $host           Host, like en.wikipedia.org
@param bool   $exactHostMatch if true, we will not look for wildcard config matches

@return false|SiteConfig
Returns SiteConfig instance if an appropriate one is found false otherwise . by default if host is test . example . org we will look for and load . example . org . txt if it exists .