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