/[cvs]/nfo/php/libs/org.netfrag.glib/Data/Driver/Proxy.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/Data/Driver/Proxy.php

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

revision 1.1 by joko, Sun Feb 9 17:23:21 2003 UTC revision 1.3 by joko, Sat Mar 1 04:56:38 2003 UTC
# Line 1  Line 1 
1  <?  <?php
2  /*  
3  ##    -------------------------------------------------------------------------------------  /**
4  ##    $Id$   * -------------------------------------------------------------------------
5  ##    -------------------------------------------------------------------------------------   *    $Id$
6  ##    $Log$   * -------------------------------------------------------------------------
7  ##    Revision 1.1  2003/02/09 17:23:21  joko   *    $Log$
8  ##    + refactored from flib/Application/RPC/ProxyObject.php   *    Revision 1.3  2003/03/01 04:56:38  joko
9  ##   *    new comment style for large blocks - stolen from phpHtmlLib
10  ##    Revision 1.7  2003/02/03 03:31:38  jonen   *    commit-log encapsulated into such a block
11  ##    - moved '$encoder->toISO()' to 'Remote.php'   *    introduced some documentation
12  ##   *    refactored todo (now also inside a stylish block)
13  ##    Revision 1.6  2002/12/22 13:26:20  jonen   *
14  ##    + added support of tangram independent id (e.g. Data::UUID) toggled by option at conrtuctor   *    Revision 1.2  2003/02/13 21:48:09  joko
15  ##   *    + caching mechanisms more configurable now
16  ##    Revision 1.5  2002/12/18 22:36:49  jonen   *
17  ##    + added support to get remote objects via backend via 'guid'   *    Revision 1.1  2003/02/09 17:23:21  joko
18  ##    + renamed '_loadBackend' to '_loadRemote'   *    + refactored from flib/Application/RPC/ProxyObject.php
19  ##    + constructor now accepts additional options:   *
20  ##      + remote: try to get object via '_loadRemote' ...   *    Revision 1.7  2003/02/03 03:31:38  jonen
21  ##      + oid: use the given identifier as an 'oid' when doing '_loadRemote'   *    - moved '$encoder->toISO()' to 'Remote.php'
22  ##      + guid: use the given identifier as a 'guid' when doing '_loadRemote'   *
23  ##   *    Revision 1.6  2002/12/22 13:26:20  jonen
24  ##    Revision 1.4  2002/12/12 02:46:31  joko   *    + added support of tangram independent id (e.g. Data::UUID) toggled by option at conrtuctor
25  ##    + state (session) gets flushed when data was successfully loaded from remote side   *
26  ##    + fixed _loadBackend   *    Revision 1.5  2002/12/18 22:36:49  jonen
27  ##    + fixed flushState   *    + added support to get remote objects via backend via 'guid'
28  ##   *    + renamed '_loadBackend' to '_loadRemote'
29  ##    Revision 1.3  2002/12/06 04:12:54  joko   *    + constructor now accepts additional options:
30  ##    + replaced 'xyzCache' through 'xyzProxy'   *      + remote: try to get object via '_loadRemote' ...
31  ##    + function store(...)   *      + oid: use the given identifier as an 'oid' when doing '_loadRemote'
32  ##   *      + guid: use the given identifier as a 'guid' when doing '_loadRemote'
33  ##    Revision 1.2  2002/12/05 21:44:09  joko   *
34  ##    + debugging   *    Revision 1.4  2002/12/12 02:46:31  joko
35  ##   *    + state (session) gets flushed when data was successfully loaded from remote side
36  ##    Revision 1.1  2002/12/01 17:23:58  joko   *    + fixed _loadBackend
37  ##    + initial check-in   *    + fixed flushState
38  ##   *
39  ##    Revision 1.11  2002/11/12 06:05:58  cvsjoko   *    Revision 1.3  2002/12/06 04:12:54  joko
40  ##    + renamed class: Text_Encode -> TextEncode   *    + replaced 'xyzCache' through 'xyzProxy'
41  ##   *    + function store(...)
42  ##    Revision 1.10  2002/10/29 19:15:33  cvsjoko   *
43  ##    - moved utf8/iso-conversion to lib/utils/Text_Encode.php   *    Revision 1.2  2002/12/05 21:44:09  joko
44  ##   *    + debugging
45  ##    Revision 1.9  2002/10/26 12:32:36  cvsjoko   *
46  ##    - removed debugging via "print"   *    Revision 1.1  2002/12/01 17:23:58  joko
47  ##    + added generic logging via PEAR::Log   *    + initial check-in
48  ##   *
49  ##    Revision 1.8  2002/10/22 09:51:38  cvsmax   *    Revision 1.11  2002/11/12 06:05:58  cvsjoko
50  ##    + moved semi-method 'createBackend' to method $site->user->create at User.class.php   *    + renamed class: Text_Encode -> TextEncode
51  ##   *
52  ##    Revision 1.7  2002/10/21 18:27:09  cvsjoko   *    Revision 1.10  2002/10/29 19:15:33  cvsjoko
53  ##    - manually disabled any form of caching   *    - moved utf8/iso-conversion to lib/utils/Text_Encode.php
54  ##   *
55  ##    Revision 1.6  2002/10/17 03:48:47  cvsmax   *    Revision 1.9  2002/10/26 12:32:36  cvsjoko
56  ##    + new   *    - removed debugging via "print"
57  ##       + function _createBackend      create new Backend   *    + added generic logging via PEAR::Log
58  ##       + function _create             api-create   *
59  ##   *    Revision 1.8  2002/10/22 09:51:38  cvsmax
60  ##    Revision 1.5  2002/10/16 03:37:54  cvsjoko   *    + moved semi-method 'createBackend' to method $site->user->create at User.class.php
61  ##    + bugfix: wrong comparison in restriction to save to array   *
62  ##   *    Revision 1.7  2002/10/21 18:27:09  cvsjoko
63  ##    Revision 1.4  2002/10/10 03:04:23  cvsjoko   *    - manually disabled any form of caching
64  ##    + no debug-output   *
65  ##   *    Revision 1.6  2002/10/17 03:48:47  cvsmax
66  ##    Revision 1.3  2002/10/10 03:03:27  cvsjoko   *    + new
67  ##    + bugfix: save object to cache only if payload from backend isn't empty   *       + function _createBackend      create new Backend
68  ##   *       + function _create             api-create
69  ##    Revision 1.2  2002/10/10 02:40:06  cvsjoko   *
70  ##    + new level of data-caching (session and persistant)   *    Revision 1.5  2002/10/16 03:37:54  cvsjoko
71  ##        + function _loadState loads data from session   *    + bugfix: wrong comparison in restriction to save to array
72  ##        + function _saveState saves data to session   *
73  ##        + function save               api-save (session & backend)   *    Revision 1.4  2002/10/10 03:04:23  cvsjoko
74  ##        + function _commit    saves data to backend   *    + no debug-output
75  ##    + handy utils   *
76  ##        + function _setAttributes   *    Revision 1.3  2002/10/10 03:03:27  cvsjoko
77  ##        + function flushState   *    + bugfix: save object to cache only if payload from backend isn't empty
78  ##   *
79  ##    Revision 1.1  2002/10/09 00:51:39  cvsjoko   *    Revision 1.2  2002/10/10 02:40:06  cvsjoko
80  ##    + new   *    + new level of data-caching (session and persistant)
81  ##    -------------------------------------------------------------------------------------   *        + function _loadState loads data from session
82  */   *        + function _saveState saves data to session
83     *        + function save               api-save (session & backend)
84     *        + function _commit    saves data to backend
85     *    + handy utils
86     *        + function _setAttributes
87     *        + function flushState
88     *
89     *    Revision 1.1  2002/10/09 00:51:39  cvsjoko
90     *    + new
91     * -------------------------------------------------------------------------
92     */
93    
94    /**
95     *
96     * Data::Driver::Proxy  --  Multiple stage data fetching and caching
97     *
98     *
99     * This class (Data::Driver::Proxy) provides an abstract framework
100     * for loading/saving arbitrary data from/to data storages interfaced
101     * by storage *proxy*-drivers.
102     * Don't mix these up with the concrete storage *handle*-drivers
103     * doing the lowlevel stuff (opening files, talking sql, etc.).
104     * These proxy-drivers are "just" wrappers around them
105     * providing a more highlevel, consistent API making
106     * it easier for Data::Driver::Proxy to do its main work:
107     *
108     * Multiple stage data fetching and caching:
109     *
110     * DATA, ...
111     *    ... also refered to as data, should be handled as
112     *    something called data.
113     *
114     * STAGES
115     *    x native php4 session: serialized payload
116     *    x single rdbms table: serialized payload
117     *       x ... via custom database wrapper
118     *          x included php-file, included php-library
119     *          o object, component, package, callbacks
120     *       x ... via php PEAR DB abstraction objects
121     *    x remote objects (items): flat attribute hash
122     *       o use Data::Object::Identity
123     *       o via Data::Driver::Proxy::RPC or others
124     *       o Data::Object::Encoder: encodes/decodes values
125     *       o Data::Object::Interpolator: interpolates/resolves references
126     *
127     * WORK
128     *    x move data transparently around between these stages
129     *
130     * TOOLS
131     *
132     * x Overview - Packages, Handlers and Stages:
133     *     This is weird.  ;-)
134     *     - A Package can be instantiated by its namespaced classname
135     *       e.g.: "mkObject('My::Package');"
136     *     - A Package can be a Handler for Data::Driver::Proxy
137     *     - A Handler implements exactly one Stage
138     *     - Data::Driver::Proxy itself embeds these Stages:
139     *        x php4-session
140     *        x rdbms-table
141     *     - An example Handler is Data::Driver::RPC::Remote
142     *
143     * x Handlers:
144     *    x Data::Driver::RPC::Remote
145     *        Interacts with a RPC::XML server (todo: talk SOAP!)
146     *        using PEAR::XML::RPC.
147     *        It can cache data for "disconnected mode" using the
148     *    o Data::Driver::phpHtmlLib
149     *    o Data::Driver::PEAR::DB
150     *    x Data::Driver::PEAR::Tree (via Data::Lift)
151     *
152     */
153    
154    /**
155     * Todo:
156     *  x extend options to en-/disable caching via a) session and/or b) database
157     *    o make feature available via runtime setter-method to these options
158     *  o use PEAR::Cache for caching purposes!!!
159     *  o refactor database access: use PEAR for this! no more 'connectdb' here!!!
160     *  o make database connection more flexible to make possible
161     *      to have different (probably named) proxy databases (besides a "main database")
162     *  o rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper?
163     *
164     */
165    
166    
167  class Data_Driver_Proxy {  class Data_Driver_Proxy {
# Line 94  class Data_Driver_Proxy { Line 176  class Data_Driver_Proxy {
176    function Data_Driver_Proxy($objectId = "", $options = array() ) {    function Data_Driver_Proxy($objectId = "", $options = array() ) {
177      logp(get_class($this) . "->new()", PEAR_LOG_INFO);      logp(get_class($this) . "->new()", PEAR_LOG_INFO);
178      global $proxy;      global $proxy;
179      //print Dumper($objectId, $options);  
180      session_register_safe("proxy");      // trace
181      if ($options[rpcinfo]) {        //print Dumper($objectId, $options);
182        $this->backend = mkObject('Data::Driver::RPC::Remote', $options[rpcinfo]);  
183      }      // initialization/startup
184      $this->_init($objectId, $options);        $this->_init_meta_options($objectId, $options);
185          $this->_init_caching();
186          $this->_init_load();
187    
188    }    }
189    
190    function _init($objectId="", $options = array() ) {    function _init_meta_options( $objectId="", $options = array() ) {
191        $this->meta = $options;
192    
193      if ($objectId) {      if ($objectId) {
194        $this->objectId = $objectId;        $this->objectId = $objectId;
       $this->meta = $options;  
195                
196        // set default load mechanism        // set default load mechanism
197        if( $this->meta[remote] && ((!$this->meta[oid] && !$this->meta[guid]) || ($this->meta[oid] && $this->meta[guid])) && (!$this->meta[key]) ) {        if ( $this->meta[remote] && ((!$this->meta[oid] && !$this->meta[guid]) || ($this->meta[oid] && $this->meta[guid])) && (!$this->meta[key]) ) {
198          $this->meta[oid] = 1;          $this->meta[oid] = 1;
199        }        }
200                
201        }
202      }
203    
204      function _init_caching() {
205        
206        if ($this->meta[cache][session]) {
207          session_register_safe("proxy");
208        }  
209    
210        if ($this->meta[remote]) {
211          $this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]);
212        }
213      }
214    
215      function _init_load() {
216        if ($this->objectId) {
217        $this->load();        $this->load();
218        //$this->_saveProxy();        //$this->_saveProxy();
219      }      }
220    }    }
221    
222    
223    function load() {    function load() {
224      logp(get_class($this) . "->load()", PEAR_LOG_INFO);      logp(get_class($this) . "->load()", PEAR_LOG_INFO);
225      if (!$this->_loadState()) {      if (!$this->_loadState()) {
# Line 189  class Data_Driver_Proxy { Line 292  class Data_Driver_Proxy {
292    
293    function _loadState() {    function _loadState() {
294      global $proxy;      global $proxy;
295  //print Dumper($this);  
296      logp(get_class($this) . "->_loadState()");      // trace
297          //print Dumper($this);
298    
299        // debug
300          logp(get_class($this) . "->_loadState()");
301          
302      if ($this->attributes = $proxy[$this->objectId]) {      if ($this->attributes = $proxy[$this->objectId]) {
303        //print "_loadState:" . dumpVar($this->attributes);        //print "_loadState:" . dumpVar($this->attributes);
304        $this->meta[decoded] = 1;        $this->meta[decoded] = 1;
# Line 208  class Data_Driver_Proxy { Line 316  class Data_Driver_Proxy {
316    }    }
317    
318    function _loadProxy() {    function _loadProxy() {
319      logp(get_class($this) . "->_loadProxy()");      
320        // FIXME!
321        if (!$this->meta[cache][db]) { return; }
322        
323        // trace & debug
324          //print Dumper($this);
325          logp(get_class($this) . "->_loadProxy()");
326          
327      connectdb();      connectdb();
328      $sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'";      $sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'";
329      if ($res = send_sql($sql)) {      if ($res = send_sql($sql)) {
# Line 223  class Data_Driver_Proxy { Line 338  class Data_Driver_Proxy {
338        
339    // TODO: use PEAR here    // TODO: use PEAR here
340    function _saveProxy() {    function _saveProxy() {
341    
342        // FIXME!
343        if (!$this->meta[cache][db]) { return; }
344    
345      logp(get_class($this) . "->_saveProxy()");      logp(get_class($this) . "->_saveProxy()");
346          connectdb();          connectdb();
347          if ($this->payload) {          if ($this->payload) {
# Line 238  class Data_Driver_Proxy { Line 357  class Data_Driver_Proxy {
357    function _loadRemote() {    function _loadRemote() {
358      logp(get_class($this) . "->_loadRemote()");      logp(get_class($this) . "->_loadRemote()");
359            
360      //print Dumper($this->meta);      // trace
361          //print Dumper($this->meta);
362                    
363      // 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)
364            
# Line 274  class Data_Driver_Proxy { Line 394  class Data_Driver_Proxy {
394            logp(get_class($this) . "->_loadRemote: argument 'key' requires 'command'", PEAR_LOG_WARNING);            logp(get_class($this) . "->_loadRemote: argument 'key' requires 'command'", PEAR_LOG_WARNING);
395            return;            return;
396          }          }
397            /*
398          if (!$this->meta[query]) {          if (!$this->meta[query]) {
399            logp(get_class($this) . "->_loadRemote: argument 'key' requires 'query'", PEAR_LOG_WARNING);            logp(get_class($this) . "->_loadRemote: argument 'key' requires 'query'", PEAR_LOG_WARNING);
400            return;            return;
401          }          }
402            */
403          $result = $this->backend->send($this->meta[command], $this->meta[query]);          $result = $this->backend->send($this->meta[command], $this->meta[query]);
404                    
405        }        }

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

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