1 |
<? |
2 |
/** |
3 |
* This file contains the Application::Core module. |
4 |
* |
5 |
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
* @package org.netfrag.glib |
7 |
* @name Application::Core |
8 |
* |
9 |
*/ |
10 |
|
11 |
|
12 |
// --------------------------------------------------------------------------- |
13 |
// $Id: Core.php,v 1.4 2003/03/03 21:11:01 joko Exp $ |
14 |
// --------------------------------------------------------------------------- |
15 |
// $Log: Core.php,v $ |
16 |
// Revision 1.4 2003/03/03 21:11:01 joko |
17 |
// mungled the namespaces |
18 |
// |
19 |
// Revision 1.3 2003/02/09 17:05:15 joko |
20 |
// + minor update related to new log level constants |
21 |
// + restructured get-/setter methods |
22 |
// |
23 |
// Revision 1.2 2003/02/03 14:42:28 joko |
24 |
// + added logging |
25 |
// + methods for accessing configuration variables |
26 |
// |
27 |
// Revision 1.1 2003/02/03 05:00:01 joko |
28 |
// + initial commit |
29 |
// |
30 |
// --------------------------------------------------------------------------- |
31 |
|
32 |
|
33 |
$appConfig = mkObject('Application::Config', $init); |
34 |
|
35 |
$app = mkObject('Application::Core', $appConfig); |
36 |
$app->run(); |
37 |
|
38 |
|
39 |
loadModule('Class::Logger'); |
40 |
|
41 |
|
42 |
/** |
43 |
* This is the Application::Core module. |
44 |
* |
45 |
* How to use this? |
46 |
* |
47 |
* <code> |
48 |
* require_once("../etc/defaults.php"); |
49 |
* require_once("../etc/includes.php"); |
50 |
* |
51 |
* $init = |
52 |
* array( |
53 |
* 'machine' => 'grasshopper', |
54 |
* 'appname' => 'pub', |
55 |
* 'resources' => array( |
56 |
* 'machines' => '../etc/machines.php', |
57 |
* ), |
58 |
* 'run' => array( |
59 |
* 'boot' => array( |
60 |
* 'scripts' => array( '../core/boot/boot.php' ), |
61 |
* //'objects' => array(), |
62 |
* 'methods' => array( 'e_init', 'e_start', 'e_shutdown' ), |
63 |
* ), |
64 |
* ), |
65 |
* ); |
66 |
* </code> |
67 |
* |
68 |
* |
69 |
* @author Andreas Motl <andreas.motl@ilo.de> |
70 |
* @package org.netfrag.glib |
71 |
* @subpackage Application |
72 |
* @name Application::AbstractBase |
73 |
* |
74 |
*/ |
75 |
class Application_Core extends Class_Logger { |
76 |
|
77 |
var $_config; |
78 |
|
79 |
function Application_Core($initCfgObject = null) { |
80 |
$this->_config = $initCfgObject; |
81 |
} |
82 |
|
83 |
function run() { |
84 |
//print Dumper($this->_config); |
85 |
|
86 |
parent::constructor(); |
87 |
|
88 |
$this->log("-----------------------------------------------------------------", PEAR_LOG_INFO); |
89 |
$this->log(get_class($this) . "->run: begin", PEAR_LOG_INFO); |
90 |
|
91 |
$cfg = $this->getConfig(); |
92 |
|
93 |
//print Dumper($cfg); exit; |
94 |
|
95 |
if (!is_array($cfg[run])) { return; } |
96 |
|
97 |
foreach ($cfg[run] as $key => $container) { |
98 |
|
99 |
//print "key: $key<br>"; |
100 |
|
101 |
// include files |
102 |
if (is_array($container[scripts])) { |
103 |
foreach ($container[scripts] as $script) { |
104 |
$this->_require_once_isolated($script); |
105 |
$this->_config->merge(); |
106 |
} |
107 |
} |
108 |
|
109 |
// run procedural functions |
110 |
if (is_array($container[methods])) { |
111 |
foreach ($container[methods] as $method) { |
112 |
$this->log(get_class($this) . "->run: calling function in global namespace: '$method'", PEAR_LOG_DEBUG); |
113 |
call_user_func($method); |
114 |
} |
115 |
} |
116 |
|
117 |
} |
118 |
|
119 |
$this->log(get_class($this) . "->run: end", PEAR_LOG_INFO); |
120 |
|
121 |
} |
122 |
|
123 |
function getConfig($var = null) { |
124 |
return $this->_config->get($var); |
125 |
} |
126 |
|
127 |
function _require_once_isolated($file) { |
128 |
$this->log(get_class($this) . "->_require_once_isolated: $file", PEAR_LOG_DEBUG); |
129 |
if (require_once($file)) { |
130 |
return 1; |
131 |
} |
132 |
} |
133 |
|
134 |
function setConfigVar($var, $val) { |
135 |
//print "$var=$val<br>"; |
136 |
$this->_config->set_absolute($var, $val); |
137 |
} |
138 |
|
139 |
function getConfigVar($var) { |
140 |
return $this->_config->get_absolute($var); |
141 |
} |
142 |
|
143 |
} |
144 |
|
145 |
?> |