/[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.2 - (show annotations)
Thu Feb 27 16:30:17 2003 UTC (21 years, 6 months ago) by joko
Branch: MAIN
Changes since 1.1: +37 -6 lines
+ enhanced '_autodetect'
+ added '_check'
+ now throughout returning lifted values by reference

1 <?
2 // -------------------------------------------------------------------------
3 // $Id: Lift.php,v 1.1 2003/02/22 16:20:04 joko Exp $
4 // -------------------------------------------------------------------------
5 // $Log: Lift.php,v $
6 // Revision 1.1 2003/02/22 16:20:04 joko
7 // + initial commit
8 //
9 // -------------------------------------------------------------------------
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
42 if ($metatype) { $this->metatype = $metatype; }
43 $this->_autodetect();
44 $this->_check();
45 }
46
47 function _autodetect() {
48
49 // FIXME: distinguish between is_array and is_hash here!
50 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 $this->vartype = 'hash';
59
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 }
77
78 }
79
80 function &to($level) {
81 $this->_resolve_location($level);
82 //print Dumper($this->actor);
83 //exit;
84 //$result = array( name => 'abc', description => 'def' );
85 $result = &$this->_perform_actor();
86 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 function &_perform_actor() {
106 //$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 ?>

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