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

Contents of /nfo/php/libs/org.netfrag.glib/DesignPattern/Proxy.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Mon Mar 10 23:30:30 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +8 -1 lines
+ fixed metadata for phpDocumentor

1 <?php
2 /**
3 * This file contains the DesignPattern::Proxy class
4 *
5 * @author Andreas Motl <andreas.motl@ilo.de>
6 * @package org.netfrag.glib
7 * @name DesignPattern::Proxy
8 *
9 *
10 */
11
12
13 /**
14 *
15 *
16 * <b>Cvs-Log:</b>
17 *
18 * <pre>
19 * $Id: Proxy.php,v 1.6 2003/03/10 22:31:56 joko Exp $
20 *
21 * $Log: Proxy.php,v $
22 * Revision 1.6 2003/03/10 22:31:56 joko
23 * + fixed metadata for phpDocumentor
24 *
25 * Revision 1.5 2003/03/05 17:28:43 joko
26 * updated docu (phpDocumentor testing....)
27 *
28 * Revision 1.4 2003/03/05 16:32:18 joko
29 * updated docu (phpDocumentor testing....)
30 *
31 * Revision 1.3 2003/03/05 16:10:17 joko
32 * updated docu (phpDocumentor testing....)
33 *
34 * Revision 1.2 2003/03/05 12:12:42 joko
35 * re-renamed methods and privates: _handler becomes _proxy again
36 *
37 * Revision 1.1 2003/03/03 22:05:25 joko
38 * abstract implementation... ;-)
39 * </pre>
40 *
41 *
42 */
43
44
45 /**
46 * Load required modules:
47 *
48 */
49 loadModule('Class::Logger');
50
51
52 /**
53 * An attempt to implement some software design patterns...
54 * --- ProxyPattern
55 *
56 * @link http://c2.com/cgi-bin/wiki?ProxyPattern
57 *
58 * @author Andreas Motl <andreas.motl@ilo.de>
59 * @link http://www.netfrag.org/~joko/
60 *
61 * @copyright (c) 2003 - All Rights reserved.
62 * @license GNU LGPL (GNU Lesser General Public License)
63 * @link http://www.gnu.org/licenses/lgpl.txt
64 *
65 * @package org.netfrag.glib
66 * @subpackage DesignPattern
67 * @name DesignPattern::Proxy
68 *
69 * @todo (x) DesignPattern::DecoratorProxy (->decorate)
70 * @todo (x) DesignPattern::TransparentProxy (->make_transparent)
71 * @todo (o) DesignPattern::MultiProxy (->both???) (diamond inheritance? possible in php?)
72 * @todo (o) DesignPattern::GenericAdapterProxy???
73 * @todo (o) no 'locator/query' or 'type/component'
74 * @todo (o) even more generic: just 'adapter_metadata' (-> global adapter registry?)
75 *
76 */
77 class DesignPattern_Proxy extends Class_Logger {
78
79 /**
80 * This holds some information about the tracing level.
81 *
82 */
83 var $_debug = array(
84 notice => 1,
85 trace => 1,
86 payload => 1,
87 );
88
89 var $_component_name;
90 var $_component_options;
91
92 /**
93 * This var holds the Handler object
94 * that is used to do the work.
95 * It acts as a dispatcher combining result caching.
96 * It is assumed that this provides 4 methods:
97 * queryData() - execute a query against a data storage
98 * querySchema() - execute a query against underlying storage metadata
99 * sendCommand() - send a command against an arbitrary execution engine
100 * ... or others! (these are just proposals for convenience)
101 *
102 */
103 var $_proxy = NULL;
104
105
106 /**
107 * This var holds options fed to the Proxy object
108 * These are built from locator metadata (_locator) and query arguments (_query)
109 * It's a simple structured hash:
110 * $proxy_options = array(
111 * method => '<remote-method-name>',
112 * args => array('list', 'of', 'arguments')
113 * );
114 *
115 */
116 var $_proxy_options = NULL;
117
118
119 function about() {
120 $this->_about =
121 <<<ABOUT
122 * --- DesignPattern::Proxy
123 * --- http://cvs.netfrag.org/nfo/php/libs/org.netfrag.glib/DesignPattern/Proxy.php
124 *
125 * http://c2.com/cgi-bin/wiki?ProxyPattern says...
126 * Intent: Provide a surrogate or placeholder for another object to control access to it.
127 * http://www.fluffycat.com/java/patterns.html says...
128 * One class controls the creation of and access to objects in another class.
129
130 ABOUT;
131 }
132
133
134 function constructor($handler = array()) {
135 if (sizeof($handler)) {
136 $this->set_proxy($handler);
137 }
138 $this->create_proxy();
139 $this->call_proxy();
140 }
141
142 /*
143 function _abstract_method($method) {
144 $package = get_class($this);
145 $package_p = get_parent_class($this);
146 user_error("DesignPattern::Proxy.$package_p.$package: Please implement method '$method'.");
147 }
148 */
149
150
151 /**
152 * Directly inject a Handler instance to use.
153 *
154 * @param Handler object - &$handler
155 *
156 */
157 function set_proxy( &$handler ) {
158 $this->_proxy = &$handler;
159 }
160
161 function &get_proxy() {
162 return $this->_proxy;
163 }
164
165 function call_proxy() {
166 $this->_abstract_method('call_proxy', 'DesignPattern::Proxy');
167 }
168
169 function set_component_name($name) {
170 $this->_component_name = $name;
171 }
172 function get_component_name() {
173 return $this->_component_name;
174 }
175 function set_component_options_v1() {
176 $options = func_get_args();
177 if (is_array($options)) {
178 if (is_hash($options)) {
179 $this->_component_options = $options;
180 } else {
181 $this->_component_options = array();
182 foreach ($options as $option) {
183 array_push($this->_component_options, $option);
184 }
185 }
186 } else {
187 $this->_component_options = $options;
188 }
189 }
190 function set_component_options() {
191 $options = func_get_args();
192 if (sizeof($options) >= 1) {
193 $this->_component_options = array();
194 foreach ($options as $option) {
195 array_push($this->_component_options, $option);
196 }
197 } else {
198 $this->_component_options = $options;
199 }
200 }
201 function get_component_options() {
202 return $this->_component_options;
203 }
204
205 function create_proxy() {
206 //print "DesignPattern::Proxy->create_proxy<br/>";
207 //print "comp: " . $this->get_component_name() . "<br/>";
208 //print "comp: " . $this->get_component_options() . "<br/>";
209 $handler = php::mkComponent( $this->get_component_name(), $this->get_component_options() );
210 //print Dumper($handler);
211 //exit;
212
213 $this->set_proxy( $handler );
214 }
215
216
217 }
218
219 ?>

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