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.4 2003/03/08 18:22:23 joko |
16 |
|
// updated comments: now in phpDocumentor style |
17 |
|
// |
18 |
|
// Revision 1.3 2003/03/03 21:28:11 joko |
19 |
|
// updated comments |
20 |
|
// |
21 |
|
// 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 |
// Revision 1.1 2003/02/22 16:20:04 joko |
// Revision 1.1 2003/02/22 16:20:04 joko |
27 |
// + initial commit |
// + initial commit |
28 |
// |
// |
29 |
// ------------------------------------------------------------------------- |
// ------------------------------------------------------------------------- |
30 |
|
|
31 |
|
|
|
// Data::Lift - Pass data around between locations doing operations on it |
|
32 |
|
|
33 |
|
|
34 |
|
/** |
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 |
|
* $lift = new Data::Lift($locator); |
73 |
|
* $lift->perform(); // talks to a Data::Driver |
74 |
|
* |
75 |
|
* can do: |
76 |
|
* new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu |
77 |
|
* new Data_Lift_hash_job_html |
78 |
|
* |
79 |
|
*/ |
80 |
class Data_Lift { |
class Data_Lift { |
81 |
|
|
82 |
var $dblocations; |
var $dblocations; |
103 |
|
|
104 |
function set(&$payload, $metatype = '') { |
function set(&$payload, $metatype = '') { |
105 |
$this->payload = &$payload; |
$this->payload = &$payload; |
106 |
|
|
107 |
if ($metatype) { $this->metatype = $metatype; } |
if ($metatype) { $this->metatype = $metatype; } |
108 |
$this->_autodetect(); |
$this->_autodetect(); |
109 |
|
$this->_check(); |
110 |
} |
} |
111 |
|
|
112 |
function _autodetect() { |
function _autodetect() { |
113 |
|
|
114 |
// FIXME: distinguish between is_array and is_hash here! |
// FIXME: distinguish between is_array and is_hash here! |
115 |
if (is_array($this->payload)) { |
if (is_object($this->payload)) { |
116 |
|
$this->vartype = 'object'; |
117 |
|
$this->metatype = get_class($this->payload); |
118 |
|
if ($parent_class = get_parent_class($this->payload)) { |
119 |
|
$this->metatype = $parent_class; |
120 |
|
} |
121 |
|
|
122 |
|
} elseif (is_array($this->payload)) { |
123 |
$this->vartype = 'hash'; |
$this->vartype = 'hash'; |
124 |
|
|
125 |
|
} else { |
126 |
|
$this->vartype = 'scalar'; |
127 |
|
|
128 |
|
} |
129 |
|
} |
130 |
|
|
131 |
|
function _check() { |
132 |
|
|
133 |
|
$good = $this->vartype && $this->metatype; |
134 |
|
|
135 |
|
//print "metatype: " . $this->metatype . "<br>"; |
136 |
|
|
137 |
|
if (!$good) { |
138 |
|
print "Data::Lift cannot handle this payload: "; |
139 |
|
print "(vartype=" . $this->vartype . ", metatype=" . $this->metatype . ")<br/>"; |
140 |
|
print Dumper($this->payload); |
141 |
} |
} |
142 |
|
|
143 |
} |
} |
144 |
|
|
145 |
function to($level) { |
function &to($level) { |
146 |
$this->_resolve_location($level); |
$this->_resolve_location($level); |
147 |
//print Dumper($this->actor); |
//print Dumper($this->actor); |
148 |
//exit; |
//exit; |
149 |
//$result = array( name => 'abc', description => 'def' ); |
//$result = array( name => 'abc', description => 'def' ); |
150 |
$result = $this->_perform_actor(); |
$result = &$this->_perform_actor(); |
151 |
return $result; |
return $result; |
152 |
} |
} |
153 |
|
|
167 |
|
|
168 |
} |
} |
169 |
|
|
170 |
function _perform_actor() { |
function &_perform_actor() { |
171 |
//$actor_file = join('/', $this->actor) . '.php'; |
//$actor_file = join('/', $this->actor) . '.php'; |
172 |
//include($actor_file); |
//include($actor_file); |
173 |
$actor_name = 'Data/Lift/' . join('/', $this->actor); |
$actor_name = 'Data/Lift/' . join('/', $this->actor); |