1 |
<?php |
<?php |
|
|
|
2 |
/** |
/** |
3 |
|
* This file contains the DesignPattern::RemoteProxy class |
4 |
|
* |
5 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
|
* @package org.netfrag.glib |
7 |
|
* @name DesignPattern::RemoteProxy |
8 |
|
* @filesource |
9 |
|
* |
10 |
|
* |
11 |
|
* <b>Cvs-Log:</b> |
12 |
|
* |
13 |
|
* <pre> |
14 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
15 |
* $Id$ |
* $Id$ |
16 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
17 |
* $Log$ |
* $Log$ |
18 |
|
* Revision 1.7 2003/03/09 15:51:44 joko |
19 |
|
* + additional metadata for Autodia |
20 |
|
* |
21 |
|
* Revision 1.6 2003/03/05 17:28:43 joko |
22 |
|
* updated docu (phpDocumentor testing....) |
23 |
|
* |
24 |
|
* Revision 1.5 2003/03/05 17:02:22 joko |
25 |
|
* updated docu (phpDocumentor testing....) |
26 |
|
* |
27 |
|
* Revision 1.4 2003/03/05 16:32:19 joko |
28 |
|
* updated docu (phpDocumentor testing....) |
29 |
|
* |
30 |
|
* Revision 1.3 2003/03/05 16:10:17 joko |
31 |
|
* updated docu (phpDocumentor testing....) |
32 |
|
* |
33 |
|
* Revision 1.2 2003/03/05 12:14:02 joko |
34 |
|
* renamed method |
35 |
|
* constructor argument expansion |
36 |
|
* |
37 |
* Revision 1.1 2003/03/03 22:06:46 joko |
* Revision 1.1 2003/03/03 22:06:46 joko |
38 |
* refactored from Data::Driver::Proxy |
* refactored from Data::Driver::Proxy |
39 |
* |
* |
121 |
* Revision 1.1 2002/10/09 00:51:39 cvsjoko |
* Revision 1.1 2002/10/09 00:51:39 cvsjoko |
122 |
* + new |
* + new |
123 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
124 |
|
* </pre> |
125 |
|
* |
126 |
*/ |
*/ |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
/** |
/** |
132 |
|
* Load required modules: |
133 |
* |
* |
134 |
* Data::Driver::Proxy -- Multiple stage data fetching and caching |
*/ |
135 |
|
loadModule('DesignPattern::Proxy'); |
136 |
|
|
137 |
|
|
138 |
|
/** |
139 |
|
* DesignPattern::RemoteProxy -- Multiple stage data fetching and caching |
140 |
* |
* |
141 |
* |
* |
142 |
* This class (Data::Driver::Proxy) provides an abstract framework |
* This class (DesignPattern::RemoteProxy) provides an abstract framework |
143 |
* for loading/saving arbitrary data from/to data storages interfaced |
* for loading/saving arbitrary data from/to data storages interfaced |
144 |
* by storage *proxy*-drivers. |
* by storage *proxy*-drivers. |
145 |
* Don't mix these up with the concrete storage *handle*-drivers |
* Don't mix these up with the concrete storage *handle*-drivers |
148 |
* providing a more highlevel, consistent API making |
* providing a more highlevel, consistent API making |
149 |
* it easier for Data::Driver::Proxy to do its main work: |
* it easier for Data::Driver::Proxy to do its main work: |
150 |
* |
* |
151 |
|
* quote from: http://home.earthlink.net/~huston2/dp/proxy.html |
152 |
|
* "A remote proxy provides a local representative for an |
153 |
|
* object that resides in a different address space. This is |
154 |
|
* what the "stub" code in RPC and CORBA provides." |
155 |
|
* |
156 |
|
* |
157 |
* Multiple stage data fetching and caching: |
* Multiple stage data fetching and caching: |
158 |
* |
* |
159 |
|
* <pre> |
160 |
|
* |
161 |
* DATA, ... |
* DATA, ... |
162 |
* ... also refered to as data, should be handled as |
* ... also refered to as data, should be handled as |
163 |
* something called data. |
* something called data. |
200 |
* o Data::Driver::PEAR::DB |
* o Data::Driver::PEAR::DB |
201 |
* x Data::Driver::PEAR::Tree (via Data::Lift) |
* x Data::Driver::PEAR::Tree (via Data::Lift) |
202 |
* |
* |
203 |
*/ |
* </pre> |
|
|
|
|
/** |
|
|
* Todo: |
|
|
* x extend options to en-/disable caching via a) session and/or b) database |
|
|
* o make feature available via runtime setter-method to these options |
|
|
* o use PEAR::Cache for caching purposes!!! |
|
|
* o refactor database access: use PEAR for this! no more 'connectdb' here!!! |
|
|
* o make database connection more flexible to make possible |
|
|
* to have different (probably named) proxy databases (besides a "main database") |
|
|
* o rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper? |
|
204 |
* |
* |
205 |
*/ |
* |
206 |
|
* An attempt to implement some software design patterns |
207 |
/** |
* --- RemoteProxyPattern |
208 |
* Load required modules: |
* |
209 |
|
* @link http://www.agcs.com/supportv2/techpapers/patterns/papers/tutnotes/sld017.htm |
210 |
|
* @link http://home.earthlink.net/~huston2/dp/proxy.html |
211 |
|
* @link http://wiki.cs.uiuc.edu/PatternStories/RemoteObject |
212 |
|
* @link http://c2.com/cgi-bin/wiki?ProxyPattern |
213 |
|
* @link http://c2.com/cgi-bin/wiki?LazyProxies |
214 |
|
* |
215 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
216 |
|
* @link http://www.netfrag.org/~joko/ |
217 |
|
* |
218 |
|
* @copyright (c) 2003 - All Rights reserved. |
219 |
|
* @license GNU LGPL (GNU Lesser General Public License) |
220 |
|
* @link http://www.gnu.org/licenses/lgpl.txt |
221 |
|
* |
222 |
|
* @package org.netfrag.glib |
223 |
|
* @subpackage DesignPattern |
224 |
|
* @name DesignPattern::RemoteProxy |
225 |
|
* |
226 |
|
* |
227 |
|
* @todo extend options to en-/disable caching via a) session and/or b) database |
228 |
|
* make feature available via runtime setter-method to these options |
229 |
|
* @todo PEAR::Cache for caching purposes!!! |
230 |
|
* @todo refactor database access: use PEAR for this! no more 'connectdb' here!!! |
231 |
|
* @todo make database connection more flexible to make possible |
232 |
|
* to have different (probably named) proxy databases (besides a "main database") |
233 |
|
* @todo rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper? |
234 |
|
* @todo refactor this to a "RemoteObject" class!!! (inheriting from DesignPattern::RemoteObject) |
235 |
|
* @todo rename this to "DesignPattern::LazyRemoteProxy"??? |
236 |
* |
* |
237 |
*/ |
*/ |
|
loadModule('DesignPattern::Proxy'); |
|
|
|
|
238 |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
239 |
|
|
240 |
var $objectId; |
var $objectId; |
248 |
logp(get_class($this) . "->new()", PEAR_LOG_INFO); |
logp(get_class($this) . "->new()", PEAR_LOG_INFO); |
249 |
global $proxy; |
global $proxy; |
250 |
|
|
251 |
|
// 2003-03-05 - modified constructor |
252 |
|
// expand objectId |
253 |
|
if (is_array($objectId)) { |
254 |
|
$options = $objectId[1]; |
255 |
|
$objectId = $objectId[0]; |
256 |
|
} |
257 |
|
|
258 |
// trace |
// trace |
259 |
//print Dumper($objectId, $options); |
//print Dumper($objectId, $options); |
260 |
|
|
263 |
$this->_init_caching(); |
$this->_init_caching(); |
264 |
$this->_init_load(); |
$this->_init_load(); |
265 |
|
|
266 |
|
//print Dumper($this); |
267 |
|
|
268 |
} |
} |
269 |
|
|
270 |
function _init_meta_options( $objectId="", $options = array() ) { |
function _init_meta_options( $objectId="", $options = array() ) { |
287 |
session_register_safe("proxy"); |
session_register_safe("proxy"); |
288 |
} |
} |
289 |
|
|
290 |
|
/** |
291 |
|
* <!-- Autodia --> |
292 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
293 |
|
* $this->backend = new DataSource_Proxy_XMLRPC() |
294 |
|
* |
295 |
|
*/ |
296 |
|
|
297 |
if ($this->meta[remote]) { |
if ($this->meta[remote]) { |
298 |
//$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
//$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
299 |
$this->backend = mkObject('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]); |
$this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]); |
300 |
} |
} |
301 |
} |
} |
302 |
|
|
354 |
} |
} |
355 |
*/ |
*/ |
356 |
|
|
357 |
function getAttributes() { |
function getResult() { |
358 |
if (!$this->meta[decoded]) { |
if (!$this->meta[decoded]) { |
359 |
$this->_decode(); |
$this->_decode(); |
360 |
$this->_saveState(); |
$this->_saveState(); |