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