/[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.4 - (hide annotations)
Sat Mar 8 18:22:23 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.3: +59 -25 lines
updated comments: now in phpDocumentor style

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 joko 1.4 // $Id: Lift.php,v 1.3 2003/03/03 21:28:11 joko Exp $
13 joko 1.1 // -------------------------------------------------------------------------
14 joko 1.2 // $Log: Lift.php,v $
15 joko 1.4 // Revision 1.3 2003/03/03 21:28:11 joko
16     // updated comments
17     //
18 joko 1.3 // Revision 1.2 2003/02/27 16:30:17 joko
19     // + enhanced '_autodetect'
20     // + added '_check'
21     // + now throughout returning lifted values by reference
22     //
23 joko 1.2 // Revision 1.1 2003/02/22 16:20:04 joko
24     // + initial commit
25     //
26 joko 1.1 // -------------------------------------------------------------------------
27    
28    
29    
30    
31 joko 1.4 /**
32     * --- Data::Lift
33     *
34     * <pre>
35     * Data::Lift - Pass data around between various "actors".
36     *
37     * These "actors" are kinda plugin-modules
38     * lying at "locations" and actually mungle the data.
39     *
40     * "Locations" are by now:
41     * x local filesystem
42     * o remote anything
43     *
44     * The "actors" require (by now) to be native php classes
45     * having a method "perform". Please have a look at others
46     * lying in the Data::Lift namespace at org.netfrag.glib to
47     * get a picture of how to implement own "actors".
48     * </pre>
49     *
50     *
51     * @author Andreas Motl <andreas.motl@ilo.de>
52     * @copyright (c) 2003 - All Rights reserved.
53     * @license GNU LGPL (GNU Lesser General Public License)
54     *
55     * @link http://www.netfrag.org/~joko/
56     * @link http://www.gnu.org/licenses/lgpl.txt
57     *
58     * @package org.netfrag.glib
59     * @subpackage Data::Lift
60     * @name Data::Lift
61     *
62     * @link http://cvs.netfrag.org/php/libs/org.netfrag.glib
63     *
64     *
65     * @todo refactor Data::Deep to a plugin module
66     * @todo refactor Data::Encode to a plugin module
67     * @todo combine Data::Lift and Data::Container somehow
68     * @todo integrate with Data::Driver somehow -- proposal:
69     * $lift = new Data::Lift($locator);
70     * $lift->perform(); // talks to a Data::Driver
71     *
72     * can do:
73     * new Data_Lift_object_tree_common_PEAR_HTML_TreeMenu
74     * new Data_Lift_hash_job_html
75     *
76     */
77 joko 1.1 class Data_Lift {
78    
79     var $dblocations;
80     var $actor;
81    
82     var $payload;
83     var $vartype;
84     var $metatype;
85    
86     function Data_Lift(&$payload, $options = array()) {
87     $this->_init_locations();
88     //print Dumper($options);
89     //exit;
90     if ($options[metatype]) { $this->metatype = $options[metatype]; }
91     $this->set(&$payload);
92     }
93    
94     function _init_locations() {
95     $this->actor = array();
96     $this->dblocations = array(
97     'bla' => 'blub',
98     );
99     }
100    
101     function set(&$payload, $metatype = '') {
102     $this->payload = &$payload;
103 joko 1.2
104 joko 1.1 if ($metatype) { $this->metatype = $metatype; }
105     $this->_autodetect();
106 joko 1.2 $this->_check();
107 joko 1.1 }
108    
109     function _autodetect() {
110 joko 1.2
111 joko 1.1 // FIXME: distinguish between is_array and is_hash here!
112 joko 1.2 if (is_object($this->payload)) {
113     $this->vartype = 'object';
114     $this->metatype = get_class($this->payload);
115     if ($parent_class = get_parent_class($this->payload)) {
116     $this->metatype = $parent_class;
117     }
118    
119     } elseif (is_array($this->payload)) {
120 joko 1.1 $this->vartype = 'hash';
121 joko 1.2
122     } else {
123     $this->vartype = 'scalar';
124    
125     }
126     }
127    
128     function _check() {
129    
130     $good = $this->vartype && $this->metatype;
131    
132     //print "metatype: " . $this->metatype . "<br>";
133    
134     if (!$good) {
135     print "Data::Lift cannot handle this payload: ";
136     print "(vartype=" . $this->vartype . ", metatype=" . $this->metatype . ")<br/>";
137     print Dumper($this->payload);
138 joko 1.1 }
139 joko 1.2
140 joko 1.1 }
141    
142 joko 1.2 function &to($level) {
143 joko 1.1 $this->_resolve_location($level);
144     //print Dumper($this->actor);
145     //exit;
146     //$result = array( name => 'abc', description => 'def' );
147 joko 1.2 $result = &$this->_perform_actor();
148 joko 1.1 return $result;
149     }
150    
151     function _resolve_location($level) {
152    
153     // location can be resolved by location-table
154     if ($location = $this->dblocations[$level]) {
155     $this->actor = split('/', $location);
156     }
157    
158     // try to automagically resolve location
159     $part = array();
160     array_push($part, $this->vartype);
161     array_push($part, $this->metatype);
162     array_push($part, $level);
163     $this->actor = $part;
164    
165     }
166    
167 joko 1.2 function &_perform_actor() {
168 joko 1.1 //$actor_file = join('/', $this->actor) . '.php';
169     //include($actor_file);
170     $actor_name = 'Data/Lift/' . join('/', $this->actor);
171     $actor_object = mkObject($actor_name);
172     return $actor_object->perform($this->payload);
173     }
174    
175     function get() {
176     return $this->payload;
177     }
178    
179     function add($data = array()) {
180     $this->payload = array_merge($this->payload, $data);
181     }
182    
183     }
184    
185     ?>

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