--- nfo/php/libs/org.netfrag.flib/Site/Boot.php 2002/12/03 15:54:54 1.3 +++ nfo/php/libs/org.netfrag.flib/Site/Boot.php 2002/12/19 06:19:31 1.4 @@ -1,8 +1,13 @@ 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: @@ -48,67 +101,81 @@ 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); + } - // 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); } - - } - } }