/** * @return array - the key/value pairs read from config file */ public static function &getConfig($forceReload = false) { if (self::$config && !$forceReload) { return self::$config; } $filename = self::getConfigFilename(); if ($filename) { if (XRef::verbose()) { echo "Using config {$filename}\n"; } $ini = parse_ini_file($filename, true); if (!$ini) { throw new Exception("Error: can parse ini file '{$filename}'"); } } else { // if no file explicitly specified, and default config doesn't exist, // don't throw error and provide default config values if (XRef::verbose()) { echo "Using default config\n"; } $ini = array(); } $config = array(); foreach ($ini as $sectionName => $section) { foreach ($section as $k => $v) { $config["{$sectionName}.{$k}"] = $v; } } // default config values are for command-line xref tool only; // you have to specify a real config for xref-doc, CI and web-based tools $defaultConfig = array('project.exclude-path' => array(), 'xref.storage-manager' => 'XRef_Storage_File', 'xref.project-check' => true, 'doc.parsers' => array('XRef_Parser_PHP'), 'doc.plugins' => array('XRef_Doc_ClassesPHP', 'XRef_Doc_MethodsPHP', 'XRef_Doc_PropertiesPHP', 'XRef_Doc_ConstantsPHP', 'XRef_Doc_SourceFileDisplay', 'XRef_Lint_UninitializedVars', 'XRef_Lint_LowerCaseLiterals', 'XRef_Lint_StaticThis', 'XRef_Lint_ClosingTag', 'XRef_Doc_LintReport'), 'lint.color' => 'auto', 'lint.report-level' => 'warnings', 'lint.parsers' => array('XRef_Parser_PHP'), 'lint.plugins' => array('XRef_Lint_UninitializedVars', 'XRef_Lint_LowerCaseLiterals', 'XRef_Lint_StaticThis', 'XRef_Lint_AssignmentInCondition', 'XRef_Lint_ClosingTag', 'XRef_ProjectLint_CheckClassAccess', 'XRef_ProjectLint_MissedParentConstructor', 'XRef_ProjectLint_FunctionSignature', 'XRef_Doc_SourceFileDisplay'), 'lint.add-constant' => array(), 'lint.add-function-signature' => array(), 'lint.add-global-var' => array(), 'lint.ignore-missing-class' => array('PEAR', 'PHPUnit_Framework_TestCase'), 'lint.ignore-error' => array(), 'lint.check-global-scope' => true, 'ci.source-code-manager' => 'XRef_SourceCodeManager_Git'); foreach ($defaultConfig as $key => $value) { if (!isset($config[$key])) { $config[$key] = $value; } } // override values with -d command-line option if (self::$options && isset(self::$options["define"])) { foreach (self::$options["define"] as $d) { list($k, $v) = explode("=", $d, 2); if ($v) { if ($v == "true" || $v == "on") { $v = true; } elseif ($v == "false" || $v == "off") { $v = false; } } $force_array = false; if (substr($k, strlen($k) - 2) == '[]') { $force_array = true; $k = substr($k, 0, strlen($k) - 2); } if ($force_array || isset($config[$k]) && is_array($config[$k])) { if ($v) { $config[$k][] = $v; } else { $config[$k] = array(); } } else { $config[$k] = $v; } } } self::$config = $config; return self::$config; }