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