| 1 | joko | 1.1 | <? | 
| 2 |  |  | //    ------------------------------------------------------------------------- | 
| 3 | joko | 1.2 | //    $Id: Boot.php,v 1.1 2002/11/12 05:42:30 joko Exp $ | 
| 4 | joko | 1.1 | //    ------------------------------------------------------------------------- | 
| 5 | joko | 1.2 | //    $Log: Boot.php,v $ | 
| 6 |  |  | //    Revision 1.1  2002/11/12 05:42:30  joko | 
| 7 |  |  | //    + initial checkin | 
| 8 |  |  | // | 
| 9 | joko | 1.1 | //    ------------------------------------------------------------------------- | 
| 10 |  |  |  | 
| 11 |  |  |  | 
| 12 |  |  | require_once 'DebugBox.php'; | 
| 13 |  |  | require_once 'ExtHttp.php'; | 
| 14 |  |  | require_once 'Loader.php'; | 
| 15 |  |  | require_once 'Handler.php'; | 
| 16 |  |  | require_once 'Request.php'; | 
| 17 |  |  | require_once 'Misc.php'; | 
| 18 |  |  |  | 
| 19 |  |  | class Site_Boot { | 
| 20 |  |  |  | 
| 21 |  |  | function _init_logger() { | 
| 22 |  |  | // Log | 
| 23 |  |  | // valid logging-levels are: | 
| 24 |  |  | // LOG_EMERG, LOG_ALERT, LOG_CRIT, | 
| 25 |  |  | // LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. | 
| 26 |  |  | // The default is LOG_INFO. | 
| 27 |  |  | $logfile = 'log.txt'; | 
| 28 |  |  | $logfile = $this->config[path][base] . "core/var/log/logfile.txt"; | 
| 29 |  |  |  | 
| 30 |  |  | // TODO: maybe include userid here? | 
| 31 |  |  | //$log_ident = substr(session_id(), 10, 6); | 
| 32 |  |  | $log_ident = session_id(); | 
| 33 |  |  | if ($this->config[mode][LOG]) { | 
| 34 |  |  | $this->logger = &Log::singleton('file', $logfile, $log_ident); | 
| 35 |  |  | //$site->logger = new Log_file($logfile, $log_ident); | 
| 36 |  |  | } else { | 
| 37 |  |  | $this->logger = &Log::singleton('dummy', $logfile, $log_ident); | 
| 38 |  |  | } | 
| 39 |  |  | $this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG ); | 
| 40 |  |  | } | 
| 41 |  |  |  | 
| 42 |  |  |  | 
| 43 |  |  | function _init_helpers() { | 
| 44 |  |  | $this->log( get_class($this) . "->_init_helpers()", LOG_DEBUG ); | 
| 45 |  |  | $helpers = array( 'Site_DebugBox', 'Site_Handler', 'Site_Request', 'Site_Loader', 'Site_Misc', 'Site_Http' ); | 
| 46 |  |  | $args = array( class_names => $helpers, parent_name => 'site', run => 'start' ); | 
| 47 |  |  | $this->_mkEmbeddedObjects( $args ); | 
| 48 |  |  | } | 
| 49 |  |  |  | 
| 50 |  |  | function _init_application() { | 
| 51 |  |  | $this->log( get_class($this) . "->_init_application()", LOG_DEBUG ); | 
| 52 |  |  | /* | 
| 53 |  |  | was: | 
| 54 |  |  | // User | 
| 55 |  |  | // was: | 
| 56 |  |  | //$user = new User; | 
| 57 |  |  | //$this->user = &$user; | 
| 58 |  |  | // is: | 
| 59 |  |  | $this->user = new User; | 
| 60 |  |  | //$site->log( "boot.inc:init_site: user ready", LOG_DEBUG); | 
| 61 |  |  | // Session | 
| 62 |  |  | $this->session = new Session; | 
| 63 |  |  | */ | 
| 64 |  |  |  | 
| 65 |  |  | $helpers = array( 'User', 'Session' ); | 
| 66 |  |  | $args = array( class_names => $helpers, parent_name => 'site', run => 'start' ); | 
| 67 |  |  | $this->_mkEmbeddedObjects( $args ); | 
| 68 |  |  |  | 
| 69 |  |  | } | 
| 70 |  |  |  | 
| 71 |  |  | function &_mkInstance($classname) { | 
| 72 |  |  | $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG ); | 
| 73 |  |  | return new $classname; | 
| 74 |  |  | } | 
| 75 |  |  |  | 
| 76 |  |  | function _mkEmbeddedObjects($args) { | 
| 77 |  |  |  | 
| 78 |  |  | $this->log( get_class($this) . "->_mkEmbeddedObjects()", LOG_DEBUG ); | 
| 79 | joko | 1.2 |  | 
| 80 |  |  | //print Dumper($args); | 
| 81 | joko | 1.1 |  | 
| 82 |  |  | foreach ($args[class_names] as $classname) { | 
| 83 |  |  |  | 
| 84 |  |  | // build objectname from classname | 
| 85 |  |  | //  - make lowercase | 
| 86 |  |  | // - strip leading "Xyz_" ('Site_' here) | 
| 87 |  |  | $objectname = $classname; | 
| 88 |  |  | $objectname = str_replace('Site_', '', $objectname); | 
| 89 |  |  | $objectname = strtolower($objectname); | 
| 90 |  |  |  | 
| 91 |  |  | // create new instance of helper object by classname | 
| 92 |  |  | $this->$objectname = &$this->_mkInstance($classname); | 
| 93 |  |  |  | 
| 94 |  |  | // helper gets reference to ourselves as a parent | 
| 95 |  |  | $this->$objectname->$args[parent_name] = &$this; | 
| 96 |  |  |  | 
| 97 |  |  | if ( $method = $args[run] ) { | 
| 98 |  |  | if (method_exists($this->$objectname, $method)) { | 
| 99 |  |  | $this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG ); | 
| 100 |  |  | $this->$objectname->$method(); | 
| 101 |  |  | } | 
| 102 |  |  | } | 
| 103 |  |  |  | 
| 104 |  |  | } | 
| 105 |  |  |  | 
| 106 |  |  | } | 
| 107 |  |  |  | 
| 108 |  |  | } | 
| 109 |  |  | ?> |