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 |
joko |
1.7 |
// $Id: Lift.php,v 1.6 2003/03/09 15:49:20 joko Exp $ |
13 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
14 |
joko |
1.2 |
// $Log: Lift.php,v $ |
15 |
joko |
1.7 |
// 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 |
joko |
1.6 |
// Revision 1.5 2003/03/08 20:04:59 root |
20 |
|
|
// + optimized comments for Autodia |
21 |
|
|
// |
22 |
root |
1.5 |
// Revision 1.4 2003/03/08 18:22:23 joko |
23 |
|
|
// updated comments: now in phpDocumentor style |
24 |
|
|
// |
25 |
joko |
1.4 |
// Revision 1.3 2003/03/03 21:28:11 joko |
26 |
|
|
// updated comments |
27 |
|
|
// |
28 |
joko |
1.3 |
// 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 |
joko |
1.2 |
// Revision 1.1 2003/02/22 16:20:04 joko |
34 |
|
|
// + initial commit |
35 |
|
|
// |
36 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
joko |
1.4 |
/** |
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 |
joko |
1.6 |
* @subpackage DataLift |
70 |
joko |
1.4 |
* @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 |
root |
1.5 |
* // $lift = ne w Data::Lift($locator); |
80 |
|
|
* // $lift->perform(); // talks to a Data::Driver |
81 |
joko |
1.4 |
* |
82 |
|
|
* |
83 |
|
|
*/ |
84 |
joko |
1.1 |
class Data_Lift { |
85 |
root |
1.5 |
|
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 |
joko |
1.1 |
var $dblocations; |
93 |
|
|
var $actor; |
94 |
root |
1.5 |
var $actor_instance; |
95 |
joko |
1.1 |
|
96 |
|
|
var $payload; |
97 |
|
|
var $vartype; |
98 |
|
|
var $metatype; |
99 |
|
|
|
100 |
|
|
function Data_Lift(&$payload, $options = array()) { |
101 |
|
|
$this->_init_locations(); |
102 |
|
|
//print Dumper($options); |
103 |
|
|
//exit; |
104 |
|
|
if ($options[metatype]) { $this->metatype = $options[metatype]; } |
105 |
|
|
$this->set(&$payload); |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
function _init_locations() { |
109 |
|
|
$this->actor = array(); |
110 |
|
|
$this->dblocations = array( |
111 |
|
|
'bla' => 'blub', |
112 |
|
|
); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
|
function set(&$payload, $metatype = '') { |
116 |
|
|
$this->payload = &$payload; |
117 |
joko |
1.2 |
|
118 |
joko |
1.1 |
if ($metatype) { $this->metatype = $metatype; } |
119 |
|
|
$this->_autodetect(); |
120 |
joko |
1.2 |
$this->_check(); |
121 |
joko |
1.1 |
} |
122 |
|
|
|
123 |
|
|
function _autodetect() { |
124 |
joko |
1.2 |
|
125 |
joko |
1.1 |
// FIXME: distinguish between is_array and is_hash here! |
126 |
joko |
1.2 |
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 |
joko |
1.1 |
$this->vartype = 'hash'; |
135 |
joko |
1.2 |
|
136 |
|
|
} else { |
137 |
|
|
$this->vartype = 'scalar'; |
138 |
|
|
|
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
function _check() { |
143 |
|
|
|
144 |
|
|
$good = $this->vartype && $this->metatype; |
145 |
|
|
|
146 |
|
|
//print "metatype: " . $this->metatype . "<br>"; |
147 |
|
|
|
148 |
|
|
if (!$good) { |
149 |
joko |
1.7 |
$msg = "Data::Lift cannot handle this payload: "; |
150 |
|
|
$msg .= "[vartype=" . $this->vartype . ", metatype=" . $this->metatype . "]<br/>"; |
151 |
|
|
$msg .= "payload: '" . Dumper($this->payload) . "'"; |
152 |
|
|
user_error($msg); |
153 |
joko |
1.1 |
} |
154 |
joko |
1.2 |
|
155 |
joko |
1.1 |
} |
156 |
|
|
|
157 |
joko |
1.2 |
function &to($level) { |
158 |
joko |
1.1 |
$this->_resolve_location($level); |
159 |
|
|
//print Dumper($this->actor); |
160 |
|
|
//exit; |
161 |
|
|
//$result = array( name => 'abc', description => 'def' ); |
162 |
joko |
1.2 |
$result = &$this->_perform_actor(); |
163 |
joko |
1.1 |
return $result; |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
function _resolve_location($level) { |
167 |
|
|
|
168 |
|
|
// location can be resolved by location-table |
169 |
|
|
if ($location = $this->dblocations[$level]) { |
170 |
|
|
$this->actor = split('/', $location); |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
// try to automagically resolve location |
174 |
|
|
$part = array(); |
175 |
|
|
array_push($part, $this->vartype); |
176 |
|
|
array_push($part, $this->metatype); |
177 |
|
|
array_push($part, $level); |
178 |
|
|
$this->actor = $part; |
179 |
|
|
|
180 |
|
|
} |
181 |
|
|
|
182 |
joko |
1.2 |
function &_perform_actor() { |
183 |
joko |
1.1 |
//$actor_file = join('/', $this->actor) . '.php'; |
184 |
|
|
//include($actor_file); |
185 |
root |
1.5 |
|
186 |
|
|
/** |
187 |
joko |
1.6 |
* <!-- Autodia --> |
188 |
root |
1.5 |
* can do: (this is metadata supplied for Autodia, don't delete!) |
189 |
joko |
1.6 |
* $this->_actor_instance = new Data_Lift_hash_job_html() |
190 |
|
|
* $this->_actor_instance = new Data_Lift_hash_tree_PEAR_Tree() |
191 |
root |
1.5 |
* $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu() |
192 |
joko |
1.6 |
* $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu_DHTML() |
193 |
|
|
* $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu_Listbox() |
194 |
|
|
* |
195 |
root |
1.5 |
*/ |
196 |
|
|
|
197 |
joko |
1.1 |
$actor_name = 'Data/Lift/' . join('/', $this->actor); |
198 |
joko |
1.7 |
//$actor_name = 'Data::Lift::' . join('::', $this->actor); |
199 |
|
|
|
200 |
|
|
//$actor_object = mkObject($actor_name); |
201 |
|
|
//return $actor_object->perform($this->payload); |
202 |
|
|
|
203 |
|
|
// fix [2003-04-13]: just perform if instance good |
204 |
|
|
//if ($actor_object = php::mkComponent($actor_name)) { |
205 |
joko |
1.1 |
$actor_object = mkObject($actor_name); |
206 |
joko |
1.7 |
if (is_object($actor_object) && method_exists($actor_object, 'perform')) { |
207 |
|
|
return $actor_object->perform($this->payload); |
208 |
|
|
} else { |
209 |
|
|
user_error("Data::Lift could not call method 'perform' on actor object. [actor_name='$actor_name']"); |
210 |
|
|
//return array(); |
211 |
|
|
} |
212 |
|
|
|
213 |
joko |
1.1 |
} |
214 |
|
|
|
215 |
|
|
function get() { |
216 |
|
|
return $this->payload; |
217 |
|
|
} |
218 |
|
|
|
219 |
|
|
function add($data = array()) { |
220 |
|
|
$this->payload = array_merge($this->payload, $data); |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
} |
224 |
|
|
|
225 |
root |
1.5 |
?> |