* USA
*/
-if (!isset ($fusionforge_config)) {
- $fusionforge_config = array () ;
-}
+class FusionForgeConfig {
+ static private $instance = NULL ;
+ private $settings ;
+
+ public function get_instance () {
+ if (self::$instance == NULL) {
+ self::$instance = new FusionForgeConfig () ;
+ }
+ return self::$instance ;
+ }
+
+ public function get_value ($section, $var) {
+ if (!isset ($settings[$section])
+ || !isset ($settings[$section][$var])) {
+ return NULL ;
+ }
+ return $settings[$section][$var] ;
+ }
-function get_config ($section, $var) {
- if (!isset ($fusionforge_config[$section])) {
- return false ;
+ public function set_value ($section, $var, $value) {
+ if (!isset ($settings[$section])) {
+ $settings[$section] = array () ;
+ }
+
+ if (!isset ($settings[$section][$var])) {
+ $settings[$section][$var] = $value ;
+ }
}
- if (!isset ($fusionforge_config[$section][$var])) {
- return false ;
+ function fusionforge_read_config_file ($file) {
+ $sections = parse_ini_file ($file, true) ;
+ foreach ($sections as $sectname => $options) {
+ if (!isset ($settings[$section]))
+ continue ;
+ foreach ($options as $key => $value) {
+ if (!isset ($settings[$section][$var]))
+ continue ;
+ $settings[$sectname][$key] = $value ;
+ }
+ }
+ return ;
}
- return $fusionforge_config[$section][$var] ;
+ }
+
+if (!isset ($fusionforge_config)) {
+ $fusionforge_config = new FusionForgeConfig () ;
+}
+
+function fusionforge_get_config ($section, $var) {
+ $c = FusionForgeConfig::get_instance () ;
+
+ return $c->get_value ($section, $var) ;
}
-function read_config_file ($file) {
- // Initial implementation reuses values from local.inc:
- $fusionforge_config['core']['forge_name'] = $GLOBALS['sys_name'] ;
- return ;
-
- // Real implementation should read *.ini files
- /* Pseudo-code:
- $sections = ini_parse ($file) ;
- foreach ($sections as $sectname => $options) {
- foreach ($options as $key => $value) {
- $fusionforge_config[$sectname][$key] = $value ;
- }
- }
- */
+function fusionforge_define_config_item ($section, $var, $default) {
+ $c = FusionForgeConfig::get_instance () ;
+
+ return $c->set_value ($section, $var, $default) ;
+}
+
+function fusionforge_read_config_file ($file) {
+ $c = FusionForgeConfig::get_instance () ;
+
+ return $c->read_config_file ($file) ;
}
// Local Variables: