/[cvs]/nfo/php/libs/org.netfrag.flib/Application/RPC/ProxyObject.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.flib/Application/RPC/ProxyObject.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by joko, Thu Dec 12 02:46:31 2002 UTC revision 1.6 by jonen, Sun Dec 22 13:26:20 2002 UTC
# Line 3  Line 3 
3  ##    $Id$  ##    $Id$
4  ##    -------------------------------------------------------------------------------------  ##    -------------------------------------------------------------------------------------
5  ##    $Log$  ##    $Log$
6    ##    Revision 1.6  2002/12/22 13:26:20  jonen
7    ##    + added support of tangram independent id (e.g. Data::UUID) toggled by option at conrtuctor
8    ##
9    ##    Revision 1.5  2002/12/18 22:36:49  jonen
10    ##    + added support to get remote objects via backend via 'guid'
11    ##    + renamed '_loadBackend' to '_loadRemote'
12    ##    + constructor now accepts additional options:
13    ##      + remote: try to get object via '_loadRemote' ...
14    ##      + oid: use the given identifier as an 'oid' when doing '_loadRemote'
15    ##      + guid: use the given identifier as a 'guid' when doing '_loadRemote'
16    ##
17  ##    Revision 1.4  2002/12/12 02:46:31  joko  ##    Revision 1.4  2002/12/12 02:46:31  joko
18  ##    + state (session) gets flushed when data was successfully loaded from remote side  ##    + state (session) gets flushed when data was successfully loaded from remote side
19  ##    + fixed _loadBackend  ##    + fixed _loadBackend
# Line 71  class ProxyObject { Line 82  class ProxyObject {
82    var $attributes;    var $attributes;
83    var $backend;    var $backend;
84    
85    function ProxyObject($objectId = "") {    function ProxyObject($objectId = "", $options = array() ) {
86      session_register_safe("proxy");      session_register_safe("proxy");
87      $this->backend = new Remote;      $this->backend = new Remote;
88      $this->_init($objectId);      $this->_init($objectId, $options);
89    }    }
90    
91    function _init($objectId="") {    function _init($objectId="", $options = array() ) {
92      if ($objectId) {      if ($objectId) {
93        $this->objectId = $objectId;        $this->objectId = $objectId;
94          $this->meta = $options;
95          
96          // set default load mechanismn
97          if( $this->meta[remote] && ((!$this->meta[oid] && !$this->meta[guid]) || ($this->meta[oid] && $this->meta[guid])) ) {
98            $this->meta[oid] = 1;
99          }
100    
101        $this->load();        $this->load();
102        //$this->_saveProxy();        //$this->_saveProxy();
103      }      }
# Line 88  class ProxyObject { Line 106  class ProxyObject {
106    function load() {    function load() {
107      if (!$this->_loadState()) {      if (!$this->_loadState()) {
108        if (!$this->_loadProxy()) {        if (!$this->_loadProxy()) {
109          $this->_loadBackend();  
110            // just load object from remote side if its flagged to be a remote one ...
111            if ($this->meta[remote]) {
112              $this->_loadRemote();
113            }
114    
115        }        }
116      }      }
117    }      }  
# Line 196  class ProxyObject { Line 219  class ProxyObject {
219      }      }
220    }    }
221        
222    function _loadBackend() {    function _loadRemote() {
223      logp(get_class($this) . "->_loadBackend()", LOG_DEBUG);      logp(get_class($this) . "->_loadRemote()", LOG_DEBUG);
224        
225      // 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)
226      if ($result = $this->backend->call('getObject', $this->objectId)) {      
227        // check for guid or oid
228        if($this->meta[guid]) {
229          $args = array( guid => $this->objectId, classname => $this->meta[classname] );
230          $result = $this->backend->send('getObjectByGuid', $args );
231        }
232        if($this->meta[oid]) {
233          $result = $this->backend->send('getObject', $this->objectId);
234        }
235        
236        if ($result) {
237        //print "result: " . dumpVar($result) . "<br>";        //print "result: " . dumpVar($result) . "<br>";
238        if (count($result) == 0) { return; }        if (count($result) == 0) { return; }
239          
240          // ----- move this to _encode some times:  $this->_encode()
241        $encoder = new TextEncode($result);        $encoder = new TextEncode($result);
242        $encoder->toISO();        $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          // ----- move this to _encode some times
248          
249        $this->_saveProxy();        $this->_saveProxy();
250        //print "oid: $this->objectId<br>";        //print "oid: $this->objectId<br>";
251        $this->flushState();        $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() {

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.6

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed