/** * A method to read in and parse a plugin configuration file. * * @static * @param string $configFileName The path to the configuration file. * @param boolean $processSections Process section names in the configuration file, and return * as a multidimenstional array. * {@see http://uk.php.net/manual/en/function.parse-ini-file.php}. * @param boolean $raiseErrors If true, raise PEAR errors on failure. * @return mixed An array containing the parsed configuration file, or false on error. */ function getConfigByFileName($configFileName, $processSections = false, $raiseErrors = true) { if (!file_exists($configFileName)) { if ($raiseErrors) { MAX::raiseError("Config file '{$configFileName}' does not exist.", MAX_ERROR_NOFILE); } return false; } $conf = parse_ini_file($configFileName, $processSections); if (isset($conf['realConfig'])) { if (preg_match('#.*\\/(.*)\\.plugin\\.conf\\.php#D', $configFileName, $match = null)) { $configFileName = str_replace($match[1], $conf['realConfig'], $configFileName); return MAX_Plugin::getConfigByFileName($configFileName, $processSections, $raiseErrors); } else { return false; } } if (is_array($conf)) { return $conf; } else { return false; } }
/** * A method to test the getConfigByFileName() method. */ function deprecated_testGetConfigByFileName() { // Set the error handling class' handleErrors() method as // the error handler for PHP for this test. $oTestErrorHandler = new TestErrorHandler(); PEAR::pushErrorHandling(PEAR_ERROR_CALLBACK, array(&$oTestErrorHandler, 'handleErrors')); // Test a config file that does not exist $result = MAX_Plugin::getConfigByFileName('foo'); $this->assertEqual(count($oTestErrorHandler->aErrors), 1); $this->assertEqual($oTestErrorHandler->aErrors[0]->message, "Config file 'foo' does not exist."); $this->assertFalse($result); $oTestErrorHandler->reset(); // Unset the error handler PEAR::popErrorHandling(); // Test a config file that does exist $result = MAX_Plugin::getConfigByFileName(MAX_PATH . '/plugins/geotargeting/default.plugin.conf.php'); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 2); $this->assertEqual($result['type'], 'none'); $this->assertFalse($result['saveStats']); // Test a config file that does exist, with sections $result = MAX_Plugin::getConfigByFileName(MAX_PATH . '/plugins/geotargeting/default.plugin.conf.php', true); $this->assertTrue(is_array($result)); $this->assertEqual(count($result), 1); $this->assertTrue(is_array($result['geotargeting'])); $this->assertEqual(count($result['geotargeting']), 2); $this->assertEqual($result['geotargeting']['type'], 'none'); $this->assertFalse($result['geotargeting']['saveStats']); }