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