3 * FusionForge configuration functions
5 * Copyright 2009, Roland Mas
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FusionForge; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 class FusionForgeConfig {
26 static private $instance = NULL ;
29 public function get_instance () {
30 if (self::$instance == NULL) {
31 self::$instance = new FusionForgeConfig () ;
33 return self::$instance ;
36 public function get_value ($section, $var) {
37 if (!isset ($settings[$section])
38 || !isset ($settings[$section][$var])) {
41 return $settings[$section][$var] ;
44 public function set_value ($section, $var, $value) {
45 if (!isset ($settings[$section])) {
46 $settings[$section] = array () ;
49 if (!isset ($settings[$section][$var])) {
50 $settings[$section][$var] = $value ;
54 function fusionforge_read_config_file ($file) {
55 $sections = parse_ini_file ($file, true) ;
56 foreach ($sections as $sectname => $options) {
57 if (!isset ($settings[$section]))
59 foreach ($options as $key => $value) {
60 if (!isset ($settings[$section][$var]))
62 $settings[$sectname][$key] = $value ;
70 if (!isset ($fusionforge_config)) {
71 $fusionforge_config = new FusionForgeConfig () ;
74 function fusionforge_get_config ($var, $section = 'core') {
75 $c = FusionForgeConfig::get_instance () ;
77 return $c->get_value ($section, $var) ;
80 function fusionforge_get_config_array ($arr) {
81 $c = FusionForgeConfig::get_instance () ;
85 foreach ($arr as $item) {
87 if (isset ($arr[1])) {
92 $ret[] = $c->get_value ($section, $var) ;
98 function fusionforge_define_config_item ($var, $section, $default) {
99 $c = FusionForgeConfig::get_instance () ;
101 return $c->set_value ($section, $var, $default) ;
104 function fusionforge_read_config_file ($file) {
105 $c = FusionForgeConfig::get_instance () ;
107 return $c->read_config_file ($file) ;
112 // c-file-style: "bsd"