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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.6

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