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