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 |
## Revision 1.4 2002/12/12 02:46:31 joko |
15 |
## + state (session) gets flushed when data was successfully loaded from remote side |
## + state (session) gets flushed when data was successfully loaded from remote side |
16 |
## + fixed _loadBackend |
## + fixed _loadBackend |
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->_saveProxy(); |
//$this->_saveProxy(); |
100 |
} |
} |
103 |
function load() { |
function load() { |
104 |
if (!$this->_loadState()) { |
if (!$this->_loadState()) { |
105 |
if (!$this->_loadProxy()) { |
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 |
} |
} |
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 |
|
// ----- move this to _encode some times |
245 |
|
|
246 |
$this->_saveProxy(); |
$this->_saveProxy(); |
247 |
//print "oid: $this->objectId<br>"; |
//print "oid: $this->objectId<br>"; |
248 |
$this->flushState(); |
$this->flushState(); |
249 |
|
} else { |
250 |
|
print "Error in _loadRemote!!!<br>"; |
251 |
} |
} |
252 |
|
|
253 |
} |
} |
254 |
|
|
255 |
function _saveBackend($result) { |
function _saveBackend($result) { |