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$ |
// $Id$ |
14 |
// --------------------------------------------------------------------------- |
// --------------------------------------------------------------------------- |
15 |
// $Log$ |
// $Log$ |
16 |
|
// Revision 1.6 2003/03/10 22:58:48 joko |
17 |
|
// + fixed metadata for phpDocumentor |
18 |
|
// |
19 |
|
// Revision 1.5 2003/03/05 23:16:47 joko |
20 |
|
// updated docu - phpDocumentor is very strict about its 'blocks'... |
21 |
|
// |
22 |
|
// Revision 1.4 2003/03/03 21:11:01 joko |
23 |
|
// mungled the namespaces |
24 |
|
// |
25 |
|
// Revision 1.3 2003/02/09 17:05:15 joko |
26 |
|
// + minor update related to new log level constants |
27 |
|
// + restructured get-/setter methods |
28 |
|
// |
29 |
// Revision 1.2 2003/02/03 14:42:28 joko |
// Revision 1.2 2003/02/03 14:42:28 joko |
30 |
// + logging (LOG_DEBUG) |
// + added logging |
31 |
// + methods for accessing configuration variables |
// + methods for accessing configuration variables |
32 |
// |
// |
33 |
// Revision 1.1 2003/02/03 05:00:01 joko |
// Revision 1.1 2003/02/03 05:00:01 joko |
36 |
// --------------------------------------------------------------------------- |
// --------------------------------------------------------------------------- |
37 |
|
|
38 |
|
|
39 |
/* |
$appConfig = mkObject('Application::Config', $init); |
|
|
|
|
------------------------------------------------------------ |
|
|
How to use this? |
|
|
------------------------------------------------------------ |
|
40 |
|
|
41 |
require_once("../etc/defaults.php"); |
$app = mkObject('Application::Core', $appConfig); |
42 |
require_once("../etc/includes.php"); |
$app->run(); |
|
|
|
|
$init = |
|
|
array( |
|
|
'machine' => 'grasshopper', |
|
|
'appname' => 'pub', |
|
|
'resources' => array( |
|
|
'machines' => '../etc/machines.php', |
|
|
), |
|
|
'run' => array( |
|
|
'boot' => array( |
|
|
'scripts' => array( '../core/boot/boot.php' ), |
|
|
//'objects' => array(), |
|
|
'methods' => array( 'e_init', 'e_start', 'e_shutdown' ), |
|
|
), |
|
|
), |
|
|
); |
|
|
|
|
|
$appConfig = mkObject('Application::Config', $init); |
|
|
|
|
|
$app = mkObject('Application::Core', $appConfig); |
|
|
$app->run(); |
|
43 |
|
|
|
------------------------------------------------------------ |
|
44 |
|
|
45 |
*/ |
loadModule('Class::Logger'); |
46 |
|
|
47 |
|
|
48 |
class Application_Core extends DesignPattern_Logger { |
/** |
49 |
|
* This is the Application::Core module. |
50 |
|
* |
51 |
|
* How to use this? |
52 |
|
* |
53 |
|
* <code> |
54 |
|
* require_once("../etc/defaults.php"); |
55 |
|
* require_once("../etc/includes.php"); |
56 |
|
* |
57 |
|
* $init = |
58 |
|
* array( |
59 |
|
* 'machine' => 'grasshopper', |
60 |
|
* 'appname' => 'pub', |
61 |
|
* 'resources' => array( |
62 |
|
* 'machines' => '../etc/machines.php', |
63 |
|
* ), |
64 |
|
* 'run' => array( |
65 |
|
* 'boot' => array( |
66 |
|
* 'scripts' => array( '../core/boot/boot.php' ), |
67 |
|
* //'objects' => array(), |
68 |
|
* 'methods' => array( 'e_init', 'e_start', 'e_shutdown' ), |
69 |
|
* ), |
70 |
|
* ), |
71 |
|
* ); |
72 |
|
* </code> |
73 |
|
* |
74 |
|
* |
75 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
76 |
|
* @package org.netfrag.glib |
77 |
|
* @subpackage Application |
78 |
|
* @name Application::Core |
79 |
|
* |
80 |
|
*/ |
81 |
|
class Application_Core extends Class_Logger { |
82 |
|
|
83 |
var $_config; |
var $_config; |
84 |
|
|
91 |
|
|
92 |
parent::constructor(); |
parent::constructor(); |
93 |
|
|
94 |
$this->log(get_class($this) . "->run: begin", LOG_INFO); |
$this->log("-----------------------------------------------------------------", PEAR_LOG_INFO); |
95 |
|
$this->log(get_class($this) . "->run: begin", PEAR_LOG_INFO); |
96 |
|
|
97 |
$cfg = $this->getConfig(); |
$cfg = $this->getConfig(); |
98 |
|
|
115 |
// run procedural functions |
// run procedural functions |
116 |
if (is_array($container[methods])) { |
if (is_array($container[methods])) { |
117 |
foreach ($container[methods] as $method) { |
foreach ($container[methods] as $method) { |
118 |
$this->log(get_class($this) . "->run: calling function in global namespace: '$method'", LOG_DEBUG); |
$this->log(get_class($this) . "->run: calling function in global namespace: '$method'", PEAR_LOG_DEBUG); |
119 |
call_user_func($method); |
call_user_func($method); |
120 |
} |
} |
121 |
} |
} |
122 |
|
|
123 |
} |
} |
124 |
|
|
125 |
$this->log(get_class($this) . "->run: end", LOG_INFO); |
$this->log(get_class($this) . "->run: end", PEAR_LOG_INFO); |
126 |
|
|
127 |
} |
} |
128 |
|
|
129 |
function getConfig($var = null) { |
function getConfig($var = null) { |
130 |
return $this->_config->getPart($var); |
return $this->_config->get($var); |
131 |
} |
} |
132 |
|
|
133 |
function _require_once_isolated($file) { |
function _require_once_isolated($file) { |
134 |
$this->log(get_class($this) . "->_require_once_isolated: $file", LOG_DEBUG); |
$this->log(get_class($this) . "->_require_once_isolated: $file", PEAR_LOG_DEBUG); |
135 |
if (require_once($file)) { |
if (require_once($file)) { |
136 |
return 1; |
return 1; |
137 |
} |
} |
139 |
|
|
140 |
function setConfigVar($var, $val) { |
function setConfigVar($var, $val) { |
141 |
//print "$var=$val<br>"; |
//print "$var=$val<br>"; |
142 |
$this->_config->setVar($var, $val); |
$this->_config->set_absolute($var, $val); |
143 |
} |
} |
144 |
|
|
145 |
function getConfigVar($var) { |
function getConfigVar($var) { |
146 |
return $this->_config->getVar($var); |
return $this->_config->get_absolute($var); |
147 |
} |
} |
148 |
|
|
149 |
} |
} |