| 3 |
// $Id$ |
// $Id$ |
| 4 |
// --------------------------------------------------------------------------- |
// --------------------------------------------------------------------------- |
| 5 |
// $Log$ |
// $Log$ |
| 6 |
|
// Revision 1.4 2003/02/09 17:07:53 joko |
| 7 |
|
// + minor update related to new log level constants |
| 8 |
|
// + generic argument merger to show full constructor args |
| 9 |
|
// |
| 10 |
|
// Revision 1.3 2003/02/03 14:46:57 joko |
| 11 |
|
// + wrapped calls to available initializers (constructors, declared startup methods) |
| 12 |
|
// - moved logger-code to DesignPattern::Logger |
| 13 |
|
// |
| 14 |
|
// Revision 1.2 2003/02/03 05:01:27 joko |
| 15 |
|
// + now attributes can get passed in to the constructors |
| 16 |
|
// |
| 17 |
// Revision 1.1 2003/02/03 03:33:48 joko |
// Revision 1.1 2003/02/03 03:33:48 joko |
| 18 |
// + initial commit |
// + initial commit |
| 19 |
// |
// |
| 22 |
|
|
| 23 |
class DesignPattern_Bridge extends DesignPattern_Logger { |
class DesignPattern_Bridge extends DesignPattern_Logger { |
| 24 |
|
|
| 25 |
function DesignPattern_Bridge($classname) { |
function DesignPattern_Bridge($classname, $attributes = null) { |
| 26 |
return $this->_mkInstance($classname); |
//print "init_bridge!<br>"; |
| 27 |
|
//return $this->_mkInstance($classname, $attributes); |
| 28 |
|
//$this->_init_logger("../core/var/log/logfile.txt", 1); |
| 29 |
|
//parent::constructor(); |
| 30 |
|
$this = $this->_mkInstance($classname, $attributes); |
| 31 |
|
//parent::constructor(); |
| 32 |
|
// $this->_init_logger("../core/var/log/logfile.txt", 1); |
| 33 |
|
//print Dumper($this); |
| 34 |
|
//parent::DesignPattern_Logger(); |
| 35 |
|
//return $this; |
| 36 |
} |
} |
| 37 |
|
|
| 38 |
function &_mkInstance($classname) { |
function &_mkInstance($classname, $attributes = null) { |
| 39 |
$this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG ); |
parent::constructor(); |
| 40 |
return new $classname; |
$this->log( get_class($this) . "->_mkInstance( classname $classname )" ); |
| 41 |
|
if (isset($attributes)) { |
| 42 |
|
//print Dumper($attributes); |
| 43 |
|
|
| 44 |
|
/* |
| 45 |
|
// pass single argument 1:1 |
| 46 |
|
if (count($attributes) == 1) { |
| 47 |
|
$attributes_merged = $attributes[0]; |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
// pass hash 1:1 |
| 52 |
|
} elseif (is_hash($attributes)) { |
| 53 |
|
$attributes_merged = $attributes; |
| 54 |
|
|
| 55 |
|
} else { |
| 56 |
|
$attributes_merged = $attributes; |
| 57 |
|
} |
| 58 |
|
*/ |
| 59 |
|
|
| 60 |
|
$args_pass = array(); |
| 61 |
|
for ($i=0; $i<=count($attributes); $i++) { |
| 62 |
|
array_push($args_pass, '$attributes[' . $i . ']'); |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
$arg_string = join(', ', $args_pass); |
| 66 |
|
|
| 67 |
|
/* |
| 68 |
|
// merge entries of numerical indexed arrays together into one hash |
| 69 |
|
} else { |
| 70 |
|
$attributes_merged = array(); |
| 71 |
|
foreach ($attributes as $entry) { |
| 72 |
|
$attributes_merged = array_merge($attributes_merged, $entry); |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
|
*/ |
| 76 |
|
|
| 77 |
|
//print Dumper($attributes_merged); |
| 78 |
|
//print Dumper($attributes); |
| 79 |
|
//$instance = new $classname($attributes_merged); |
| 80 |
|
//$instance = new $classname($attributes[0]); |
| 81 |
|
$evalstr = 'return new $classname(' . $arg_string . ');'; |
| 82 |
|
$instance = eval($evalstr); |
| 83 |
|
//print $evalstr . "<br>"; |
| 84 |
|
} else { |
| 85 |
|
$instance = new $classname; |
| 86 |
|
} |
| 87 |
|
//$this->log("ok"); |
| 88 |
|
return $instance; |
| 89 |
} |
} |
| 90 |
|
|
| 91 |
function _mkEmbeddedObjects($args) { |
function _mkEmbeddedObjects($args) { |
| 92 |
|
|
| 93 |
$this->log( get_class($this) . "->_mkEmbeddedObjects()", LOG_DEBUG ); |
$this->log( get_parent_class($this) . "->_mkEmbeddedObjects( parent='" . $args[parent_name] . "' )", PEAR_LOG_INFO ); |
| 94 |
|
//$this->log( get_parent_class($this) . "->_init_helpers: instantiating helper objects below '" . get_class($this) . "::'" ); |
| 95 |
|
|
| 96 |
|
//print Dumper($args); |
| 97 |
|
|
| 98 |
foreach ($args[class_names] as $classname) { |
foreach ($args[class_names] as $classname) { |
| 99 |
|
|
| 121 |
// helper gets reference to ourselves as a parent |
// helper gets reference to ourselves as a parent |
| 122 |
$this->$objectname->$args[parent_name] = &$this; |
$this->$objectname->$args[parent_name] = &$this; |
| 123 |
|
|
| 124 |
|
$this->_call_initializer($objectname, 'constructor'); |
| 125 |
if ( $method = $args[run] ) { |
if ( $method = $args[run] ) { |
| 126 |
if (method_exists($this->$objectname, $method)) { |
$this->_call_initializer($objectname, $method); |
|
$this->log( get_class($this) . "->_mkEmbeddedObjects: calling method \$this->" . $objectname . "->$method()", LOG_DEBUG ); |
|
|
$this->$objectname->$method(); |
|
|
} |
|
| 127 |
} |
} |
| 128 |
|
|
| 129 |
} |
} |
| 130 |
|
|
| 131 |
} |
} |
| 132 |
|
|
| 133 |
function _init_logger() { |
function _call_initializer($objectname, $method) { |
| 134 |
// Log |
if (method_exists($this->$objectname, $method)) { |
| 135 |
// valid logging-levels are: |
$this->log( get_class($this) . "->_call_initializer: autocalling \$this->" . $objectname . "->$method()" ); |
| 136 |
// LOG_EMERG, LOG_ALERT, LOG_CRIT, |
$this->$objectname->$method(); |
| 137 |
// LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, and LOG_DEBUG. |
} |
|
// The default is LOG_INFO. |
|
|
$logfile = 'log.txt'; |
|
|
$logfile = $this->config[path][base] . "core/var/log/logfile.txt"; |
|
|
|
|
|
// TODO: maybe include userid here? |
|
|
//$log_ident = substr(session_id(), 10, 6); |
|
|
$log_ident = session_id(); |
|
|
if ($this->config[mode][LOG]) { |
|
|
$this->logger = &Log::singleton('file', $logfile, $log_ident); |
|
|
//$site->logger = new Log_file($logfile, $log_ident); |
|
|
} else { |
|
|
$this->logger = &Log::singleton('dummy', $logfile, $log_ident); |
|
|
} |
|
|
$this->log( get_class($this) . "->_init_logger: ready\t\t--------------------", LOG_DEBUG ); |
|
| 138 |
} |
} |
| 139 |
|
|
| 140 |
|
|
| 141 |
} |
} |
| 142 |
?> |
?> |