| 3 | //  $Id$ | //  $Id$ | 
| 4 | // --------------------------------------------------------------------------- | // --------------------------------------------------------------------------- | 
| 5 | //  $Log$ | //  $Log$ | 
| 6 |  | //  Revision 1.5  2003/02/27 18:09:56  joko | 
| 7 |  | //  mungled mechanism to shift in and pass on arguments | 
| 8 |  | // | 
| 9 |  | //  Revision 1.4  2003/02/09 17:07:53  joko | 
| 10 |  | //  + minor update related to new log level constants | 
| 11 |  | //  + generic argument merger to show full constructor args | 
| 12 |  | // | 
| 13 | //  Revision 1.3  2003/02/03 14:46:57  joko | //  Revision 1.3  2003/02/03 14:46:57  joko | 
| 14 | //  + wrapped calls to available initializers (constructors, declared startup methods) | //  + wrapped calls to available initializers (constructors, declared startup methods) | 
| 15 | //  - moved logger-code to DesignPattern::Logger | //  - moved logger-code to DesignPattern::Logger | 
| 25 |  |  | 
| 26 | class DesignPattern_Bridge extends DesignPattern_Logger { | class DesignPattern_Bridge extends DesignPattern_Logger { | 
| 27 |  |  | 
| 28 | function DesignPattern_Bridge($classname, $attributes = null) { | function DesignPattern_Bridge() { | 
| 29 |  |  | 
| 30 |  | $arg_list = func_get_args(); | 
| 31 |  | $classname = array_shift($arg_list); | 
| 32 |  |  | 
| 33 |  | // expand single argument | 
| 34 |  | if (count($arg_list) == 1) { | 
| 35 |  | $arg_list = $arg_list[0]; | 
| 36 |  | } | 
| 37 |  | $attributes = &$arg_list; | 
| 38 |  |  | 
| 39 |  | //print Dumper($attributes); | 
| 40 |  |  | 
| 41 | //print "init_bridge!<br>"; | //print "init_bridge!<br>"; | 
| 42 | //return $this->_mkInstance($classname, $attributes); | //return $this->_mkInstance($classname, $attributes); | 
| 43 | //$this->_init_logger("../core/var/log/logfile.txt", 1); | //$this->_init_logger("../core/var/log/logfile.txt", 1); | 
| 52 |  |  | 
| 53 | function &_mkInstance($classname, $attributes = null) { | function &_mkInstance($classname, $attributes = null) { | 
| 54 | parent::constructor(); | parent::constructor(); | 
| 55 | $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG ); | $this->log( get_class($this) . "->_mkInstance( classname $classname )" ); | 
| 56 | if (isset($attributes)) { | if (isset($attributes)) { | 
| 57 | $instance = new $classname($attributes); | //print Dumper($attributes); | 
| 58 |  |  | 
| 59 |  | /* | 
| 60 |  | // pass single argument 1:1 | 
| 61 |  | if (count($attributes) == 1) { | 
| 62 |  | $attributes_merged = $attributes[0]; | 
| 63 |  |  | 
| 64 |  |  | 
| 65 |  |  | 
| 66 |  | // pass hash 1:1 | 
| 67 |  | } elseif (is_hash($attributes)) { | 
| 68 |  | $attributes_merged = $attributes; | 
| 69 |  |  | 
| 70 |  | } else { | 
| 71 |  | $attributes_merged = $attributes; | 
| 72 |  | } | 
| 73 |  | */ | 
| 74 |  |  | 
| 75 |  | $args_pass = array(); | 
| 76 |  | for ($i=0; $i<=count($attributes); $i++) { | 
| 77 |  | array_push($args_pass, '$attributes[' . $i . ']'); | 
| 78 |  | } | 
| 79 |  |  | 
| 80 |  | $arg_string = join(', ', $args_pass); | 
| 81 |  |  | 
| 82 |  | /* | 
| 83 |  | // merge entries of numerical indexed arrays together into one hash | 
| 84 |  | } else { | 
| 85 |  | $attributes_merged = array(); | 
| 86 |  | foreach ($attributes as $entry) { | 
| 87 |  | $attributes_merged = array_merge($attributes_merged, $entry); | 
| 88 |  | } | 
| 89 |  | } | 
| 90 |  | */ | 
| 91 |  |  | 
| 92 |  | //print Dumper($attributes_merged); | 
| 93 |  | //print Dumper($attributes); | 
| 94 |  | //$instance = new $classname($attributes_merged); | 
| 95 |  | //$instance = new $classname($attributes[0]); | 
| 96 |  | $evalstr = 'return new $classname(' . $arg_string . ');'; | 
| 97 |  | $instance = eval($evalstr); | 
| 98 |  | //print $evalstr . "<br>"; | 
| 99 | } else { | } else { | 
| 100 | $instance = new $classname; | $instance = new $classname; | 
| 101 | } | } | 
| 102 | //$this->log("ok", LOG_DEBUG); | //$this->log("ok"); | 
| 103 | return $instance; | return $instance; | 
| 104 | } | } | 
| 105 |  |  | 
| 106 | function _mkEmbeddedObjects($args) { | function _mkEmbeddedObjects($args) { | 
| 107 |  |  | 
| 108 | $this->log( get_parent_class($this) . "->_mkEmbeddedObjects( parent='" . $args[parent_name] . "' )", LOG_DEBUG ); | $this->log( get_parent_class($this) . "->_mkEmbeddedObjects( parent='" . $args[parent_name] . "' )", PEAR_LOG_INFO ); | 
| 109 | //$this->log( get_parent_class($this) . "->_init_helpers: instantiating helper objects below '" . get_class($this) . "::'", LOG_DEBUG ); | //$this->log( get_parent_class($this) . "->_init_helpers: instantiating helper objects below '" . get_class($this) . "::'" ); | 
| 110 |  |  | 
| 111 |  | //print Dumper($args); | 
| 112 |  |  | 
| 113 | foreach ($args[class_names] as $classname) { | foreach ($args[class_names] as $classname) { | 
| 114 |  |  | 
| 147 |  |  | 
| 148 | function _call_initializer($objectname, $method) { | function _call_initializer($objectname, $method) { | 
| 149 | if (method_exists($this->$objectname, $method)) { | if (method_exists($this->$objectname, $method)) { | 
| 150 | $this->log( get_class($this) . "->_call_initializer: autocalling \$this->" . $objectname . "->$method()", LOG_DEBUG ); | $this->log( get_class($this) . "->_call_initializer: autocalling \$this->" . $objectname . "->$method()" ); | 
| 151 | $this->$objectname->$method(); | $this->$objectname->$method(); | 
| 152 | } | } | 
| 153 | } | } |