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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Thu Dec 19 10:26:25 2002 UTC (21 years, 8 months ago) by jonen
Branch: MAIN
Changes since 1.4: +19 -1 lines
+ set_locale on 'lt_init()' according to choosen languange

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

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