1 |
<? |
2 |
// ------------------------------------------------------------------------- |
3 |
// $Id: Boot.php,v 1.6 2002/12/22 14:20:08 joko Exp $ |
4 |
// ------------------------------------------------------------------------- |
5 |
// $Log: Boot.php,v $ |
6 |
// Revision 1.6 2002/12/22 14:20:08 joko |
7 |
// + comment |
8 |
// |
9 |
// Revision 1.5 2002/12/19 10:26:25 jonen |
10 |
// + set_locale on 'lt_init()' according to choosen languange |
11 |
// |
12 |
// Revision 1.4 2002/12/19 06:19:31 joko |
13 |
// + function _init_database |
14 |
// + function _init_smarty |
15 |
// + function _init_lt |
16 |
// |
17 |
// Revision 1.3 2002/12/03 15:54:54 joko |
18 |
// + minor update |
19 |
// |
20 |
// Revision 1.2 2002/12/01 22:31:11 joko |
21 |
// + debugging |
22 |
// |
23 |
// Revision 1.1 2002/11/12 05:42:30 joko |
24 |
// + initial checkin |
25 |
// |
26 |
// ------------------------------------------------------------------------- |
27 |
|
28 |
|
29 |
require_once 'DebugBox.php'; |
30 |
require_once 'ExtHttp.php'; |
31 |
require_once 'Loader.php'; |
32 |
require_once 'Handler.php'; |
33 |
require_once 'Request.php'; |
34 |
require_once 'Misc.php'; |
35 |
require_once 'Template.php'; |
36 |
|
37 |
class Site_Boot { |
38 |
|
39 |
|
40 |
function &_mkInstance($classname) { |
41 |
$this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG ); |
42 |
return new $classname; |
43 |
} |
44 |
|
45 |
function _mkEmbeddedObjects($args) { |
46 |
|
47 |
$this->log( get_class($this) . "->_mkEmbeddedObjects()", LOG_DEBUG ); |
48 |
|
49 |
foreach ($args[class_names] as $classname) { |
50 |
|
51 |
// build objectname from classname |
52 |
// - make lowercase |
53 |
// - strip leading "Xyz_" ('Site_' here) |
54 |
$objectname = $classname; |
55 |
$objectname = str_replace('Site_', '', $objectname); |
56 |
$objectname = strtolower($objectname); |
57 |
|
58 |
// create new instance of helper object by classname |
59 |
$this->$objectname = &$this->_mkInstance($classname); |
60 |
|
61 |
// create additional references to helper object with other names if requested |
62 |
// the intention is (e.g.) to migrate objects over to new reference-names when development progresses and ... |
63 |
// ... refactoring the object hierarchy is needed, but ... |
64 |
// ... you wanna provide the old reference names as "fallbacks" for old code using the libs |
65 |
if (is_array($args[ref_names])) { |
66 |
foreach ($args[ref_names] as $ref_name) { |
67 |
//print "mkRef: $ref_name<br>"; |
68 |
$this->$ref_name = &$this->$objectname; |
69 |
} |
70 |
} |
71 |
|
72 |
// helper gets reference to ourselves as a parent |
73 |
$this->$objectname->$args[parent_name] = &$this; |
74 |
|
75 |
if ( $method = $args[run] ) { |
76 |
if (method_exists($this->$objectname, $method)) { |
77 |
$this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG ); |
78 |
$this->$objectname->$method(); |
79 |
} |
80 |
} |
81 |
|
82 |
} |
83 |
|
84 |
} |
85 |
|
86 |
function _init_logger() { |
87 |
// Log |
88 |
// valid logging-levels are: |
89 |
// LOG_EMERG, LOG_ALERT, LOG_CRIT, |
90 |
// LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. |
91 |
// The default is LOG_INFO. |
92 |
$logfile = 'log.txt'; |
93 |
$logfile = $this->config[path][base] . "core/var/log/logfile.txt"; |
94 |
|
95 |
// TODO: maybe include userid here? |
96 |
//$log_ident = substr(session_id(), 10, 6); |
97 |
$log_ident = session_id(); |
98 |
if ($this->config[mode][LOG]) { |
99 |
$this->logger = &Log::singleton('file', $logfile, $log_ident); |
100 |
//$site->logger = new Log_file($logfile, $log_ident); |
101 |
} else { |
102 |
$this->logger = &Log::singleton('dummy', $logfile, $log_ident); |
103 |
} |
104 |
$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG ); |
105 |
} |
106 |
|
107 |
|
108 |
function _init_helpers() { |
109 |
$this->log( get_class($this) . "->_init_helpers()", LOG_DEBUG ); |
110 |
$helpers = array( 'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Misc', 'Site_Http', 'Site_Template' ); |
111 |
$args = array( class_names => $helpers, parent_name => 'site', run => 'start' ); |
112 |
$this->_mkEmbeddedObjects( $args ); |
113 |
} |
114 |
|
115 |
function _init_application() { |
116 |
$this->log( get_class($this) . "->_init_application()", LOG_DEBUG ); |
117 |
$helpers = array( 'User', 'Session' ); |
118 |
$args = array( class_names => $helpers, parent_name => 'site', run => 'start' ); |
119 |
$this->_mkEmbeddedObjects( $args ); |
120 |
} |
121 |
|
122 |
function _init_smarty() { |
123 |
$this->log( get_class($this) . "->_init_smarty()", LOG_DEBUG ); |
124 |
/* |
125 |
$helpers = array( 'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Misc', 'Site_Http' ); |
126 |
$args = array( class_names => $helpers, parent_name => 'site', run => 'start' ); |
127 |
$this->_mkEmbeddedObjects( $args ); |
128 |
*/ |
129 |
|
130 |
// smarty (template engine) |
131 |
$smarty = new Smarty; |
132 |
$smarty->template_dir = $this->config[path][templates]; |
133 |
$smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/"; |
134 |
$smarty->config_dir = $this->config[path]["var"] . "smarty/configs/"; |
135 |
$smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/"; |
136 |
$smarty->compile_check = true; |
137 |
//$smarty->caching = false; |
138 |
//$smarty->caching = true; |
139 |
// TODO: inherit global debugging option(s) here? |
140 |
//$smarty->debugging = true; |
141 |
// we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse |
142 |
$smarty->clear_cache(null, "volatile"); |
143 |
//$site->smarty = &$smarty; |
144 |
$this->smarty = &$smarty; |
145 |
//$site->log( "init_site: smarty ready", LOG_DEBUG); |
146 |
|
147 |
} |
148 |
|
149 |
function _init_lt() { |
150 |
// LocaleText-class for language |
151 |
$this->log( "init_site: LocaleText starting", LOG_DEBUG); |
152 |
|
153 |
// V1: |
154 |
//$lt = new LocaleText; |
155 |
//$site->lt = $lt; |
156 |
|
157 |
// V2: |
158 |
//$this->lt = new LocaleText; |
159 |
|
160 |
// V3: |
161 |
$args = array( class_names => array('LocaleText'), ref_names => array('lt'), parent_name => 'site', run => 'start' ); |
162 |
$this->_mkEmbeddedObjects( $args ); |
163 |
|
164 |
// Set locale according to choosed language (needed for date/time functions) |
165 |
// TODO: set this according to user's profile |
166 |
// TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()') |
167 |
// TODO: don't wire this to the locale-text setting |
168 |
// ---> actually wire the locale-text setting to $app->l10n->getLocaleKey() (the other way round....) |
169 |
$langkey = $this->localetext->getCurrentLanguage(); |
170 |
if($langkey == "de") { |
171 |
setlocale (LC_ALL, 'de_DE'); |
172 |
} |
173 |
elseif($langkey == "en") { |
174 |
setlocale (LC_ALL, 'en_US'); |
175 |
} |
176 |
elseif($langkey == "tr") { |
177 |
setlocale (LC_ALL, 'tr_TR'); |
178 |
} |
179 |
|
180 |
} |
181 |
|
182 |
function _init_database() { |
183 |
// Database |
184 |
$this->log( "init_site: database connect", LOG_DEBUG); |
185 |
//print "dsn: " . $site->config[dbinfo][dsn] . "<br>"; |
186 |
$this->db = DB::connect($this->config[dbinfo][dsn], true); |
187 |
if (DB::isError($this->db)) { |
188 |
// TODO |
189 |
// (notifyBox!!! (will we get there?)) else: |
190 |
// do a redirect to a completely static "out-of-order-page" ("maintenance.html") |
191 |
// or do a die here? |
192 |
$error_log = $this->db->getMessage(); |
193 |
$this->log( "init_site: database ERROR (dsn=" . $this->config[dbinfo][dsn] . "): \"$error_log\"", LOG_EMERG); |
194 |
// TODO: include email-address, too (from config, if available there) |
195 |
gen_badDbError(); |
196 |
exit; |
197 |
} else { |
198 |
$this->db->setFetchMode(DB_FETCHMODE_ASSOC); |
199 |
$this->log( "init_site: database ready", LOG_DEBUG); |
200 |
} |
201 |
} |
202 |
|
203 |
} |
204 |
?> |