--- nfo/php/libs/org.netfrag.flib/Site/Boot.php 2002/11/12 05:42:30 1.1
+++ nfo/php/libs/org.netfrag.flib/Site/Boot.php 2002/12/19 10:26:25 1.5
@@ -1,8 +1,22 @@
// -------------------------------------------------------------------------
-// $Id: Boot.php,v 1.1 2002/11/12 05:42:30 joko Exp $
+// $Id: Boot.php,v 1.5 2002/12/19 10:26:25 jonen Exp $
// -------------------------------------------------------------------------
// $Log: Boot.php,v $
+// Revision 1.5 2002/12/19 10:26:25 jonen
+// + set_locale on 'lt_init()' according to choosen languange
+//
+// Revision 1.4 2002/12/19 06:19:31 joko
+// + function _init_database
+// + function _init_smarty
+// + function _init_lt
+//
+// Revision 1.3 2002/12/03 15:54:54 joko
+// + minor update
+//
+// Revision 1.2 2002/12/01 22:31:11 joko
+// + debugging
+//
// Revision 1.1 2002/11/12 05:42:30 joko
// + initial checkin
//
@@ -15,9 +29,57 @@
require_once 'Handler.php';
require_once 'Request.php';
require_once 'Misc.php';
+require_once 'Template.php';
class Site_Boot {
+
+ function &_mkInstance($classname) {
+ $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG );
+ return new $classname;
+ }
+
+ function _mkEmbeddedObjects($args) {
+
+ $this->log( get_class($this) . "->_mkEmbeddedObjects()", LOG_DEBUG );
+
+ foreach ($args[class_names] as $classname) {
+
+ // build objectname from classname
+ // - make lowercase
+ // - strip leading "Xyz_" ('Site_' here)
+ $objectname = $classname;
+ $objectname = str_replace('Site_', '', $objectname);
+ $objectname = strtolower($objectname);
+
+ // create new instance of helper object by classname
+ $this->$objectname = &$this->_mkInstance($classname);
+
+ // create additional references to helper object with other names if requested
+ // the intention is (e.g.) to migrate objects over to new reference-names when development progresses and ...
+ // ... refactoring the object hierarchy is needed, but ...
+ // ... you wanna provide the old reference names as "fallbacks" for old code using the libs
+ if (is_array($args[ref_names])) {
+ foreach ($args[ref_names] as $ref_name) {
+//print "mkRef: $ref_name
";
+ $this->$ref_name = &$this->$objectname;
+ }
+ }
+
+ // helper gets reference to ourselves as a parent
+ $this->$objectname->$args[parent_name] = &$this;
+
+ if ( $method = $args[run] ) {
+ if (method_exists($this->$objectname, $method)) {
+ $this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG );
+ $this->$objectname->$method();
+ }
+ }
+
+ }
+
+ }
+
function _init_logger() {
// Log
// valid logging-levels are:
@@ -42,65 +104,94 @@
function _init_helpers() {
$this->log( get_class($this) . "->_init_helpers()", LOG_DEBUG );
- $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' );
$args = array( class_names => $helpers, parent_name => 'site', run => 'start' );
$this->_mkEmbeddedObjects( $args );
}
function _init_application() {
$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;
- */
-
$helpers = array( 'User', 'Session' );
$args = array( class_names => $helpers, parent_name => 'site', run => 'start' );
$this->_mkEmbeddedObjects( $args );
-
}
- function &_mkInstance($classname) {
- $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG );
- return new $classname;
- }
+ function _init_smarty() {
+ $this->log( get_class($this) . "->_init_smarty()", LOG_DEBUG );
+/*
+ $helpers = array( 'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Misc', 'Site_Http' );
+ $args = array( class_names => $helpers, parent_name => 'site', run => 'start' );
+ $this->_mkEmbeddedObjects( $args );
+*/
- function _mkEmbeddedObjects($args) {
+ // smarty (template engine)
+ $smarty = new Smarty;
+ $smarty->template_dir = $this->config[path][templates];
+ $smarty->compile_dir = $this->config[path]["var"] . "smarty/templates_c/";
+ $smarty->config_dir = $this->config[path]["var"] . "smarty/configs/";
+ $smarty->cache_dir = $this->config[path]["var"] . "smarty/cache/";
+ $smarty->compile_check = true;
+ //$smarty->caching = false;
+ //$smarty->caching = true;
+ // TODO: inherit global debugging option(s) here?
+ //$smarty->debugging = true;
+ // we declare "volatile" as a special namespace/cache key which is clean on each script-startup/reuse
+ $smarty->clear_cache(null, "volatile");
+ //$site->smarty = &$smarty;
+ $this->smarty = &$smarty;
+ //$site->log( "init_site: smarty ready", LOG_DEBUG);
- $this->log( get_class($this) . "->_mkEmbeddedObjects()", LOG_DEBUG );
+ }
- foreach ($args[class_names] as $classname) {
-
- // build objectname from classname
- // - make lowercase
- // - strip leading "Xyz_" ('Site_' here)
- $objectname = $classname;
- $objectname = str_replace('Site_', '', $objectname);
- $objectname = strtolower($objectname);
+ function _init_lt() {
+ // LocaleText-class for language
+ $this->log( "init_site: LocaleText starting", LOG_DEBUG);
+
+ // V1:
+ //$lt = new LocaleText;
+ //$site->lt = $lt;
+
+ // V2:
+ //$this->lt = new LocaleText;
+
+ // V3:
+ $args = array( class_names => array('LocaleText'), ref_names => array('lt'), parent_name => 'site', run => 'start' );
+ $this->_mkEmbeddedObjects( $args );
- // create new instance of helper object by classname
- $this->$objectname = &$this->_mkInstance($classname);
+ // Set locale according to choosed language (needed for date/time functions)
+ // TODO: set this according to user's profile
+ $langkey = $this->localetext->getCurrentLanguage();
+ if($langkey == "de") {
+ setlocale (LC_ALL, 'de_DE');
+ }
+ elseif($langkey == "en") {
+ setlocale (LC_ALL, 'en_US');
+ }
+ elseif($langkey == "tr") {
+ setlocale (LC_ALL, 'tr_TR');
+ }
- // helper gets reference to ourselves as a parent
- $this->$objectname->$args[parent_name] = &$this;
-
- if ( $method = $args[run] ) {
- if (method_exists($this->$objectname, $method)) {
- $this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG );
- $this->$objectname->$method();
- }
+ }
+
+ function _init_database() {
+ // Database
+ $this->log( "init_site: database connect", LOG_DEBUG);
+ //print "dsn: " . $site->config[dbinfo][dsn] . "
";
+ $this->db = DB::connect($this->config[dbinfo][dsn], true);
+ if (DB::isError($this->db)) {
+ // TODO
+ // (notifyBox!!! (will we get there?)) else:
+ // do a redirect to a completely static "out-of-order-page" ("maintenance.html")
+ // or do a die here?
+ $error_log = $this->db->getMessage();
+ $this->log( "init_site: database ERROR (dsn=" . $this->config[dbinfo][dsn] . "): \"$error_log\"", LOG_EMERG);
+ // TODO: include email-address, too (from config, if available there)
+ gen_badDbError();
+ exit;
+ } else {
+ $this->db->setFetchMode(DB_FETCHMODE_ASSOC);
+ $this->log( "init_site: database ready", LOG_DEBUG);
}
-
- }
-
}
}