| 3 |
## $Id$ |
## $Id$ |
| 4 |
## ------------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------------------- |
| 5 |
## $Log$ |
## $Log$ |
| 6 |
|
## Revision 1.7 2003/02/03 03:31:38 jonen |
| 7 |
|
## - moved '$encoder->toISO()' to 'Remote.php' |
| 8 |
|
## |
| 9 |
|
## Revision 1.6 2002/12/22 13:26:20 jonen |
| 10 |
|
## + added support of tangram independent id (e.g. Data::UUID) toggled by option at conrtuctor |
| 11 |
|
## |
| 12 |
|
## Revision 1.5 2002/12/18 22:36:49 jonen |
| 13 |
|
## + added support to get remote objects via backend via 'guid' |
| 14 |
|
## + renamed '_loadBackend' to '_loadRemote' |
| 15 |
|
## + constructor now accepts additional options: |
| 16 |
|
## + remote: try to get object via '_loadRemote' ... |
| 17 |
|
## + oid: use the given identifier as an 'oid' when doing '_loadRemote' |
| 18 |
|
## + guid: use the given identifier as a 'guid' when doing '_loadRemote' |
| 19 |
|
## |
| 20 |
|
## Revision 1.4 2002/12/12 02:46:31 joko |
| 21 |
|
## + state (session) gets flushed when data was successfully loaded from remote side |
| 22 |
|
## + fixed _loadBackend |
| 23 |
|
## + fixed flushState |
| 24 |
|
## |
| 25 |
|
## Revision 1.3 2002/12/06 04:12:54 joko |
| 26 |
|
## + replaced 'xyzCache' through 'xyzProxy' |
| 27 |
|
## + function store(...) |
| 28 |
|
## |
| 29 |
|
## Revision 1.2 2002/12/05 21:44:09 joko |
| 30 |
|
## + debugging |
| 31 |
|
## |
| 32 |
## Revision 1.1 2002/12/01 17:23:58 joko |
## Revision 1.1 2002/12/01 17:23:58 joko |
| 33 |
## + initial check-in |
## + initial check-in |
| 34 |
## |
## |
| 85 |
var $attributes; |
var $attributes; |
| 86 |
var $backend; |
var $backend; |
| 87 |
|
|
| 88 |
function ProxyObject($objectId = "") { |
function ProxyObject($objectId = "", $options = array() ) { |
| 89 |
session_register_safe("proxy"); |
session_register_safe("proxy"); |
| 90 |
$this->backend = new Remote; |
$this->backend = new Remote; |
| 91 |
$this->_init($objectId); |
$this->_init($objectId, $options); |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
function _init($objectId="") { |
function _init($objectId="", $options = array() ) { |
| 95 |
if ($objectId) { |
if ($objectId) { |
| 96 |
$this->objectId = $objectId; |
$this->objectId = $objectId; |
| 97 |
|
$this->meta = $options; |
| 98 |
|
|
| 99 |
|
// set default load mechanismn |
| 100 |
|
if( $this->meta[remote] && ((!$this->meta[oid] && !$this->meta[guid]) || ($this->meta[oid] && $this->meta[guid])) ) { |
| 101 |
|
$this->meta[oid] = 1; |
| 102 |
|
} |
| 103 |
|
|
| 104 |
$this->load(); |
$this->load(); |
| 105 |
//$this->_saveCache(); |
//$this->_saveProxy(); |
| 106 |
} |
} |
| 107 |
} |
} |
| 108 |
|
|
| 109 |
function load() { |
function load() { |
| 110 |
if (!$this->_loadState()) { |
if (!$this->_loadState()) { |
| 111 |
if (!$this->_loadCache()) { |
if (!$this->_loadProxy()) { |
| 112 |
$this->_loadBackend(); |
|
| 113 |
|
// just load object from remote side if its flagged to be a remote one ... |
| 114 |
|
if ($this->meta[remote]) { |
| 115 |
|
$this->_loadRemote(); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
} |
} |
| 119 |
} |
} |
| 120 |
} |
} |
| 132 |
|
|
| 133 |
function flush() { |
function flush() { |
| 134 |
$this->flushState(); |
$this->flushState(); |
| 135 |
$this->flushCache(); |
$this->flushProxy(); |
| 136 |
} |
} |
| 137 |
|
|
| 138 |
function _commit() { |
function _commit() { |
| 139 |
$this->_saveBackend($this->attributes); |
$this->_saveBackend($this->attributes); |
| 140 |
$this->flushState(); |
$this->flushState(); |
| 141 |
$this->flushCache(); |
$this->flushProxy(); |
| 142 |
} |
} |
| 143 |
|
|
| 144 |
|
|
| 147 |
function _create() { |
function _create() { |
| 148 |
$this->_createBackend($this->attributes); |
$this->_createBackend($this->attributes); |
| 149 |
$this->flushState(); |
$this->flushState(); |
| 150 |
$this->flushCache(); |
$this->flushProxy(); |
| 151 |
} |
} |
| 152 |
*/ |
*/ |
| 153 |
|
|
| 163 |
$this->attributes = $data; |
$this->attributes = $data; |
| 164 |
} |
} |
| 165 |
|
|
| 166 |
function flushCache() { |
function flushProxy() { |
| 167 |
connectdb(); |
connectdb(); |
| 168 |
$sql = "DELETE FROM f_proxy WHERE oid='$this->objectId'"; |
$sql = "DELETE FROM f_proxy WHERE oid='$this->objectId'"; |
| 169 |
send_sql($sql); |
send_sql($sql); |
| 172 |
function flushState() { |
function flushState() { |
| 173 |
global $proxy; |
global $proxy; |
| 174 |
unset($proxy[$this->objectId]); |
unset($proxy[$this->objectId]); |
| 175 |
|
$this->meta[decoded] = 0; |
| 176 |
} |
} |
| 177 |
|
|
| 178 |
function _loadState() { |
function _loadState() { |
| 194 |
// TODO: throw exception-message back to user if operation fails |
// TODO: throw exception-message back to user if operation fails |
| 195 |
} |
} |
| 196 |
|
|
| 197 |
function _loadCache() { |
function _loadProxy() { |
| 198 |
logp(get_class($this) . "->_loadCache()", LOG_DEBUG); |
logp(get_class($this) . "->_loadProxy()", LOG_DEBUG); |
| 199 |
connectdb(); |
connectdb(); |
| 200 |
$sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'"; |
$sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'"; |
| 201 |
if ($res = send_sql($sql)) { |
if ($res = send_sql($sql)) { |
| 208 |
} |
} |
| 209 |
} |
} |
| 210 |
|
|
| 211 |
function _saveCache() { |
// TODO: use PEAR here |
| 212 |
logp(get_class($this) . "->_saveCache()", LOG_DEBUG); |
function _saveProxy() { |
| 213 |
|
logp(get_class($this) . "->_saveProxy()", LOG_DEBUG); |
| 214 |
connectdb(); |
connectdb(); |
| 215 |
if ($this->payload) { |
if ($this->payload) { |
| 216 |
//$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'"; |
| 222 |
} |
} |
| 223 |
} |
} |
| 224 |
|
|
| 225 |
function _loadBackend() { |
function _loadRemote() { |
| 226 |
logp(get_class($this) . "->_loadBackend()", LOG_DEBUG); |
logp(get_class($this) . "->_loadRemote()", LOG_DEBUG); |
| 227 |
|
|
| 228 |
// 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) |
| 229 |
if ($result = $this->backend->call('getObject', $this->objectId)) { |
|
| 230 |
//print dumpVar($result); |
// check for guid or oid |
| 231 |
|
if($this->meta[guid]) { |
| 232 |
|
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
| 233 |
|
$result = $this->backend->send('getObjectByGuid', $args ); |
| 234 |
|
} |
| 235 |
|
if($this->meta[oid]) { |
| 236 |
|
$result = $this->backend->send('getObject', $this->objectId); |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
if ($result) { |
| 240 |
|
//print "result: " . dumpVar($result) . "<br>"; |
| 241 |
if (count($result) == 0) { return; } |
if (count($result) == 0) { return; } |
| 242 |
$encoder = new TextEncode($result); |
|
|
$encoder->toISO(); |
|
| 243 |
if ($_GET[debug]) { |
if ($_GET[debug]) { |
| 244 |
print dumpVar($result); |
print dumpVar($result); |
| 245 |
} |
} |
| 246 |
$this->payload = serialize($result); |
$this->payload = serialize($result); |
| 247 |
$this->_saveCache(); |
// ----- move this to _encode some times |
| 248 |
|
|
| 249 |
|
$this->_saveProxy(); |
| 250 |
|
//print "oid: $this->objectId<br>"; |
| 251 |
|
$this->flushState(); |
| 252 |
|
} else { |
| 253 |
|
print "Error in _loadRemote!!!<br>"; |
| 254 |
} |
} |
| 255 |
|
|
| 256 |
} |
} |
| 257 |
|
|
| 258 |
function _saveBackend($result) { |
function _saveBackend($result) { |
| 259 |
logp(get_class($this) . "->_saveBackend()", LOG_DEBUG); |
logp(get_class($this) . "->_saveBackend()", LOG_DEBUG); |
| 260 |
$encoder = new TextEncode($result); |
|
| 261 |
$encoder->toUTF8(); |
//$encoder = new TextEncode($result); |
| 262 |
$response = $this->backend->send('saveObject', array('oid' => $this->objectId, 'data' => $result) ); |
//$encoder->toUTF8(); |
| 263 |
|
|
| 264 |
|
// check for guid or oid |
| 265 |
|
if($this->meta[guid]) { |
| 266 |
|
$args = array( 'guid' => $this->objectId, 'classname' => $this->meta[classname], 'data' => $result ); |
| 267 |
|
$response = $this->backend->send('saveObjectByGuid', $args, array( utf8 => 1) ); |
| 268 |
|
} |
| 269 |
|
if($this->meta[oid]) { |
| 270 |
|
$response = $this->backend->send('saveObject', array('oid' => $this->objectId, 'data' => $result), array( utf8 => 1) ); |
| 271 |
|
} |
| 272 |
} |
} |
| 273 |
|
|
| 274 |
function _decode() { |
function _decode() { |
| 279 |
$this->meta[decoded] = 1; |
$this->meta[decoded] = 1; |
| 280 |
} |
} |
| 281 |
} |
} |
| 282 |
|
|
| 283 |
|
function store($struct) { |
| 284 |
|
$this->payload = serialize($struct); |
| 285 |
|
$this->_saveProxy(); |
| 286 |
|
} |
| 287 |
|
|
| 288 |
} |
} |
| 289 |
|
|