/[cvs]/nfo/php/libs/org.netfrag.flib/Site/Boot.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.flib/Site/Boot.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Sun Dec 22 14:20:08 2002 UTC (21 years, 8 months ago) by joko
Branch: MAIN
Changes since 1.5: +7 -1 lines
+ comment

1 <?
2 // -------------------------------------------------------------------------
3 // $Id: Boot.php,v 1.5 2002/12/19 10:26:25 jonen Exp $
4 // -------------------------------------------------------------------------
5 // $Log: Boot.php,v $
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
18 // + debugging
19 //
20 // Revision 1.1 2002/11/12 05:42:30 joko
21 // + initial checkin
22 //
23 // -------------------------------------------------------------------------
24
25
26 require_once 'DebugBox.php';
27 require_once 'ExtHttp.php';
28 require_once 'Loader.php';
29 require_once 'Handler.php';
30 require_once 'Request.php';
31 require_once 'Misc.php';
32 require_once 'Template.php';
33
34 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() {
84 // Log
85 // valid logging-levels are:
86 // LOG_EMERG, LOG_ALERT, LOG_CRIT,
87 // LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG.
88 // The default is LOG_INFO.
89 $logfile = 'log.txt';
90 $logfile = $this->config[path][base] . "core/var/log/logfile.txt";
91
92 // TODO: maybe include userid here?
93 //$log_ident = substr(session_id(), 10, 6);
94 $log_ident = session_id();
95 if ($this->config[mode][LOG]) {
96 $this->logger = &Log::singleton('file', $logfile, $log_ident);
97 //$site->logger = new Log_file($logfile, $log_ident);
98 } else {
99 $this->logger = &Log::singleton('dummy', $logfile, $log_ident);
100 }
101 $this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG );
102 }
103
104
105 function _init_helpers() {
106 $this->log( get_class($this) . "->_init_helpers()", LOG_DEBUG );
107 $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' );
109 $this->_mkEmbeddedObjects( $args );
110 }
111
112 function _init_application() {
113 $this->log( get_class($this) . "->_init_application()", LOG_DEBUG );
114 $helpers = array( 'User', 'Session' );
115 $args = array( class_names => $helpers, parent_name => 'site', run => 'start' );
116 $this->_mkEmbeddedObjects( $args );
117 }
118
119 function _init_smarty() {
120 $this->log( get_class($this) . "->_init_smarty()", LOG_DEBUG );
121 /*
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 // 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 }
145
146 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 // Set locale according to choosed language (needed for date/time functions)
162 // TODO: set this according to user's profile
163 // TODO: make an flib/Application/l10n/Locale.php from this (available by doing e.g. an '$locale_key = $app->l10n->getLocaleKey()')
164 // TODO: don't wire this to the locale-text setting
165 // ---> actually wire the locale-text setting to $app->l10n->getLocaleKey() (the other way round....)
166 $langkey = $this->localetext->getCurrentLanguage();
167 if($langkey == "de") {
168 setlocale (LC_ALL, 'de_DE');
169 }
170 elseif($langkey == "en") {
171 setlocale (LC_ALL, 'en_US');
172 }
173 elseif($langkey == "tr") {
174 setlocale (LC_ALL, 'tr_TR');
175 }
176
177 }
178
179 function _init_database() {
180 // Database
181 $this->log( "init_site: database connect", LOG_DEBUG);
182 //print "dsn: " . $site->config[dbinfo][dsn] . "<br>";
183 $this->db = DB::connect($this->config[dbinfo][dsn], true);
184 if (DB::isError($this->db)) {
185 // TODO
186 // (notifyBox!!! (will we get there?)) else:
187 // do a redirect to a completely static "out-of-order-page" ("maintenance.html")
188 // or do a die here?
189 $error_log = $this->db->getMessage();
190 $this->log( "init_site: database ERROR (dsn=" . $this->config[dbinfo][dsn] . "): \"$error_log\"", LOG_EMERG);
191 // TODO: include email-address, too (from config, if available there)
192 gen_badDbError();
193 exit;
194 } else {
195 $this->db->setFetchMode(DB_FETCHMODE_ASSOC);
196 $this->log( "init_site: database ready", LOG_DEBUG);
197 }
198 }
199
200 }
201 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed