| 1 | joko | 1.1 | <? | 
| 2 |  |  | /** | 
| 3 | joko | 1.5 | * This file contains the DesignPattern::AdapterProxy namespace. | 
| 4 | joko | 1.1 | * | 
| 5 |  |  | * @author Andreas Motl <andreas.motl@ilo.de> | 
| 6 | joko | 1.2 | * @package org.netfrag.glib | 
| 7 | joko | 1.6 | * @name DesignPattern::AdapterProxy | 
| 8 | joko | 1.4 | * @filesource | 
| 9 |  |  | * | 
| 10 |  |  | * <b>Cvs-Log:</b> | 
| 11 | joko | 1.1 | * | 
| 12 | joko | 1.4 | * <pre> | 
| 13 | joko | 1.8 | * $Id: AdapterProxy.php,v 1.7 2003/03/05 17:13:17 joko Exp $ | 
| 14 | joko | 1.2 | * | 
| 15 |  |  | * $Log: AdapterProxy.php,v $ | 
| 16 | joko | 1.8 | * Revision 1.7  2003/03/05 17:13:17  joko | 
| 17 |  |  | * updated docu (phpDocumentor testing....) | 
| 18 |  |  | * | 
| 19 | joko | 1.7 | * Revision 1.6  2003/03/05 17:02:22  joko | 
| 20 |  |  | * updated docu (phpDocumentor testing....) | 
| 21 |  |  | * | 
| 22 | joko | 1.6 | * Revision 1.5  2003/03/05 16:45:58  joko | 
| 23 |  |  | * updated docu (phpDocumentor testing....) | 
| 24 |  |  | * | 
| 25 | joko | 1.5 | * Revision 1.4  2003/03/05 16:32:18  joko | 
| 26 |  |  | * updated docu (phpDocumentor testing....) | 
| 27 |  |  | * | 
| 28 | joko | 1.4 | * Revision 1.3  2003/03/05 16:10:17  joko | 
| 29 |  |  | * updated docu (phpDocumentor testing....) | 
| 30 |  |  | * | 
| 31 | joko | 1.3 | * Revision 1.2  2003/03/05 15:41:03  joko | 
| 32 |  |  | * updated docu (phpDocumentor testing....) | 
| 33 |  |  | * | 
| 34 | joko | 1.2 | * Revision 1.1  2003/03/05 12:07:10  joko | 
| 35 |  |  | * + initial commit | 
| 36 | joko | 1.1 | * | 
| 37 |  |  | * Revision 1.1  2003/03/03 22:11:08  joko | 
| 38 |  |  | * + initial commit | 
| 39 | joko | 1.4 | * </pre> | 
| 40 | joko | 1.1 | * | 
| 41 |  |  | * | 
| 42 |  |  | */ | 
| 43 | joko | 1.6 | // cvs-log | 
| 44 | joko | 1.1 |  | 
| 45 |  |  |  | 
| 46 |  |  | /** | 
| 47 | joko | 1.4 | * Make sure we have the required parent class | 
| 48 |  |  | */ | 
| 49 |  |  | loadModule('DesignPattern::TransparentProxy'); | 
| 50 |  |  |  | 
| 51 |  |  |  | 
| 52 |  |  | /** | 
| 53 | joko | 1.5 | * This tries to combine some DesignPatterns.... | 
| 54 | joko | 1.1 | * | 
| 55 | joko | 1.5 | * It combines features from both the standard Proxy | 
| 56 |  |  | * and the TransparentProxy adding some Adapter features. | 
| 57 | joko | 1.2 | * | 
| 58 | joko | 1.7 | * @name DesignPattern::AdapterProxy | 
| 59 |  |  | * @subpackage DesignPattern | 
| 60 |  |  | * @package org.netfrag.glib | 
| 61 | joko | 1.8 | * | 
| 62 | joko | 1.7 | * @link http://www.gnu.org/licenses/lgpl.txt | 
| 63 | joko | 1.2 | * @license GNU LGPL (GNU Lesser General Public License) | 
| 64 | joko | 1.8 | * | 
| 65 | joko | 1.7 | * @link http://www.netfrag.org/~joko/ | 
| 66 |  |  | * @copyright (c) 2003 - All Rights reserved. | 
| 67 |  |  | * @author Andreas Motl <andreas.motl@ilo.de> | 
| 68 | joko | 1.1 | * | 
| 69 | joko | 1.7 | * @todo Learn TransparentProxy to do procedural calls ... <br> | 
| 70 |  |  | * ... instead of instantiating a component and even less code could be in here<br> | 
| 71 | joko | 1.3 | * benefit: the TransparentProxy would be become even more powerful | 
| 72 |  |  | * eeäähhh, to the master Proxy it goes......!!! This one calls the handler(s)! | 
| 73 |  |  | * | 
| 74 |  |  | */ | 
| 75 | joko | 1.1 | class DesignPattern_AdapterProxy extends DesignPattern_TransparentProxy { | 
| 76 |  |  |  | 
| 77 |  |  | var $_adapter; | 
| 78 |  |  | var $_adapter_module; | 
| 79 |  |  | var $_adapter_options; | 
| 80 |  |  |  | 
| 81 |  |  | function &get_adapter() { | 
| 82 |  |  | return $this->_adapter; | 
| 83 |  |  | } | 
| 84 |  |  |  | 
| 85 |  |  | function &set_adapter(&$adapter) { | 
| 86 |  |  | $this->_adapter = &$adapter; | 
| 87 |  |  | } | 
| 88 |  |  |  | 
| 89 |  |  | // move this code to php::call_func!!! and wrap here!!! | 
| 90 |  |  | function &create_adapter($m, $f, $a, $options = array()) { | 
| 91 |  |  |  | 
| 92 |  |  | // load required module | 
| 93 |  |  | php::loadModule($m); | 
| 94 |  |  |  | 
| 95 |  |  | // V0: call-handler tests | 
| 96 |  |  | //$m::$f(); | 
| 97 |  |  | //$res = call_user_func(array($m, $f)); | 
| 98 |  |  | //call_user_func("$m::$f"); | 
| 99 |  |  | //$m->$f(); | 
| 100 |  |  |  | 
| 101 |  |  | // V1: | 
| 102 |  |  | //$res = call_user_func( array( $m, $f ) ); | 
| 103 |  |  |  | 
| 104 |  |  | // V2: | 
| 105 |  |  | //return call_user_func( array( $m, $f ), $a ); | 
| 106 |  |  |  | 
| 107 |  |  | if ($options[object]) { | 
| 108 |  |  | $m = php::mkInstance($m); | 
| 109 |  |  | } | 
| 110 |  |  |  | 
| 111 |  |  | // V3: | 
| 112 |  |  | $this->set_adapter( call_user_func( array( &$m, $f ), $a ) ); | 
| 113 |  |  | return $this->get_adapter(); | 
| 114 |  |  |  | 
| 115 |  |  | //print Dumper($res); | 
| 116 |  |  | //exit; | 
| 117 |  |  |  | 
| 118 |  |  | // FIXME: use TransparentProxy for this! | 
| 119 |  |  | // V1: | 
| 120 |  |  | //$this = $res; | 
| 121 |  |  | // V2: | 
| 122 |  |  | //$this->make_transparent(); | 
| 123 |  |  |  | 
| 124 |  |  | //return $res; | 
| 125 |  |  |  | 
| 126 |  |  | } | 
| 127 |  |  |  | 
| 128 |  |  | function set_adapter_module($name) { | 
| 129 |  |  | $this->_adapter_module = $name; | 
| 130 |  |  | } | 
| 131 |  |  | function get_adapter_module() { | 
| 132 |  |  | return $this->_adapter_module; | 
| 133 |  |  | } | 
| 134 |  |  | function set_adapter_options(&$options) { | 
| 135 |  |  | $this->_adapter_options = &$options; | 
| 136 |  |  | } | 
| 137 |  |  | function get_adapter_options() { | 
| 138 |  |  | return $this->_adapter_options; | 
| 139 |  |  | } | 
| 140 |  |  |  | 
| 141 |  |  | } | 
| 142 |  |  |  | 
| 143 |  |  | ?> |