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