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