| 1 | 
joko | 
1.1 | 
<? | 
| 2 | 
  | 
  | 
// --------------------------------------------------------------------------- | 
| 3 | 
  | 
  | 
//  $Id: Site.php,v 1.5 2002/12/23 11:33:58 jonen Exp $ | 
| 4 | 
  | 
  | 
// --------------------------------------------------------------------------- | 
| 5 | 
  | 
  | 
//  $Log: Site.php,v $ | 
| 6 | 
  | 
  | 
// --------------------------------------------------------------------------- | 
| 7 | 
  | 
  | 
 | 
| 8 | 
  | 
  | 
 | 
| 9 | 
  | 
  | 
class DesignPattern_Bridge extends DesignPattern_Logger { | 
| 10 | 
  | 
  | 
 | 
| 11 | 
  | 
  | 
  function DesignPattern_Bridge($classname) { | 
| 12 | 
  | 
  | 
    return $this->_mkInstance($classname); | 
| 13 | 
  | 
  | 
  } | 
| 14 | 
  | 
  | 
 | 
| 15 | 
  | 
  | 
  function &_mkInstance($classname) { | 
| 16 | 
  | 
  | 
    $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG ); | 
| 17 | 
  | 
  | 
    return new $classname; | 
| 18 | 
  | 
  | 
  } | 
| 19 | 
  | 
  | 
 | 
| 20 | 
  | 
  | 
  function _mkEmbeddedObjects($args) { | 
| 21 | 
  | 
  | 
 | 
| 22 | 
  | 
  | 
    $this->log( get_class($this) . "->_mkEmbeddedObjects()", LOG_DEBUG ); | 
| 23 | 
  | 
  | 
 | 
| 24 | 
  | 
  | 
    foreach ($args[class_names] as $classname) { | 
| 25 | 
  | 
  | 
       | 
| 26 | 
  | 
  | 
      // build objectname from classname | 
| 27 | 
  | 
  | 
      //  - make lowercase | 
| 28 | 
  | 
  | 
      // - strip leading "Xyz_" ('Site_' here) | 
| 29 | 
  | 
  | 
      $objectname = $classname; | 
| 30 | 
  | 
  | 
      $objectname = str_replace('Site_', '', $objectname); | 
| 31 | 
  | 
  | 
      $objectname = strtolower($objectname); | 
| 32 | 
  | 
  | 
 | 
| 33 | 
  | 
  | 
      // create new instance of helper object by classname | 
| 34 | 
  | 
  | 
      $this->$objectname = &$this->_mkInstance($classname); | 
| 35 | 
  | 
  | 
       | 
| 36 | 
  | 
  | 
      // create additional references to helper object with other names if requested | 
| 37 | 
  | 
  | 
      // the intention is (e.g.) to migrate objects over to new reference-names when development progresses and ... | 
| 38 | 
  | 
  | 
      // ... refactoring the object hierarchy is needed, but ... | 
| 39 | 
  | 
  | 
      // ... you wanna provide the old reference names as "fallbacks" for old code using the libs | 
| 40 | 
  | 
  | 
      if (is_array($args[ref_names])) { | 
| 41 | 
  | 
  | 
        foreach ($args[ref_names] as $ref_name) { | 
| 42 | 
  | 
  | 
//print "mkRef: $ref_name<br>"; | 
| 43 | 
  | 
  | 
          $this->$ref_name = &$this->$objectname; | 
| 44 | 
  | 
  | 
        } | 
| 45 | 
  | 
  | 
      } | 
| 46 | 
  | 
  | 
 | 
| 47 | 
  | 
  | 
      // helper gets reference to ourselves as a parent | 
| 48 | 
  | 
  | 
      $this->$objectname->$args[parent_name] = &$this; | 
| 49 | 
  | 
  | 
   | 
| 50 | 
  | 
  | 
      if ( $method = $args[run] ) { | 
| 51 | 
  | 
  | 
        if (method_exists($this->$objectname, $method)) { | 
| 52 | 
  | 
  | 
          $this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG ); | 
| 53 | 
  | 
  | 
          $this->$objectname->$method(); | 
| 54 | 
  | 
  | 
        } | 
| 55 | 
  | 
  | 
      } | 
| 56 | 
  | 
  | 
     | 
| 57 | 
  | 
  | 
    } | 
| 58 | 
  | 
  | 
   | 
| 59 | 
  | 
  | 
  } | 
| 60 | 
  | 
  | 
 | 
| 61 | 
  | 
  | 
  function _init_logger() { | 
| 62 | 
  | 
  | 
    // Log | 
| 63 | 
  | 
  | 
      // valid logging-levels are: | 
| 64 | 
  | 
  | 
      // LOG_EMERG, LOG_ALERT, LOG_CRIT, | 
| 65 | 
  | 
  | 
      // LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. | 
| 66 | 
  | 
  | 
      // The default is LOG_INFO. | 
| 67 | 
  | 
  | 
      $logfile = 'log.txt'; | 
| 68 | 
  | 
  | 
      $logfile = $this->config[path][base] . "core/var/log/logfile.txt"; | 
| 69 | 
  | 
  | 
 | 
| 70 | 
  | 
  | 
      // TODO: maybe include userid here? | 
| 71 | 
  | 
  | 
      //$log_ident = substr(session_id(), 10, 6); | 
| 72 | 
  | 
  | 
      $log_ident = session_id(); | 
| 73 | 
  | 
  | 
      if ($this->config[mode][LOG]) { | 
| 74 | 
  | 
  | 
        $this->logger = &Log::singleton('file', $logfile, $log_ident); | 
| 75 | 
  | 
  | 
        //$site->logger = new Log_file($logfile, $log_ident); | 
| 76 | 
  | 
  | 
      } else { | 
| 77 | 
  | 
  | 
        $this->logger = &Log::singleton('dummy', $logfile, $log_ident); | 
| 78 | 
  | 
  | 
      } | 
| 79 | 
  | 
  | 
      $this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG ); | 
| 80 | 
  | 
  | 
  } | 
| 81 | 
  | 
  | 
   | 
| 82 | 
  | 
  | 
} | 
| 83 | 
  | 
  | 
?> |