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

Diff of /nfo/php/libs/org.netfrag.glib/Data/Lift.php

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

revision 1.1 by joko, Sat Feb 22 16:20:04 2003 UTC revision 1.6 by joko, Sun Mar 9 15:49:20 2003 UTC
# Line 1  Line 1 
1  <?  <?
2    /**
3     * This file contains the Data::Lift component.
4     *
5     * @author Andreas Motl <andreas.motl@ilo.de>
6     * @package org.netfrag.glib
7     * @name Data::Lift
8     *
9     */
10    
11  //    -------------------------------------------------------------------------  //    -------------------------------------------------------------------------
12  //    $Id$  //    $Id$
13  //    -------------------------------------------------------------------------  //    -------------------------------------------------------------------------
14  //    $Log$  //    $Log$
15    //    Revision 1.6  2003/03/09 15:49:20  joko
16    //    fix towards optimizing autodocumentation:
17    //    enriched with metadata to tell autodia how to build object-relationships by discarding the fancy namespacing stuff there
18    //
19    //    Revision 1.5  2003/03/08 20:04:59  root
20    //    + optimized comments for Autodia
21    //
22    //    Revision 1.4  2003/03/08 18:22:23  joko
23    //    updated comments: now in phpDocumentor style
24    //
25    //    Revision 1.3  2003/03/03 21:28:11  joko
26    //    updated comments
27    //
28    //    Revision 1.2  2003/02/27 16:30:17  joko
29    //    + enhanced '_autodetect'
30    //    + added '_check'
31    //    + now throughout returning lifted values by reference
32    //
33  //    Revision 1.1  2003/02/22 16:20:04  joko  //    Revision 1.1  2003/02/22 16:20:04  joko
34  //    + initial commit  //    + initial commit
35  //  //
36  //    -------------------------------------------------------------------------  //    -------------------------------------------------------------------------
37    
38    
 //    Data::Lift  -  Pass data around between locations doing operations on it  
39    
40    
41    /**
42     * --- Data::Lift
43     *
44     * <pre>
45     *    Data::Lift  -  Pass data around between various "actors".
46     *
47     *    These "actors" are kinda plugin-modules
48     *    lying at "locations" and actually mungle the data.
49     *
50     *    "Locations" are by now:
51     *      x local filesystem
52     *      o remote anything
53     *
54     *    The "actors" require (by now) to be native php classes
55     *    having a method "perform". Please have a look at others
56     *    lying in the Data::Lift namespace at org.netfrag.glib to
57     *    get a picture of how to implement own "actors".
58     * </pre>
59     *
60     *
61     * @author Andreas Motl <andreas.motl@ilo.de>
62     * @copyright (c) 2003 - All Rights reserved.
63     * @license GNU LGPL (GNU Lesser General Public License)
64     *
65     * @link http://www.netfrag.org/~joko/
66     * @link http://www.gnu.org/licenses/lgpl.txt
67     *
68     * @package org.netfrag.glib
69     * @subpackage DataLift
70     * @name Data::Lift
71     *
72     * @link http://cvs.netfrag.org/php/libs/org.netfrag.glib
73     *
74     *
75     * @todo refactor Data::Deep to a plugin module
76     * @todo refactor Data::Encode to a plugin module
77     * @todo combine Data::Lift and Data::Container somehow
78     * @todo integrate with Data::Driver somehow  --  proposal:
79     *         //  $lift = ne w Data::Lift($locator);
80     *         //  $lift->perform();     // talks to a Data::Driver
81     *
82     *
83     */
84  class Data_Lift {  class Data_Lift {
85      
86      /**
87       * this is to trick Autodia let understanding "namespaces" in php
88       * unless the pattern can be tweaked by mode (namespace=0|1)
89       * // $this = ne w Data::Lift(&$payload, $options = array());
90       */
91    
92    var $dblocations;    var $dblocations;
93    var $actor;    var $actor;
94      var $actor_instance;
95    
96    var $payload;    var $payload;
97    var $vartype;    var $vartype;
# Line 38  class Data_Lift { Line 114  class Data_Lift {
114        
115    function set(&$payload, $metatype = '') {    function set(&$payload, $metatype = '') {
116      $this->payload = &$payload;      $this->payload = &$payload;
117        
118      if ($metatype) { $this->metatype = $metatype; }      if ($metatype) { $this->metatype = $metatype; }
119      $this->_autodetect();      $this->_autodetect();
120        $this->_check();
121    }    }
122        
123    function _autodetect() {    function _autodetect() {
124    
125      // FIXME: distinguish between is_array and is_hash here!      // FIXME: distinguish between is_array and is_hash here!
126      if (is_array($this->payload)) {      if (is_object($this->payload)) {
127          $this->vartype = 'object';
128          $this->metatype = get_class($this->payload);
129          if ($parent_class = get_parent_class($this->payload)) {
130            $this->metatype = $parent_class;
131          }
132    
133        } elseif (is_array($this->payload)) {
134        $this->vartype = 'hash';        $this->vartype = 'hash';
135    
136        } else {
137          $this->vartype = 'scalar';
138        
139      }      }
140    }    }
141        
142    function to($level) {    function _check() {
143    
144        $good = $this->vartype && $this->metatype;
145        
146        //print "metatype: " . $this->metatype . "<br>";
147        
148        if (!$good) {
149          print "Data::Lift cannot handle this payload: ";
150          print "(vartype=" . $this->vartype . ", metatype=" . $this->metatype . ")<br/>";
151          print Dumper($this->payload);
152        }
153        
154      }
155      
156      function &to($level) {
157      $this->_resolve_location($level);      $this->_resolve_location($level);
158      //print Dumper($this->actor);      //print Dumper($this->actor);
159      //exit;      //exit;
160      //$result = array( name => 'abc', description => 'def' );      //$result = array( name => 'abc', description => 'def' );
161      $result = $this->_perform_actor();      $result = &$this->_perform_actor();
162      return $result;      return $result;
163    }    }
164        
# Line 74  class Data_Lift { Line 178  class Data_Lift {
178            
179    }    }
180    
181    function _perform_actor() {    function &_perform_actor() {
182      //$actor_file = join('/', $this->actor) . '.php';      //$actor_file = join('/', $this->actor) . '.php';
183      //include($actor_file);      //include($actor_file);
184    
185        /**
186         * <!-- Autodia -->
187         * can do: (this is metadata supplied for Autodia, don't delete!)
188         *  $this->_actor_instance = new Data_Lift_hash_job_html()
189         *  $this->_actor_instance = new Data_Lift_hash_tree_PEAR_Tree()
190         *  $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu()
191         *  $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu_DHTML()
192         *  $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu_Listbox()
193         *
194         */
195    
196      $actor_name = 'Data/Lift/' . join('/', $this->actor);      $actor_name = 'Data/Lift/' . join('/', $this->actor);
197      $actor_object = mkObject($actor_name);      $actor_object = mkObject($actor_name);
198      return $actor_object->perform($this->payload);      return $actor_object->perform($this->payload);
# Line 92  class Data_Lift { Line 208  class Data_Lift {
208    
209  }  }
210    
 ?>  
211    ?>

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

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