/[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.4 - (hide annotations)
Thu Dec 19 06:19:31 2002 UTC (21 years, 8 months ago) by joko
Branch: MAIN
Changes since 1.3: +110 -45 lines
+ function _init_database
+ function _init_smarty
+ function _init_lt

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

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