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