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