3 |
## $Id$ |
## $Id$ |
4 |
## ------------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------------------- |
5 |
## $Log$ |
## $Log$ |
6 |
|
## Revision 1.5 2002/12/18 22:36:49 jonen |
7 |
|
## + added support to get remote objects via backend via 'guid' |
8 |
|
## + renamed '_loadBackend' to '_loadRemote' |
9 |
|
## + constructor now accepts additional options: |
10 |
|
## + remote: try to get object via '_loadRemote' ... |
11 |
|
## + oid: use the given identifier as an 'oid' when doing '_loadRemote' |
12 |
|
## + guid: use the given identifier as a 'guid' when doing '_loadRemote' |
13 |
|
## |
14 |
|
## Revision 1.4 2002/12/12 02:46:31 joko |
15 |
|
## + state (session) gets flushed when data was successfully loaded from remote side |
16 |
|
## + fixed _loadBackend |
17 |
|
## + fixed flushState |
18 |
|
## |
19 |
|
## Revision 1.3 2002/12/06 04:12:54 joko |
20 |
|
## + replaced 'xyzCache' through 'xyzProxy' |
21 |
|
## + function store(...) |
22 |
|
## |
23 |
## Revision 1.2 2002/12/05 21:44:09 joko |
## Revision 1.2 2002/12/05 21:44:09 joko |
24 |
## + debugging |
## + debugging |
25 |
## |
## |
79 |
var $attributes; |
var $attributes; |
80 |
var $backend; |
var $backend; |
81 |
|
|
82 |
function ProxyObject($objectId = "") { |
function ProxyObject($objectId = "", $options = array() ) { |
83 |
session_register_safe("proxy"); |
session_register_safe("proxy"); |
84 |
$this->backend = new Remote; |
$this->backend = new Remote; |
85 |
$this->_init($objectId); |
$this->_init($objectId, $options); |
86 |
} |
} |
87 |
|
|
88 |
function _init($objectId="") { |
function _init($objectId="", $options = array() ) { |
89 |
if ($objectId) { |
if ($objectId) { |
90 |
$this->objectId = $objectId; |
$this->objectId = $objectId; |
91 |
|
$this->meta = $options; |
92 |
|
|
93 |
|
// set default load mechanismn |
94 |
|
if( $this->meta[remote] && ((!$this->meta[oid] && !$this->meta[guid]) || ($this->meta[oid] && $this->meta[guid])) ) { |
95 |
|
$this->meta[oid] = 1; |
96 |
|
} |
97 |
|
|
98 |
$this->load(); |
$this->load(); |
99 |
//$this->_saveCache(); |
//$this->_saveProxy(); |
100 |
} |
} |
101 |
} |
} |
102 |
|
|
103 |
function load() { |
function load() { |
104 |
if (!$this->_loadState()) { |
if (!$this->_loadState()) { |
105 |
if (!$this->_loadCache()) { |
if (!$this->_loadProxy()) { |
106 |
$this->_loadBackend(); |
|
107 |
|
// just load object from remote side if its flagged to be a remote one ... |
108 |
|
if ($this->meta[remote]) { |
109 |
|
$this->_loadRemote(); |
110 |
|
} |
111 |
|
|
112 |
} |
} |
113 |
} |
} |
114 |
} |
} |
126 |
|
|
127 |
function flush() { |
function flush() { |
128 |
$this->flushState(); |
$this->flushState(); |
129 |
$this->flushCache(); |
$this->flushProxy(); |
130 |
} |
} |
131 |
|
|
132 |
function _commit() { |
function _commit() { |
133 |
$this->_saveBackend($this->attributes); |
$this->_saveBackend($this->attributes); |
134 |
$this->flushState(); |
$this->flushState(); |
135 |
$this->flushCache(); |
$this->flushProxy(); |
136 |
} |
} |
137 |
|
|
138 |
|
|
141 |
function _create() { |
function _create() { |
142 |
$this->_createBackend($this->attributes); |
$this->_createBackend($this->attributes); |
143 |
$this->flushState(); |
$this->flushState(); |
144 |
$this->flushCache(); |
$this->flushProxy(); |
145 |
} |
} |
146 |
*/ |
*/ |
147 |
|
|
157 |
$this->attributes = $data; |
$this->attributes = $data; |
158 |
} |
} |
159 |
|
|
160 |
function flushCache() { |
function flushProxy() { |
161 |
connectdb(); |
connectdb(); |
162 |
$sql = "DELETE FROM f_proxy WHERE oid='$this->objectId'"; |
$sql = "DELETE FROM f_proxy WHERE oid='$this->objectId'"; |
163 |
send_sql($sql); |
send_sql($sql); |
166 |
function flushState() { |
function flushState() { |
167 |
global $proxy; |
global $proxy; |
168 |
unset($proxy[$this->objectId]); |
unset($proxy[$this->objectId]); |
169 |
|
$this->meta[decoded] = 0; |
170 |
} |
} |
171 |
|
|
172 |
function _loadState() { |
function _loadState() { |
188 |
// TODO: throw exception-message back to user if operation fails |
// TODO: throw exception-message back to user if operation fails |
189 |
} |
} |
190 |
|
|
191 |
function _loadCache() { |
function _loadProxy() { |
192 |
logp(get_class($this) . "->_loadCache()", LOG_DEBUG); |
logp(get_class($this) . "->_loadProxy()", LOG_DEBUG); |
193 |
connectdb(); |
connectdb(); |
194 |
$sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'"; |
$sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'"; |
195 |
if ($res = send_sql($sql)) { |
if ($res = send_sql($sql)) { |
202 |
} |
} |
203 |
} |
} |
204 |
|
|
205 |
function _saveCache() { |
// TODO: use PEAR here |
206 |
logp(get_class($this) . "->_saveCache()", LOG_DEBUG); |
function _saveProxy() { |
207 |
|
logp(get_class($this) . "->_saveProxy()", LOG_DEBUG); |
208 |
connectdb(); |
connectdb(); |
209 |
if ($this->payload) { |
if ($this->payload) { |
210 |
//$sql = "INSERT INTO f_proxy SET payload='$this->payload' WHERE oid='$this->objectId'"; |
//$sql = "INSERT INTO f_proxy SET payload='$this->payload' WHERE oid='$this->objectId'"; |
216 |
} |
} |
217 |
} |
} |
218 |
|
|
219 |
function _loadBackend() { |
function _loadRemote() { |
220 |
logp(get_class($this) . "->_loadBackend()", LOG_DEBUG); |
logp(get_class($this) . "->_loadRemote()", LOG_DEBUG); |
221 |
|
|
222 |
// 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) |
223 |
if ($result = $this->backend->call('getObject', $this->objectId)) { |
|
224 |
|
// check for guid or oid |
225 |
|
if($this->meta[guid]) { |
226 |
|
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
227 |
|
$result = $this->backend->call('getObjectByGuid', $args ); |
228 |
|
} |
229 |
|
if($this->meta[oid]) { |
230 |
|
$result = $this->backend->call('getObject', $this->objectId); |
231 |
|
} |
232 |
|
|
233 |
|
if ($result) { |
234 |
//print "result: " . dumpVar($result) . "<br>"; |
//print "result: " . dumpVar($result) . "<br>"; |
235 |
if (count($result) == 0) { return; } |
if (count($result) == 0) { return; } |
236 |
|
|
237 |
|
// ----- move this to _encode some times: $this->_encode() |
238 |
$encoder = new TextEncode($result); |
$encoder = new TextEncode($result); |
239 |
$encoder->toISO(); |
$encoder->toISO(); |
240 |
if ($_GET[debug]) { |
if ($_GET[debug]) { |
241 |
print dumpVar($result); |
print dumpVar($result); |
242 |
} |
} |
243 |
$this->payload = serialize($result); |
$this->payload = serialize($result); |
244 |
$this->_saveCache(); |
// ----- move this to _encode some times |
245 |
|
|
246 |
|
$this->_saveProxy(); |
247 |
|
//print "oid: $this->objectId<br>"; |
248 |
|
$this->flushState(); |
249 |
|
} else { |
250 |
|
print "Error in _loadRemote!!!<br>"; |
251 |
} |
} |
252 |
|
|
253 |
} |
} |
254 |
|
|
255 |
function _saveBackend($result) { |
function _saveBackend($result) { |
267 |
$this->meta[decoded] = 1; |
$this->meta[decoded] = 1; |
268 |
} |
} |
269 |
} |
} |
270 |
|
|
271 |
|
function store($struct) { |
272 |
|
$this->payload = serialize($struct); |
273 |
|
$this->_saveProxy(); |
274 |
|
} |
275 |
|
|
276 |
} |
} |
277 |
|
|