1 |
<?php |
<?php |
|
|
|
2 |
/** |
/** |
3 |
* This file contains the DesignPattern::Proxy class. |
* This file contains the DesignPattern::Proxy class |
4 |
* |
* |
5 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
* @module DesignPattern::Proxy |
* @package org.netfrag.glib |
7 |
|
* @name DesignPattern::Proxy |
8 |
* |
* |
9 |
*/ |
*/ |
10 |
|
|
11 |
/** |
/** |
12 |
|
* Cvs-Log: |
13 |
|
* |
14 |
* $Id$ |
* $Id$ |
15 |
* |
* |
16 |
* $Log$ |
* $Log$ |
17 |
|
* Revision 1.3 2003/03/05 16:10:17 joko |
18 |
|
* updated docu (phpDocumentor testing....) |
19 |
|
* |
20 |
|
* Revision 1.2 2003/03/05 12:12:42 joko |
21 |
|
* re-renamed methods and privates: _handler becomes _proxy again |
22 |
|
* |
23 |
* Revision 1.1 2003/03/03 22:05:25 joko |
* Revision 1.1 2003/03/03 22:05:25 joko |
24 |
* abstract implementation... ;-) |
* abstract implementation... ;-) |
25 |
* |
* |
28 |
|
|
29 |
|
|
30 |
/** |
/** |
31 |
* --- An attempt to implement some software design patterns... |
* An attempt to implement some software design patterns... |
32 |
* --- ProxyPattern |
* --- ProxyPattern |
33 |
* |
* |
34 |
* --- http://c2.com/cgi-bin/wiki?ProxyPattern |
* @link http://c2.com/cgi-bin/wiki?ProxyPattern |
35 |
* |
* |
36 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
37 |
|
* @link http://www.netfrag.org/~joko/ |
38 |
|
* |
39 |
* @copyright (c) 2003 - All Rights reserved. |
* @copyright (c) 2003 - All Rights reserved. |
40 |
* @license GNU LGPL (GNU Lesser General Public License) |
* @license GNU LGPL (GNU Lesser General Public License) |
41 |
* |
* @link http://www.gnu.org/licenses/lgpl.txt |
|
* @author-url http://www.netfrag.org/~joko/ |
|
|
* @license-url http://www.gnu.org/licenses/lgpl.txt |
|
42 |
* |
* |
43 |
* @package org.netfrag.glib |
* @package org.netfrag.glib |
44 |
* @module DesignPattern::Proxy |
* @name DesignPattern::Proxy |
45 |
* |
* |
46 |
*/ |
*/ |
47 |
|
|
48 |
/** |
/** |
49 |
* Todo: |
* @todo |
50 |
* |
* <pre> |
51 |
* x DesignPattern::DecoratorProxy (->decorate) |
* x DesignPattern::DecoratorProxy (->decorate) |
52 |
* x DesignPattern::TransparentProxy (->make_transparent) |
* x DesignPattern::TransparentProxy (->make_transparent) |
53 |
* o DesignPattern::MultiProxy (->both???) (diamond inheritance? possible in php?) |
* o DesignPattern::MultiProxy (->both???) (diamond inheritance? possible in php?) |
54 |
* o DesignPattern::GenericAdapterProxy??? |
* o DesignPattern::GenericAdapterProxy??? |
55 |
* o no 'locator/query' or 'type/component' |
* o no 'locator/query' or 'type/component' |
56 |
* o even more generic: just 'adapter_metadata' (-> global adapter registry?) |
* o even more generic: just 'adapter_metadata' (-> global adapter registry?) |
57 |
|
* </pre> |
|
|
|
|
* |
|
58 |
* |
* |
59 |
*/ |
*/ |
60 |
|
|
71 |
* |
* |
72 |
*/ |
*/ |
73 |
var $_debug = array( |
var $_debug = array( |
74 |
notice => 0, |
notice => 1, |
75 |
trace => 0, |
trace => 1, |
76 |
payload => 0, |
payload => 1, |
77 |
); |
); |
78 |
|
|
79 |
var $_component_name; |
var $_component_name; |
90 |
* ... or others! (these are just proposals for convenience) |
* ... or others! (these are just proposals for convenience) |
91 |
* |
* |
92 |
*/ |
*/ |
93 |
var $_handler = NULL; |
var $_proxy = NULL; |
94 |
|
|
95 |
|
|
96 |
/** |
/** |
103 |
* ); |
* ); |
104 |
* |
* |
105 |
*/ |
*/ |
106 |
var $_handler_options = NULL; |
var $_proxy_options = NULL; |
107 |
|
|
108 |
|
|
109 |
function about() { |
function about() { |
123 |
|
|
124 |
function constructor($handler = array()) { |
function constructor($handler = array()) { |
125 |
if (sizeof($handler)) { |
if (sizeof($handler)) { |
126 |
$this->set_handler($handler); |
$this->set_proxy($handler); |
127 |
} |
} |
128 |
$this->create_handler(); |
$this->create_proxy(); |
129 |
$this->call_handler(); |
$this->call_proxy(); |
130 |
} |
} |
131 |
|
|
132 |
/* |
/* |
144 |
* @param Handler object - &$handler |
* @param Handler object - &$handler |
145 |
* |
* |
146 |
*/ |
*/ |
147 |
function set_handler( &$handler ) { |
function set_proxy( &$handler ) { |
148 |
$this->_handler = &$handler; |
$this->_proxy = &$handler; |
149 |
} |
} |
150 |
|
|
151 |
function &get_handler() { |
function &get_proxy() { |
152 |
return $this->_handler; |
return $this->_proxy; |
153 |
} |
} |
154 |
|
|
155 |
function call_handler() { |
function call_proxy() { |
156 |
$this->_abstract_method('call_handler', 'DesignPattern::Proxy'); |
$this->_abstract_method('call_proxy', 'DesignPattern::Proxy'); |
157 |
} |
} |
158 |
|
|
159 |
function set_component_name($name) { |
function set_component_name($name) { |
162 |
function get_component_name() { |
function get_component_name() { |
163 |
return $this->_component_name; |
return $this->_component_name; |
164 |
} |
} |
165 |
function set_component_options($options) { |
function set_component_options_v1() { |
166 |
$this->_component_options= $options; |
$options = func_get_args(); |
167 |
|
if (is_array($options)) { |
168 |
|
if (is_hash($options)) { |
169 |
|
$this->_component_options = $options; |
170 |
|
} else { |
171 |
|
$this->_component_options = array(); |
172 |
|
foreach ($options as $option) { |
173 |
|
array_push($this->_component_options, $option); |
174 |
|
} |
175 |
|
} |
176 |
|
} else { |
177 |
|
$this->_component_options = $options; |
178 |
|
} |
179 |
|
} |
180 |
|
function set_component_options() { |
181 |
|
$options = func_get_args(); |
182 |
|
if (sizeof($options) >= 1) { |
183 |
|
$this->_component_options = array(); |
184 |
|
foreach ($options as $option) { |
185 |
|
array_push($this->_component_options, $option); |
186 |
|
} |
187 |
|
} else { |
188 |
|
$this->_component_options = $options; |
189 |
|
} |
190 |
} |
} |
191 |
function get_component_options() { |
function get_component_options() { |
192 |
return $this->_component_options; |
return $this->_component_options; |
193 |
} |
} |
194 |
|
|
195 |
function create_handler() { |
function create_proxy() { |
196 |
//print "DesignPattern::Proxy->create_handler<br/>"; |
//print "DesignPattern::Proxy->create_proxy<br/>"; |
197 |
//print "comp: " . $this->get_component_name() . "<br/>"; |
//print "comp: " . $this->get_component_name() . "<br/>"; |
198 |
//print "comp: " . $this->get_component_options() . "<br/>"; |
//print "comp: " . $this->get_component_options() . "<br/>"; |
199 |
$handler = php::mkComponent( $this->get_component_name(), $this->get_component_options() ); |
$handler = php::mkComponent( $this->get_component_name(), $this->get_component_options() ); |
200 |
//print Dumper($handler); |
//print Dumper($handler); |
201 |
//exit; |
//exit; |
202 |
|
|
203 |
$this->set_handler( $handler ); |
$this->set_proxy( $handler ); |
204 |
} |
} |
205 |
|
|
206 |
|
|