4 |
## $Id$ |
## $Id$ |
5 |
## ------------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------------------- |
6 |
## $Log$ |
## $Log$ |
7 |
|
## Revision 1.2 2003/02/13 21:48:09 joko |
8 |
|
## + caching mechanisms more configurable now |
9 |
|
## |
10 |
## Revision 1.1 2003/02/09 17:23:21 joko |
## Revision 1.1 2003/02/09 17:23:21 joko |
11 |
## + refactored from flib/Application/RPC/ProxyObject.php |
## + refactored from flib/Application/RPC/ProxyObject.php |
12 |
## |
## |
84 |
## ------------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------------------- |
85 |
*/ |
*/ |
86 |
|
|
87 |
|
// TODO: |
88 |
|
// - make database connection more configurable to make possible |
89 |
|
// to have different proxy database (besides the main database) |
90 |
|
// use PEAR for this! no more 'connectdb' here!!! |
91 |
|
// - extend options to en-/disable caching via a) session and/or b) database |
92 |
|
|
93 |
class Data_Driver_Proxy { |
class Data_Driver_Proxy { |
94 |
|
|
102 |
function Data_Driver_Proxy($objectId = "", $options = array() ) { |
function Data_Driver_Proxy($objectId = "", $options = array() ) { |
103 |
logp(get_class($this) . "->new()", PEAR_LOG_INFO); |
logp(get_class($this) . "->new()", PEAR_LOG_INFO); |
104 |
global $proxy; |
global $proxy; |
105 |
//print Dumper($objectId, $options); |
|
106 |
session_register_safe("proxy"); |
// trace |
107 |
if ($options[rpcinfo]) { |
//print Dumper($objectId, $options); |
108 |
$this->backend = mkObject('Data::Driver::RPC::Remote', $options[rpcinfo]); |
|
109 |
} |
// initialization/startup |
110 |
$this->_init($objectId, $options); |
$this->_init_meta_options($objectId, $options); |
111 |
|
$this->_init_caching(); |
112 |
|
$this->_init_load(); |
113 |
|
|
114 |
} |
} |
115 |
|
|
116 |
function _init($objectId="", $options = array() ) { |
function _init_meta_options( $objectId="", $options = array() ) { |
117 |
|
$this->meta = $options; |
118 |
|
|
119 |
if ($objectId) { |
if ($objectId) { |
120 |
$this->objectId = $objectId; |
$this->objectId = $objectId; |
|
$this->meta = $options; |
|
121 |
|
|
122 |
// set default load mechanism |
// set default load mechanism |
123 |
if( $this->meta[remote] && ((!$this->meta[oid] && !$this->meta[guid]) || ($this->meta[oid] && $this->meta[guid])) && (!$this->meta[key]) ) { |
if ( $this->meta[remote] && ((!$this->meta[oid] && !$this->meta[guid]) || ($this->meta[oid] && $this->meta[guid])) && (!$this->meta[key]) ) { |
124 |
$this->meta[oid] = 1; |
$this->meta[oid] = 1; |
125 |
} |
} |
126 |
|
|
127 |
|
} |
128 |
|
} |
129 |
|
|
130 |
|
function _init_caching() { |
131 |
|
|
132 |
|
if ($this->meta[cache][session]) { |
133 |
|
session_register_safe("proxy"); |
134 |
|
} |
135 |
|
|
136 |
|
if ($this->meta[remote]) { |
137 |
|
$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
138 |
|
} |
139 |
|
} |
140 |
|
|
141 |
|
function _init_load() { |
142 |
|
if ($this->objectId) { |
143 |
$this->load(); |
$this->load(); |
144 |
//$this->_saveProxy(); |
//$this->_saveProxy(); |
145 |
} |
} |
146 |
} |
} |
147 |
|
|
148 |
|
|
149 |
function load() { |
function load() { |
150 |
logp(get_class($this) . "->load()", PEAR_LOG_INFO); |
logp(get_class($this) . "->load()", PEAR_LOG_INFO); |
151 |
if (!$this->_loadState()) { |
if (!$this->_loadState()) { |
218 |
|
|
219 |
function _loadState() { |
function _loadState() { |
220 |
global $proxy; |
global $proxy; |
221 |
//print Dumper($this); |
|
222 |
logp(get_class($this) . "->_loadState()"); |
// trace |
223 |
|
//print Dumper($this); |
224 |
|
|
225 |
|
// debug |
226 |
|
logp(get_class($this) . "->_loadState()"); |
227 |
|
|
228 |
if ($this->attributes = $proxy[$this->objectId]) { |
if ($this->attributes = $proxy[$this->objectId]) { |
229 |
//print "_loadState:" . dumpVar($this->attributes); |
//print "_loadState:" . dumpVar($this->attributes); |
230 |
$this->meta[decoded] = 1; |
$this->meta[decoded] = 1; |
242 |
} |
} |
243 |
|
|
244 |
function _loadProxy() { |
function _loadProxy() { |
245 |
logp(get_class($this) . "->_loadProxy()"); |
|
246 |
|
// FIXME! |
247 |
|
if (!$this->meta[cache][db]) { return; } |
248 |
|
|
249 |
|
// trace & debug |
250 |
|
//print Dumper($this); |
251 |
|
logp(get_class($this) . "->_loadProxy()"); |
252 |
|
|
253 |
connectdb(); |
connectdb(); |
254 |
$sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'"; |
$sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'"; |
255 |
if ($res = send_sql($sql)) { |
if ($res = send_sql($sql)) { |
264 |
|
|
265 |
// TODO: use PEAR here |
// TODO: use PEAR here |
266 |
function _saveProxy() { |
function _saveProxy() { |
267 |
|
|
268 |
|
// FIXME! |
269 |
|
if (!$this->meta[cache][db]) { return; } |
270 |
|
|
271 |
logp(get_class($this) . "->_saveProxy()"); |
logp(get_class($this) . "->_saveProxy()"); |
272 |
connectdb(); |
connectdb(); |
273 |
if ($this->payload) { |
if ($this->payload) { |
283 |
function _loadRemote() { |
function _loadRemote() { |
284 |
logp(get_class($this) . "->_loadRemote()"); |
logp(get_class($this) . "->_loadRemote()"); |
285 |
|
|
286 |
//print Dumper($this->meta); |
// trace |
287 |
|
//print Dumper($this->meta); |
288 |
|
|
289 |
// TODO: test backend for reachability first (eventually cache this information and "reset" it by another party) |
// TODO: test backend for reachability first (eventually cache this information and "reset" it by another party) |
290 |
|
|
320 |
logp(get_class($this) . "->_loadRemote: argument 'key' requires 'command'", PEAR_LOG_WARNING); |
logp(get_class($this) . "->_loadRemote: argument 'key' requires 'command'", PEAR_LOG_WARNING); |
321 |
return; |
return; |
322 |
} |
} |
323 |
|
/* |
324 |
if (!$this->meta[query]) { |
if (!$this->meta[query]) { |
325 |
logp(get_class($this) . "->_loadRemote: argument 'key' requires 'query'", PEAR_LOG_WARNING); |
logp(get_class($this) . "->_loadRemote: argument 'key' requires 'query'", PEAR_LOG_WARNING); |
326 |
return; |
return; |
327 |
} |
} |
328 |
|
*/ |
329 |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
330 |
|
|
331 |
} |
} |