Rev 228 Rev 229
1 <?php 1 <?php
2   2  
3 /** 3 /**
4 * Config class. 4 * Config class.
5 * 5 *
6 * @author Tamlyn Rhodes <tam at zenology dot co dot uk> 6 * @author Tamlyn Rhodes <tam at zenology dot co dot uk>
7 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License 7 * @license http://opensource.org/licenses/gpl-license.php GNU General Public License
8 * @copyright (c)2003-2005 Tamlyn Rhodes 8 * @copyright (c)2003-2005 Tamlyn Rhodes
9 * @version $Id: config.class.php,v 1.8 2005/11/30 23:02:18 tamlyn Exp $ 9 * @version $Id: config.class.php,v 1.8 2005/11/30 23:02:18 tamlyn Exp $
10 */ 10 */
11   11  
12 /** 12 /**
13 * Reads configuration data from data/singapore.ini and stores the values 13 * Reads configuration data from data/singapore.ini and stores the values
14 * as properties of itself. 14 * as properties of itself.
15 * 15 *
16 * @package singapore 16 * @package singapore
17 * @author Tamlyn Rhodes <tam at zenology dot co dot uk> 17 * @author Tamlyn Rhodes <tam at zenology dot co dot uk>
18 * @copyright (c)2003, 2004 Tamlyn Rhodes 18 * @copyright (c)2003, 2004 Tamlyn Rhodes
19 */ 19 */
20 class sgConfig 20 class sgConfig
21 { 21 {
22   22  
23 /** 23 /**
24 * Implements the Singleton design pattern by always returning a reference 24 * Implements the Singleton design pattern by always returning a reference
25 * to the same sgConfig object. Use instead of 'new'. 25 * to the same sgConfig object. Use instead of 'new'.
26 */ 26 */
27 function &getInstance() 27 function &getInstance()
28 { 28 {
29 static $instance; 29 static $instance;
30 if(!is_object($instance)) 30 if(!is_object($instance))
31 //note that the new config object is NOT assigned by reference as 31 //note that the new config object is NOT assigned by reference as
32 //references are not stored in static variables (don't ask me...) 32 //references are not stored in static variables (don't ask me...)
33 $instance = new sgConfig(); 33 $instance = new sgConfig();
34 return $instance; 34 return $instance;
35 } 35 }
36 36
37 /** 37 /**
38 * Parses an ini file for configuration directives and imports the values 38 * Parses an ini file for configuration directives and imports the values
39 * into the current object overwriting any previous values. 39 * into the current object overwriting any previous values.
40 * @param string relative or absolute path to the ini file to load 40 * @param string relative or absolute path to the ini file to load
41 * @return boolean true on success; false otherwise 41 * @return boolean true on success; false otherwise
42 */ 42 */
43 function loadConfig($configFilePath) 43 function loadConfig($configFilePath)
44 { 44 {
45 if(!file_exists($configFilePath)) return false; 45 if(!file_exists($configFilePath)) return false;
46 46
47 //get values from ini file 47 //get values from ini file
48 $ini_values = parse_ini_file($configFilePath); 48 $ini_values = parse_ini_file($configFilePath);
49   49  
50 //import values into object scope 50 //import values into object scope
51 foreach($ini_values as $key => $value) $this->$key = $value; 51 foreach($ini_values as $key => $value) $this->$key = $value;
52 52
53 return true; 53 return true;
54 } 54 }
55 } 55 }
56   56  
57 ?> 57 ?>