* USA
*/
+class FusionForgeConfig {
+ static protected $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 (self::$instance->settings[$section])
+ || !isset (self::$instance->settings[$section][$var])) {
+ return NULL ;
+ }
+ return self::$instance->settings[$section][$var] ;
+ }
+
+ public function set_value ($section, $var, $value) {
+ if (!isset (self::$instance->settings[$section])) {
+ self::$instance->settings[$section] = array () ;
+ }
+
+ if (!isset (self::$instance->settings[$section][$var])) {
+ self::$instance->settings[$section][$var] = $value ;
+ }
+ }
+
+ function read_config_file ($file) {
+ $sections = parse_ini_file ($file, true) ;
+ foreach ($sections as $section => $options) {
+ if (!isset (self::$instance->settings[$section]))
+ continue ;
+ foreach ($options as $var => $value) {
+ if (!isset (self::$instance->settings[$section][$var]))
+ continue ;
+ self::$instance->settings[$section][$var] = $value ;
+ }
+ }
+ return ;
+ }
+
+ }
+
if (!isset ($fusionforge_config)) {
- $fusionforge_config = array () ;
+ $fusionforge_config = new FusionForgeConfig () ;
}
-function fusionforge_get_config ($section, $var) {
- global $fusionforge_config ;
+function fusionforge_get_config ($var, $section = NULL) {
+ $c = FusionForgeConfig::get_instance () ;
- if (!isset ($fusionforge_config[$section])
- || !isset ($fusionforge_config[$section][$var])) {
- return false ;
+ if ($section == NULL) {
+ $section = 'core' ;
}
-
- return $fusionforge_config[$section][$var] ;
+
+ return $c->get_value ($section, $var) ;
}
-function fusionforge_define_config_item ($section, $var, $default) {
- global $fusionforge_config ;
+function fusionforge_get_config_array () {
+ $c = FusionForgeConfig::get_instance () ;
- if (!isset ($fusionforge_config[$section])) {
- $fusionforge_config[$section] = array () ;
- }
+ $ret = array () ;
- if (!isset ($fusionforge_config[$section][$var])) {
- $fusionforge_config[$section][$var] = $default ;
+ foreach (func_get_args() as $item) {
+ if (! is_array ($item)) {
+ $item = array ($item) ;
+ }
+ $var = $item[0] ;
+ if (isset ($item[1])) {
+ $section = $item[1] ;
+ } else {
+ $section = 'core' ;
+ }
+ $ret[] = $c->get_value ($section, $var) ;
}
+
+ return $ret ;
}
-function fusionforge_read_config_file ($file) {
- global $fusionforge_config ;
+function fusionforge_set_vars_from_config () {
+ $c = FusionForgeConfig::get_instance () ;
+
+ foreach (func_get_args() as $item) {
+ $section = NULL ;
+ if (is_array ($item)) {
+ $var = $item[0] ;
+ $x = $var ;
+ if (isset ($item[1])) {
+ $section = $item[1] ;
+ $x = $section.'__'.$var ;
+ }
+ } else {
+ $var = $item ;
+ $x = $item ;
+ }
- $sections = parse_ini_file ($file, true) ;
- foreach ($sections as $sectname => $options) {
- foreach ($options as $key => $value) {
- $fusionforge_config[$sectname][$key] = $value ;
- }
+ global $$x ;
+ $$x = fusionforge_get_config ($var, $section) ;
}
+}
+
+
+function fusionforge_define_config_item ($var, $section, $default) {
+ $c = FusionForgeConfig::get_instance () ;
+
+ return $c->set_value ($section, $var, $default) ;
+}
+
+function fusionforge_read_config_file ($file) {
+ $c = FusionForgeConfig::get_instance () ;
- return ;
+ return $c->read_config_file ($file) ;
}
// Local Variables: