/[cvs]/nfo/php/libs/org.netfrag.glib/DesignPattern/Bridge.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/DesignPattern/Bridge.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by joko, Mon Feb 3 14:46:57 2003 UTC revision 1.4 by joko, Sun Feb 9 17:07:53 2003 UTC
# Line 3  Line 3 
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  //  Revision 1.3  2003/02/03 14:46:57  joko
11  //  + wrapped calls to available initializers (constructors, declared startup methods)  //  + wrapped calls to available initializers (constructors, declared startup methods)
12  //  - moved logger-code to DesignPattern::Logger  //  - moved logger-code to DesignPattern::Logger
# Line 33  class DesignPattern_Bridge extends Desig Line 37  class DesignPattern_Bridge extends Desig
37    
38    function &_mkInstance($classname, $attributes = null) {    function &_mkInstance($classname, $attributes = null) {
39      parent::constructor();      parent::constructor();
40      $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG );      $this->log( get_class($this) . "->_mkInstance( classname $classname )" );
41      if (isset($attributes)) {      if (isset($attributes)) {
42        $instance = new $classname($attributes);  //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 {      } else {
85        $instance = new $classname;        $instance = new $classname;
86      }      }
87      //$this->log("ok", LOG_DEBUG);      //$this->log("ok");
88      return $instance;      return $instance;
89    }    }
90    
91    function _mkEmbeddedObjects($args) {    function _mkEmbeddedObjects($args) {
92    
93      $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 );
94      //$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) . "::'" );
95    
96    //print Dumper($args);
97    
98      foreach ($args[class_names] as $classname) {      foreach ($args[class_names] as $classname) {
99                
# Line 85  class DesignPattern_Bridge extends Desig Line 132  class DesignPattern_Bridge extends Desig
132    
133    function _call_initializer($objectname, $method) {    function _call_initializer($objectname, $method) {
134      if (method_exists($this->$objectname, $method)) {      if (method_exists($this->$objectname, $method)) {
135        $this->log( get_class($this) . "->_call_initializer: autocalling \$this->" . $objectname . "->$method()", LOG_DEBUG );        $this->log( get_class($this) . "->_call_initializer: autocalling \$this->" . $objectname . "->$method()" );
136        $this->$objectname->$method();        $this->$objectname->$method();
137      }      }
138    }    }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed