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