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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Sat Mar 8 20:04:59 2003 UTC (21 years, 5 months ago) by root
Branch: MAIN
Changes since 1.4: +22 -8 lines
+ optimized comments for Autodia

1 joko 1.1 <?
2 joko 1.4 /**
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 joko 1.1 // -------------------------------------------------------------------------
12 root 1.5 // $Id: Lift.php,v 1.4 2003/03/08 18:22:23 joko Exp $
13 joko 1.1 // -------------------------------------------------------------------------
14 joko 1.2 // $Log: Lift.php,v $
15 root 1.5 // Revision 1.4 2003/03/08 18:22:23 joko
16     // updated comments: now in phpDocumentor style
17     //
18 joko 1.4 // Revision 1.3 2003/03/03 21:28:11 joko
19     // updated comments
20     //
21 joko 1.3 // Revision 1.2 2003/02/27 16:30:17 joko
22     // + enhanced '_autodetect'
23     // + added '_check'
24     // + now throughout returning lifted values by reference
25     //
26 joko 1.2 // Revision 1.1 2003/02/22 16:20:04 joko
27     // + initial commit
28     //
29 joko 1.1 // -------------------------------------------------------------------------
30    
31    
32    
33    
34 joko 1.4 /**
35     * --- Data::Lift
36     *
37     * <pre>
38     * Data::Lift - Pass data around between various "actors".
39     *
40     * These "actors" are kinda plugin-modules
41     * lying at "locations" and actually mungle the data.
42     *
43     * "Locations" are by now:
44     * x local filesystem
45     * o remote anything
46     *
47     * The "actors" require (by now) to be native php classes
48     * having a method "perform". Please have a look at others
49     * lying in the Data::Lift namespace at org.netfrag.glib to
50     * get a picture of how to implement own "actors".
51     * </pre>
52     *
53     *
54     * @author Andreas Motl <andreas.motl@ilo.de>
55     * @copyright (c) 2003 - All Rights reserved.
56     * @license GNU LGPL (GNU Lesser General Public License)
57     *
58     * @link http://www.netfrag.org/~joko/
59     * @link http://www.gnu.org/licenses/lgpl.txt
60     *
61     * @package org.netfrag.glib
62     * @subpackage Data::Lift
63     * @name Data::Lift
64     *
65     * @link http://cvs.netfrag.org/php/libs/org.netfrag.glib
66     *
67     *
68     * @todo refactor Data::Deep to a plugin module
69     * @todo refactor Data::Encode to a plugin module
70     * @todo combine Data::Lift and Data::Container somehow
71     * @todo integrate with Data::Driver somehow -- proposal:
72 root 1.5 * // $lift = ne w Data::Lift($locator);
73     * // $lift->perform(); // talks to a Data::Driver
74 joko 1.4 *
75     *
76     */
77 joko 1.1 class Data_Lift {
78 root 1.5
79     /**
80     * this is to trick Autodia let understanding "namespaces" in php
81     * unless the pattern can be tweaked by mode (namespace=0|1)
82     * // $this = ne w Data::Lift(&$payload, $options = array());
83     */
84    
85 joko 1.1 var $dblocations;
86     var $actor;
87 root 1.5 var $actor_instance;
88 joko 1.1
89     var $payload;
90     var $vartype;
91     var $metatype;
92    
93     function Data_Lift(&$payload, $options = array()) {
94     $this->_init_locations();
95     //print Dumper($options);
96     //exit;
97     if ($options[metatype]) { $this->metatype = $options[metatype]; }
98     $this->set(&$payload);
99     }
100    
101     function _init_locations() {
102     $this->actor = array();
103     $this->dblocations = array(
104     'bla' => 'blub',
105     );
106     }
107    
108     function set(&$payload, $metatype = '') {
109     $this->payload = &$payload;
110 joko 1.2
111 joko 1.1 if ($metatype) { $this->metatype = $metatype; }
112     $this->_autodetect();
113 joko 1.2 $this->_check();
114 joko 1.1 }
115    
116     function _autodetect() {
117 joko 1.2
118 joko 1.1 // FIXME: distinguish between is_array and is_hash here!
119 joko 1.2 if (is_object($this->payload)) {
120     $this->vartype = 'object';
121     $this->metatype = get_class($this->payload);
122     if ($parent_class = get_parent_class($this->payload)) {
123     $this->metatype = $parent_class;
124     }
125    
126     } elseif (is_array($this->payload)) {
127 joko 1.1 $this->vartype = 'hash';
128 joko 1.2
129     } else {
130     $this->vartype = 'scalar';
131    
132     }
133     }
134    
135     function _check() {
136    
137     $good = $this->vartype && $this->metatype;
138    
139     //print "metatype: " . $this->metatype . "<br>";
140    
141     if (!$good) {
142     print "Data::Lift cannot handle this payload: ";
143     print "(vartype=" . $this->vartype . ", metatype=" . $this->metatype . ")<br/>";
144     print Dumper($this->payload);
145 joko 1.1 }
146 joko 1.2
147 joko 1.1 }
148    
149 joko 1.2 function &to($level) {
150 joko 1.1 $this->_resolve_location($level);
151     //print Dumper($this->actor);
152     //exit;
153     //$result = array( name => 'abc', description => 'def' );
154 joko 1.2 $result = &$this->_perform_actor();
155 joko 1.1 return $result;
156     }
157    
158     function _resolve_location($level) {
159    
160     // location can be resolved by location-table
161     if ($location = $this->dblocations[$level]) {
162     $this->actor = split('/', $location);
163     }
164    
165     // try to automagically resolve location
166     $part = array();
167     array_push($part, $this->vartype);
168     array_push($part, $this->metatype);
169     array_push($part, $level);
170     $this->actor = $part;
171    
172     }
173    
174 joko 1.2 function &_perform_actor() {
175 joko 1.1 //$actor_file = join('/', $this->actor) . '.php';
176     //include($actor_file);
177 root 1.5
178     /**
179     * can do: (this is metadata supplied for Autodia, don't delete!)
180     * $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu()
181     * $this->_actor_instance = new Data_Lift_hash_job_html()
182     */
183    
184 joko 1.1 $actor_name = 'Data/Lift/' . join('/', $this->actor);
185     $actor_object = mkObject($actor_name);
186     return $actor_object->perform($this->payload);
187     }
188    
189     function get() {
190     return $this->payload;
191     }
192    
193     function add($data = array()) {
194     $this->payload = array_merge($this->payload, $data);
195     }
196    
197     }
198    
199 root 1.5 ?>

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