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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Tue Nov 12 05:42:30 2002 UTC revision 1.5 by jonen, Thu Dec 19 10:26:25 2002 UTC
# Line 3  Line 3 
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
18    //    + debugging
19    //
20  //    Revision 1.1  2002/11/12 05:42:30  joko  //    Revision 1.1  2002/11/12 05:42:30  joko
21  //    + initial checkin  //    + initial checkin
22  //  //
# Line 15  require_once 'Loader.php'; Line 29  require_once 'Loader.php';
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:
# Line 42  class Site_Boot { Line 104  class Site_Boot {
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      foreach ($args[class_names] as $classname) {    function _init_lt() {
147              // LocaleText-class for language
148        // build objectname from classname       $this->log( "init_site: LocaleText starting", LOG_DEBUG);
149        //  - make lowercase      
150        // - strip leading "Xyz_" ('Site_' here)       // V1:
151        $objectname = $classname;       //$lt = new LocaleText;
152        $objectname = str_replace('Site_', '', $objectname);       //$site->lt = $lt;
153        $objectname = strtolower($objectname);      
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        // create new instance of helper object by classname      // Set locale according to choosed language (needed for date/time functions)
162        $this->$objectname = &$this->_mkInstance($classname);      // TODO: set this according to user's profile
163        $langkey = $this->localetext->getCurrentLanguage();
164        if($langkey == "de") {
165            setlocale (LC_ALL, 'de_DE');
166        }
167        elseif($langkey == "en") {
168            setlocale (LC_ALL, 'en_US');
169        }
170        elseif($langkey == "tr") {
171            setlocale (LC_ALL, 'tr_TR');
172        }
173    
174        // helper gets reference to ourselves as a parent    }
175        $this->$objectname->$args[parent_name] = &$this;  
176        function _init_database() {
177        if ( $method = $args[run] ) {      // Database
178          if (method_exists($this->$objectname, $method)) {        $this->log( "init_site: database connect", LOG_DEBUG);
179            $this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG );        //print "dsn: " . $site->config[dbinfo][dsn] . "<br>";
180            $this->$objectname->$method();        $this->db = DB::connect($this->config[dbinfo][dsn], true);
181          }        if (DB::isError($this->db)) {
182            // 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  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

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