Graby\SiteConfig\ConfigBuilder::loadSiteConfig PHP Method

loadSiteConfig() public method

by default if host is 'test.example.org' we will look for and load '.example.org.txt' if it exists.
public loadSiteConfig ( string $host, boolean $exactHostMatch = false ) : false | SiteConfig
$host string Host, like en.wikipedia.org
$exactHostMatch boolean if true, we will not look for wildcard config matches
return false | SiteConfig
    public function loadSiteConfig($host, $exactHostMatch = false)
    {
        $host = strtolower($host);
        if (substr($host, 0, 4) == 'www.') {
            $host = substr($host, 4);
        }
        if (!$host || strlen($host) > 200 || !preg_match($this->config['hostname_regex'], ltrim($host, '.'))) {
            return false;
        }
        $try = array($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->log('debug', '. looking for site config for {host} in primary folder', array('host' => $host));
        foreach ($try as $host) {
            if ($cachedConfig = $this->getCachedVersion($host)) {
                $this->logger->log('debug', '... site config for {host} already loaded in this request', array('host' => $host));
                return $cachedConfig;
            }
            // if we found site config, process it
            if (isset($this->configFiles[$host . '.txt'])) {
                $this->logger->log('debug', '... found site config {host}', array('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->log('debug', 'Appending site config settings from global.txt');
            $configGlobal = $this->loadSiteConfig('global', true);
            if (false !== $configGlobal) {
                $config = $this->mergeConfig($config, $configGlobal);
            }
        }
        return $config;
    }