1 |
joko |
1.1 |
<? |
2 |
|
|
// ------------------------------------------------------------------------- |
3 |
joko |
1.2 |
// $Id: Lift.php,v 1.1 2003/02/22 16:20:04 joko Exp $ |
4 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
5 |
joko |
1.2 |
// $Log: Lift.php,v $ |
6 |
|
|
// Revision 1.1 2003/02/22 16:20:04 joko |
7 |
|
|
// + initial commit |
8 |
|
|
// |
9 |
joko |
1.1 |
// ------------------------------------------------------------------------- |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
// Data::Lift - Pass data around between locations doing operations on it |
13 |
|
|
|
14 |
|
|
|
15 |
|
|
class Data_Lift { |
16 |
|
|
|
17 |
|
|
var $dblocations; |
18 |
|
|
var $actor; |
19 |
|
|
|
20 |
|
|
var $payload; |
21 |
|
|
var $vartype; |
22 |
|
|
var $metatype; |
23 |
|
|
|
24 |
|
|
function Data_Lift(&$payload, $options = array()) { |
25 |
|
|
$this->_init_locations(); |
26 |
|
|
//print Dumper($options); |
27 |
|
|
//exit; |
28 |
|
|
if ($options[metatype]) { $this->metatype = $options[metatype]; } |
29 |
|
|
$this->set(&$payload); |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
function _init_locations() { |
33 |
|
|
$this->actor = array(); |
34 |
|
|
$this->dblocations = array( |
35 |
|
|
'bla' => 'blub', |
36 |
|
|
); |
37 |
|
|
} |
38 |
|
|
|
39 |
|
|
function set(&$payload, $metatype = '') { |
40 |
|
|
$this->payload = &$payload; |
41 |
joko |
1.2 |
|
42 |
joko |
1.1 |
if ($metatype) { $this->metatype = $metatype; } |
43 |
|
|
$this->_autodetect(); |
44 |
joko |
1.2 |
$this->_check(); |
45 |
joko |
1.1 |
} |
46 |
|
|
|
47 |
|
|
function _autodetect() { |
48 |
joko |
1.2 |
|
49 |
joko |
1.1 |
// FIXME: distinguish between is_array and is_hash here! |
50 |
joko |
1.2 |
if (is_object($this->payload)) { |
51 |
|
|
$this->vartype = 'object'; |
52 |
|
|
$this->metatype = get_class($this->payload); |
53 |
|
|
if ($parent_class = get_parent_class($this->payload)) { |
54 |
|
|
$this->metatype = $parent_class; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
} elseif (is_array($this->payload)) { |
58 |
joko |
1.1 |
$this->vartype = 'hash'; |
59 |
joko |
1.2 |
|
60 |
|
|
} else { |
61 |
|
|
$this->vartype = 'scalar'; |
62 |
|
|
|
63 |
|
|
} |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
function _check() { |
67 |
|
|
|
68 |
|
|
$good = $this->vartype && $this->metatype; |
69 |
|
|
|
70 |
|
|
//print "metatype: " . $this->metatype . "<br>"; |
71 |
|
|
|
72 |
|
|
if (!$good) { |
73 |
|
|
print "Data::Lift cannot handle this payload: "; |
74 |
|
|
print "(vartype=" . $this->vartype . ", metatype=" . $this->metatype . ")<br/>"; |
75 |
|
|
print Dumper($this->payload); |
76 |
joko |
1.1 |
} |
77 |
joko |
1.2 |
|
78 |
joko |
1.1 |
} |
79 |
|
|
|
80 |
joko |
1.2 |
function &to($level) { |
81 |
joko |
1.1 |
$this->_resolve_location($level); |
82 |
|
|
//print Dumper($this->actor); |
83 |
|
|
//exit; |
84 |
|
|
//$result = array( name => 'abc', description => 'def' ); |
85 |
joko |
1.2 |
$result = &$this->_perform_actor(); |
86 |
joko |
1.1 |
return $result; |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
function _resolve_location($level) { |
90 |
|
|
|
91 |
|
|
// location can be resolved by location-table |
92 |
|
|
if ($location = $this->dblocations[$level]) { |
93 |
|
|
$this->actor = split('/', $location); |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
// try to automagically resolve location |
97 |
|
|
$part = array(); |
98 |
|
|
array_push($part, $this->vartype); |
99 |
|
|
array_push($part, $this->metatype); |
100 |
|
|
array_push($part, $level); |
101 |
|
|
$this->actor = $part; |
102 |
|
|
|
103 |
|
|
} |
104 |
|
|
|
105 |
joko |
1.2 |
function &_perform_actor() { |
106 |
joko |
1.1 |
//$actor_file = join('/', $this->actor) . '.php'; |
107 |
|
|
//include($actor_file); |
108 |
|
|
$actor_name = 'Data/Lift/' . join('/', $this->actor); |
109 |
|
|
$actor_object = mkObject($actor_name); |
110 |
|
|
return $actor_object->perform($this->payload); |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
function get() { |
114 |
|
|
return $this->payload; |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
function add($data = array()) { |
118 |
|
|
$this->payload = array_merge($this->payload, $data); |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
?> |