1 |
joko |
1.1 |
<? |
2 |
|
|
// --------------------------------------------------------------------------- |
3 |
joko |
1.4 |
// $Id: Config.php,v 1.3 2003/02/03 14:41:21 joko Exp $ |
4 |
joko |
1.1 |
// --------------------------------------------------------------------------- |
5 |
joko |
1.2 |
// $Log: Config.php,v $ |
6 |
joko |
1.4 |
// Revision 1.3 2003/02/03 14:41:21 joko |
7 |
|
|
// + get- and set-methods to access configuration variables |
8 |
|
|
// + recursive merging mechanism |
9 |
|
|
// |
10 |
joko |
1.3 |
// Revision 1.2 2003/02/03 04:59:29 joko |
11 |
|
|
// + fixed: constructor can now get passed variable of *any type* |
12 |
|
|
// |
13 |
joko |
1.2 |
// Revision 1.1 2003/02/03 03:51:36 joko |
14 |
|
|
// + initial commit |
15 |
|
|
// |
16 |
joko |
1.1 |
// --------------------------------------------------------------------------- |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
/* |
20 |
|
|
|
21 |
joko |
1.2 |
------------------------------------------------------------ |
22 |
|
|
How to use this? |
23 |
|
|
------------------------------------------------------------ |
24 |
joko |
1.1 |
|
25 |
|
|
require_once("../etc/defaults.php"); |
26 |
|
|
require_once("../etc/includes.php"); |
27 |
|
|
|
28 |
|
|
$appConfig = mkObject('Application::Config'); |
29 |
|
|
print "appConfig:<br/>" . Dumper($appConfig) . "<hr/>"; |
30 |
|
|
|
31 |
joko |
1.2 |
------------------------------------------------------------ |
32 |
|
|
|
33 |
joko |
1.1 |
*/ |
34 |
|
|
|
35 |
joko |
1.3 |
|
36 |
joko |
1.1 |
class Application_Config { |
37 |
joko |
1.2 |
|
38 |
|
|
var $_store; |
39 |
|
|
|
40 |
|
|
function Application_Config($initCfg = null) { |
41 |
|
|
//print "Hello World!<hr/>"; |
42 |
|
|
//print "initCfg:<br/>" . Dumper($initCfg) . "<hr/>"; |
43 |
|
|
$this->_store = $initCfg; |
44 |
joko |
1.1 |
} |
45 |
joko |
1.3 |
|
46 |
|
|
function merge() { |
47 |
|
|
//$this->_store[run] = array_merge($this->_store['default'], $this->_store['init']); |
48 |
joko |
1.4 |
//print Dumper($this); |
49 |
joko |
1.3 |
foreach ($this->_store[_init][configkeys] as $configKey) { |
50 |
|
|
//$this->_store[runtime] = array_merge($this->_store[runtime], $this->_store[$configKey]); |
51 |
|
|
//$this->_store[runtime] = array_merge_recursive($this->_store[runtime], $this->_store[$configKey]); |
52 |
|
|
$this->_store[runtime] = array_join_merge($this->_store[runtime], $this->_store[$configKey]); |
53 |
|
|
} |
54 |
|
|
//print Dumper($this); |
55 |
|
|
} |
56 |
|
|
|
57 |
joko |
1.4 |
function get($var = null) { |
58 |
joko |
1.3 |
//$this->merge(); |
59 |
|
|
if ($var) { |
60 |
joko |
1.4 |
return $this->get_absolute("runtime.$var"); |
61 |
joko |
1.3 |
} else { |
62 |
joko |
1.4 |
return $this->get_absolute("runtime"); |
63 |
joko |
1.3 |
} |
64 |
|
|
} |
65 |
|
|
|
66 |
joko |
1.4 |
function set_absolute($var, $val) { |
67 |
joko |
1.3 |
//$this->_store[runtime][$var] = $val; |
68 |
|
|
//$deep = new Data_Deep($this->_store[runtime]); |
69 |
|
|
$deep = new Data_Deep($this->_store); |
70 |
|
|
$deep->set($var, $val); |
71 |
|
|
} |
72 |
|
|
|
73 |
joko |
1.4 |
function get_absolute($var) { |
74 |
joko |
1.3 |
//$this->_store[runtime][$var] = $val; |
75 |
|
|
//$deep = new Data_Deep($this->_store[runtime]); |
76 |
|
|
$deep = new Data_Deep($this->_store); |
77 |
|
|
return $deep->get($var); |
78 |
|
|
} |
79 |
|
|
|
80 |
joko |
1.1 |
} |
81 |
|
|
|
82 |
|
|
?> |