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