/[cvs]/nfo/php/libs/org.netfrag.glib/Data/Lift.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.glib/Data/Lift.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Mon Mar 3 21:28:11 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.2: +30 -2 lines
updated comments

1 <?
2 // -------------------------------------------------------------------------
3 // $Id: Lift.php,v 1.2 2003/02/27 16:30:17 joko Exp $
4 // -------------------------------------------------------------------------
5 // $Log: Lift.php,v $
6 // Revision 1.2 2003/02/27 16:30:17 joko
7 // + enhanced '_autodetect'
8 // + added '_check'
9 // + now throughout returning lifted values by reference
10 //
11 // Revision 1.1 2003/02/22 16:20:04 joko
12 // + initial commit
13 //
14 // -------------------------------------------------------------------------
15
16
17 // Data::Lift - Pass data around between various "actors".
18 //
19 // These "actors" are kinda plugin-modules
20 // lying at "locations" and actually mungle the data.
21 //
22 // "Locations" are by now:
23 // x local filesystem
24 // o remote anything
25 //
26 // The "actors" require (by now) to be native php classes
27 // having a method "perform". Please have a look at others
28 // lying in the Data::Lift namespace at org.netfrag.glib to
29 // get a picture of how to implement own "actors".
30 //
31 // @url: http://cvs.netfrag.org/php/libs/org.netfrag.glib
32 //
33 // TODO:
34 // o refactor Data::Deep to a plugin module
35 // o refactor Data::Encode to a plugin module
36 // o combine Data::Lift and Data::Container somehow
37 // o integrate with Data::Driver somehow -- proposal:
38 // $lift = new Data::Lift($locator);
39 // $lift->perform(); // talks to a Data::Driver
40 //
41
42
43 class Data_Lift {
44
45 var $dblocations;
46 var $actor;
47
48 var $payload;
49 var $vartype;
50 var $metatype;
51
52 function Data_Lift(&$payload, $options = array()) {
53 $this->_init_locations();
54 //print Dumper($options);
55 //exit;
56 if ($options[metatype]) { $this->metatype = $options[metatype]; }
57 $this->set(&$payload);
58 }
59
60 function _init_locations() {
61 $this->actor = array();
62 $this->dblocations = array(
63 'bla' => 'blub',
64 );
65 }
66
67 function set(&$payload, $metatype = '') {
68 $this->payload = &$payload;
69
70 if ($metatype) { $this->metatype = $metatype; }
71 $this->_autodetect();
72 $this->_check();
73 }
74
75 function _autodetect() {
76
77 // FIXME: distinguish between is_array and is_hash here!
78 if (is_object($this->payload)) {
79 $this->vartype = 'object';
80 $this->metatype = get_class($this->payload);
81 if ($parent_class = get_parent_class($this->payload)) {
82 $this->metatype = $parent_class;
83 }
84
85 } elseif (is_array($this->payload)) {
86 $this->vartype = 'hash';
87
88 } else {
89 $this->vartype = 'scalar';
90
91 }
92 }
93
94 function _check() {
95
96 $good = $this->vartype && $this->metatype;
97
98 //print "metatype: " . $this->metatype . "<br>";
99
100 if (!$good) {
101 print "Data::Lift cannot handle this payload: ";
102 print "(vartype=" . $this->vartype . ", metatype=" . $this->metatype . ")<br/>";
103 print Dumper($this->payload);
104 }
105
106 }
107
108 function &to($level) {
109 $this->_resolve_location($level);
110 //print Dumper($this->actor);
111 //exit;
112 //$result = array( name => 'abc', description => 'def' );
113 $result = &$this->_perform_actor();
114 return $result;
115 }
116
117 function _resolve_location($level) {
118
119 // location can be resolved by location-table
120 if ($location = $this->dblocations[$level]) {
121 $this->actor = split('/', $location);
122 }
123
124 // try to automagically resolve location
125 $part = array();
126 array_push($part, $this->vartype);
127 array_push($part, $this->metatype);
128 array_push($part, $level);
129 $this->actor = $part;
130
131 }
132
133 function &_perform_actor() {
134 //$actor_file = join('/', $this->actor) . '.php';
135 //include($actor_file);
136 $actor_name = 'Data/Lift/' . join('/', $this->actor);
137 $actor_object = mkObject($actor_name);
138 return $actor_object->perform($this->payload);
139 }
140
141 function get() {
142 return $this->payload;
143 }
144
145 function add($data = array()) {
146 $this->payload = array_merge($this->payload, $data);
147 }
148
149 }
150
151 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed