/[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.3 by joko, Fri Dec 6 04:12:54 2002 UTC revision 1.7 by jonen, Mon Feb 3 03:31:38 2003 UTC
# Line 3  Line 3 
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  ##    Revision 1.3  2002/12/06 04:12:54  joko
26  ##    + replaced 'xyzCache' through 'xyzProxy'  ##    + replaced 'xyzCache' through 'xyzProxy'
27  ##    + function store(...)  ##    + function store(...)
# Line 66  class ProxyObject { Line 85  class ProxyObject {
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->_saveProxy();        //$this->_saveProxy();
106      }      }
# Line 83  class ProxyObject { Line 109  class ProxyObject {
109    function load() {    function load() {
110      if (!$this->_loadState()) {      if (!$this->_loadState()) {
111        if (!$this->_loadProxy()) {        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    }      }  
# Line 141  class ProxyObject { Line 172  class ProxyObject {
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() {
# Line 190  class ProxyObject { Line 222  class ProxyObject {
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        // 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>";        //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          // ----- move this to _encode some times
248          
249        $this->_saveProxy();        $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() {

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.7

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