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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations)
Sat Apr 19 16:13:52 2003 UTC (21 years, 4 months ago) by jonen
Branch: MAIN
Changes since 1.7: +11 -2 lines
+ added class var '$_hidden_elements' which are passed to 'ExplorerTree' if exists

1 joko 1.1 <?
2 joko 1.4 /**
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 joko 1.1 // -------------------------------------------------------------------------
12 jonen 1.8 // $Id: Lift.php,v 1.7 2003/04/18 15:48:00 joko Exp $
13 joko 1.1 // -------------------------------------------------------------------------
14 joko 1.2 // $Log: Lift.php,v $
15 jonen 1.8 // Revision 1.7 2003/04/18 15:48:00 joko
16     // better error handling: a) croak messages, b) just perform lift module if instance could be created
17     //
18 joko 1.7 // Revision 1.6 2003/03/09 15:49:20 joko
19     // fix towards optimizing autodocumentation:
20     // enriched with metadata to tell autodia how to build object-relationships by discarding the fancy namespacing stuff there
21     //
22 joko 1.6 // Revision 1.5 2003/03/08 20:04:59 root
23     // + optimized comments for Autodia
24     //
25 root 1.5 // Revision 1.4 2003/03/08 18:22:23 joko
26     // updated comments: now in phpDocumentor style
27     //
28 joko 1.4 // Revision 1.3 2003/03/03 21:28:11 joko
29     // updated comments
30     //
31 joko 1.3 // Revision 1.2 2003/02/27 16:30:17 joko
32     // + enhanced '_autodetect'
33     // + added '_check'
34     // + now throughout returning lifted values by reference
35     //
36 joko 1.2 // Revision 1.1 2003/02/22 16:20:04 joko
37     // + initial commit
38     //
39 joko 1.1 // -------------------------------------------------------------------------
40    
41    
42    
43    
44 joko 1.4 /**
45     * --- Data::Lift
46     *
47     * <pre>
48     * Data::Lift - Pass data around between various "actors".
49     *
50     * These "actors" are kinda plugin-modules
51     * lying at "locations" and actually mungle the data.
52     *
53     * "Locations" are by now:
54     * x local filesystem
55     * o remote anything
56     *
57     * The "actors" require (by now) to be native php classes
58     * having a method "perform". Please have a look at others
59     * lying in the Data::Lift namespace at org.netfrag.glib to
60     * get a picture of how to implement own "actors".
61     * </pre>
62     *
63     *
64     * @author Andreas Motl <andreas.motl@ilo.de>
65     * @copyright (c) 2003 - All Rights reserved.
66     * @license GNU LGPL (GNU Lesser General Public License)
67     *
68     * @link http://www.netfrag.org/~joko/
69     * @link http://www.gnu.org/licenses/lgpl.txt
70     *
71     * @package org.netfrag.glib
72 joko 1.6 * @subpackage DataLift
73 joko 1.4 * @name Data::Lift
74     *
75     * @link http://cvs.netfrag.org/php/libs/org.netfrag.glib
76     *
77     *
78     * @todo refactor Data::Deep to a plugin module
79     * @todo refactor Data::Encode to a plugin module
80     * @todo combine Data::Lift and Data::Container somehow
81     * @todo integrate with Data::Driver somehow -- proposal:
82 root 1.5 * // $lift = ne w Data::Lift($locator);
83     * // $lift->perform(); // talks to a Data::Driver
84 joko 1.4 *
85     *
86     */
87 joko 1.1 class Data_Lift {
88 root 1.5
89     /**
90     * this is to trick Autodia let understanding "namespaces" in php
91     * unless the pattern can be tweaked by mode (namespace=0|1)
92     * // $this = ne w Data::Lift(&$payload, $options = array());
93     */
94    
95 joko 1.1 var $dblocations;
96     var $actor;
97 root 1.5 var $actor_instance;
98 joko 1.1
99     var $payload;
100     var $vartype;
101     var $metatype;
102 jonen 1.8 var $_link_args = NULL;
103 joko 1.1
104     function Data_Lift(&$payload, $options = array()) {
105     $this->_init_locations();
106     //print Dumper($options);
107     //exit;
108     if ($options[metatype]) { $this->metatype = $options[metatype]; }
109 jonen 1.8 if ($options[link_args]) { $this->_link_args = $options[link_args]; }
110 joko 1.1 $this->set(&$payload);
111     }
112    
113     function _init_locations() {
114     $this->actor = array();
115     $this->dblocations = array(
116     'bla' => 'blub',
117     );
118     }
119    
120     function set(&$payload, $metatype = '') {
121     $this->payload = &$payload;
122 joko 1.2
123 joko 1.1 if ($metatype) { $this->metatype = $metatype; }
124     $this->_autodetect();
125 joko 1.2 $this->_check();
126 joko 1.1 }
127    
128     function _autodetect() {
129 joko 1.2
130 joko 1.1 // FIXME: distinguish between is_array and is_hash here!
131 joko 1.2 if (is_object($this->payload)) {
132     $this->vartype = 'object';
133     $this->metatype = get_class($this->payload);
134     if ($parent_class = get_parent_class($this->payload)) {
135     $this->metatype = $parent_class;
136     }
137    
138     } elseif (is_array($this->payload)) {
139 joko 1.1 $this->vartype = 'hash';
140 joko 1.2
141     } else {
142     $this->vartype = 'scalar';
143    
144     }
145     }
146    
147     function _check() {
148    
149     $good = $this->vartype && $this->metatype;
150    
151     //print "metatype: " . $this->metatype . "<br>";
152    
153     if (!$good) {
154 joko 1.7 $msg = "Data::Lift cannot handle this payload: ";
155     $msg .= "[vartype=" . $this->vartype . ", metatype=" . $this->metatype . "]<br/>";
156     $msg .= "payload: '" . Dumper($this->payload) . "'";
157     user_error($msg);
158 joko 1.1 }
159 joko 1.2
160 joko 1.1 }
161    
162 joko 1.2 function &to($level) {
163 joko 1.1 $this->_resolve_location($level);
164     //print Dumper($this->actor);
165     //exit;
166     //$result = array( name => 'abc', description => 'def' );
167 joko 1.2 $result = &$this->_perform_actor();
168 joko 1.1 return $result;
169     }
170    
171     function _resolve_location($level) {
172    
173     // location can be resolved by location-table
174     if ($location = $this->dblocations[$level]) {
175     $this->actor = split('/', $location);
176     }
177    
178     // try to automagically resolve location
179     $part = array();
180     array_push($part, $this->vartype);
181     array_push($part, $this->metatype);
182     array_push($part, $level);
183     $this->actor = $part;
184    
185     }
186    
187 joko 1.2 function &_perform_actor() {
188 joko 1.1 //$actor_file = join('/', $this->actor) . '.php';
189     //include($actor_file);
190 root 1.5
191     /**
192 joko 1.6 * <!-- Autodia -->
193 root 1.5 * can do: (this is metadata supplied for Autodia, don't delete!)
194 joko 1.6 * $this->_actor_instance = new Data_Lift_hash_job_html()
195     * $this->_actor_instance = new Data_Lift_hash_tree_PEAR_Tree()
196 root 1.5 * $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu()
197 joko 1.6 * $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu_DHTML()
198     * $this->_actor_instance = new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu_Listbox()
199     *
200 root 1.5 */
201    
202 joko 1.1 $actor_name = 'Data/Lift/' . join('/', $this->actor);
203 joko 1.7 //$actor_name = 'Data::Lift::' . join('::', $this->actor);
204    
205     //$actor_object = mkObject($actor_name);
206     //return $actor_object->perform($this->payload);
207    
208     // fix [2003-04-13]: just perform if instance good
209     //if ($actor_object = php::mkComponent($actor_name)) {
210 joko 1.1 $actor_object = mkObject($actor_name);
211 joko 1.7 if (is_object($actor_object) && method_exists($actor_object, 'perform')) {
212 jonen 1.8 if($actor_name == "Data/Lift/hash/topic/ExplorerTree") {
213     return $actor_object->perform($this->payload, $this->_link_args);
214     } else {
215     return $actor_object->perform($this->payload);
216     }
217 joko 1.7 } else {
218     user_error("Data::Lift could not call method 'perform' on actor object. [actor_name='$actor_name']");
219     //return array();
220     }
221    
222 joko 1.1 }
223    
224     function get() {
225     return $this->payload;
226     }
227    
228     function add($data = array()) {
229     $this->payload = array_merge($this->payload, $data);
230     }
231    
232     }
233    
234 root 1.5 ?>

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