/[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.3 by joko, Tue Dec 3 15:54:54 2002 UTC revision 1.4 by joko, Thu Dec 19 06:19:31 2002 UTC
# Line 3  Line 3 
3  //    $Id$  //    $Id$
4  //    -------------------------------------------------------------------------  //    -------------------------------------------------------------------------
5  //    $Log$  //    $Log$
6    //    Revision 1.4  2002/12/19 06:19:31  joko
7    //    + function _init_database
8    //    + function _init_smarty
9    //    + function _init_lt
10    //
11  //    Revision 1.3  2002/12/03 15:54:54  joko  //    Revision 1.3  2002/12/03 15:54:54  joko
12  //    + minor update  //    + minor update
13  //  //
# Line 21  require_once 'Loader.php'; Line 26  require_once 'Loader.php';
26  require_once 'Handler.php';  require_once 'Handler.php';
27  require_once 'Request.php';  require_once 'Request.php';
28  require_once 'Misc.php';  require_once 'Misc.php';
29    require_once 'Template.php';
30    
31  class Site_Boot {  class Site_Boot {
32    
33    
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    function _init_logger() {    function _init_logger() {
81      // Log      // Log
82        // valid logging-levels are:        // valid logging-levels are:
# Line 48  class Site_Boot { Line 101  class Site_Boot {
101    
102    function _init_helpers() {    function _init_helpers() {
103      $this->log( get_class($this) . "->_init_helpers()", LOG_DEBUG );      $this->log( get_class($this) . "->_init_helpers()", LOG_DEBUG );
104      $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' );
105      $args = array( class_names => $helpers, parent_name => 'site', run => 'start' );      $args = array( class_names => $helpers, parent_name => 'site', run => 'start' );
106      $this->_mkEmbeddedObjects( $args );      $this->_mkEmbeddedObjects( $args );
107    }    }
108    
109    function _init_application() {    function _init_application() {
   
110      $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;  
     */  
   
111      $helpers = array( 'User', 'Session' );      $helpers = array( 'User', 'Session' );
112      $args = array( class_names => $helpers, parent_name => 'site', run => 'start' );      $args = array( class_names => $helpers, parent_name => 'site', run => 'start' );
113      $this->_mkEmbeddedObjects( $args );      $this->_mkEmbeddedObjects( $args );
   
114    }    }
115    
116    function &_mkInstance($classname) {    function _init_smarty() {
117      $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG );      $this->log( get_class($this) . "->_init_smarty()", LOG_DEBUG );
118      return new $classname;  /*
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    
124    function _mkEmbeddedObjects($args) {      // 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    
141      $this->log( get_class($this) . "->_mkEmbeddedObjects()", LOG_DEBUG );    }
142    
143      foreach ($args[class_names] as $classname) {    function _init_lt() {
144              // LocaleText-class for language
145        // build objectname from classname       $this->log( "init_site: LocaleText starting", LOG_DEBUG);
146        //  - make lowercase      
147        // - strip leading "Xyz_" ('Site_' here)       // V1:
148        $objectname = $classname;       //$lt = new LocaleText;
149        $objectname = str_replace('Site_', '', $objectname);       //$site->lt = $lt;
150        $objectname = strtolower($objectname);      
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    
158        // create new instance of helper object by classname    }
       $this->$objectname = &$this->_mkInstance($classname);  
159    
160        // helper gets reference to ourselves as a parent    function _init_database() {
161        $this->$objectname->$args[parent_name] = &$this;      // Database
162            $this->log( "init_site: database connect", LOG_DEBUG);
163        if ( $method = $args[run] ) {        //print "dsn: " . $site->config[dbinfo][dsn] . "<br>";
164          if (method_exists($this->$objectname, $method)) {        $this->db = DB::connect($this->config[dbinfo][dsn], true);
165            $this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG );        if (DB::isError($this->db)) {
166            $this->$objectname->$method();          // TODO
167          }          // (notifyBox!!! (will we get there?)) else:
168            // do a redirect to a completely static "out-of-order-page" ("maintenance.html")
169            // or do a die here?
170            $error_log = $this->db->getMessage();
171            $this->log( "init_site: database ERROR (dsn=" . $this->config[dbinfo][dsn] . "): \"$error_log\"", LOG_EMERG);
172            // TODO: include email-address, too (from config, if available there)
173            gen_badDbError();
174            exit;
175          } else {
176            $this->db->setFetchMode(DB_FETCHMODE_ASSOC);
177            $this->log( "init_site: database ready", LOG_DEBUG);
178        }        }
       
     }  
     
179    }    }
180        
181  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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