Pommo_Helper::parseConfig PHP Method

parseConfig() static public method

Grammar of config file is; [key] = "value" or [key] = i am a value If parser comes across a trimmed line not beginning with [, the line will be ignored. this flexible grammar allows for commets and user error (non homogenous syntax)
static public parseConfig ( $file )
    static function parseConfig($file)
    {
        $a = array();
        @($file_content = file($file));
        if (empty($file_content)) {
            //	Pommo::kill('Could not read config file ('.$file.')');
            return false;
        }
        foreach ($file_content as $rawLine) {
            $line = trim($rawLine);
            if (substr($line, 0, 1) == '[') {
                // line should be traded as a key:value pair
                $matches = array();
                preg_match('/^\\[(\\w+)\\]\\s*=\\s*\\"?([^\\"]*)\\"?.*$/i', $line, $matches);
                // check if a key:value was extracted
                if (!empty($matches[2])) {
                    // merge key:value onto return array
                    $a = array_merge($a, array($matches[1] => $matches[2]));
                }
            }
        }
        return $a;
    }

Usage Example

 function rememberBaseURL()
 {
     $config = Pommo_Helper::parseConfig(Pommo::$_workDir . '/maintenance.php');
     return $config['baseURL'];
 }
All Usage Examples Of Pommo_Helper::parseConfig