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