1 |
<?php |
<?php |
2 |
/** |
/** |
3 |
* This file contains the GenericDataSource child class |
* This file contains the GenericDataSource child class |
|
* that may use arbitrary code modules as database handlers. |
|
|
* It's aims are to get together: |
|
|
* o phpHtmlLibs "source-handlers" |
|
|
* o PEAR's database handlers |
|
|
* o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server) |
|
4 |
* |
* |
5 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
* @package phpHtmlLib |
* @package org.netfrag.glib |
7 |
* @module GenericDataSource |
* @name DataSource::Generic |
8 |
* |
* |
9 |
*/ |
*/ |
10 |
|
|
11 |
/** |
/** |
12 |
|
* Cvs-Log: |
13 |
|
* |
14 |
* $Id$ |
* $Id$ |
15 |
* |
* |
16 |
* $Log$ |
* $Log$ |
17 |
|
* Revision 1.26 2003/12/14 01:53:42 jonen |
18 |
|
* implemented 'SELECT' mode for selecting existing object-refereneces as child-nodes |
19 |
|
* |
20 |
|
* Revision 1.25 2003/11/17 18:01:03 jonen |
21 |
|
* bugfix: php cannot use perl-syntax!! ;-) |
22 |
|
* |
23 |
|
* Revision 1.23 2003/07/14 10:02:32 jonen |
24 |
|
* removed debug dumper |
25 |
|
* |
26 |
|
* Revision 1.22 2003/06/06 04:25:45 joko |
27 |
|
* fix: query args get encapsulated once more |
28 |
|
* |
29 |
|
* Revision 1.21 2003/05/10 18:14:50 jonen |
30 |
|
* + implements 'create' of item (query mapping part) |
31 |
|
* |
32 |
|
* Revision 1.20 2003/04/19 16:07:15 jonen |
33 |
|
* + added '_query[list_meta]' at 'queryData' needed for meta query args |
34 |
|
* (e.g. at UserManagment) |
35 |
|
* |
36 |
|
* Revision 1.19 2003/04/18 15:40:51 joko |
37 |
|
* NEW: tree data handling |
38 |
|
* introduced new adapter: DataSource::Adapter::Free |
39 |
|
* enhanced datasource_handler_buildoptions: now handles a) case 'tree' b) _query[filter] |
40 |
|
* |
41 |
|
* Revision 1.18 2003/04/11 00:55:49 joko |
42 |
|
* updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete' |
43 |
|
* |
44 |
|
* Revision 1.17 2003/04/09 02:07:33 joko |
45 |
|
* CHANGE: renamed key 'classname' through 'nodename' |
46 |
|
* |
47 |
|
* Revision 1.16 2003/04/08 17:55:20 joko |
48 |
|
* CHANGE: renamed property 'datasource' to 'transport' |
49 |
|
* NEW: new case 'method' in 'function datasource_handler_buildoptions' |
50 |
|
* minor fixes: updated logging/debugging messages |
51 |
|
* |
52 |
|
* Revision 1.15 2003/04/06 04:46:33 joko |
53 |
|
* renamed linking function |
54 |
|
* mozilla fixes |
55 |
|
* |
56 |
|
* Revision 1.14 2003/04/04 21:19:21 joko |
57 |
|
* modified exception handling (enhanced, purged redundant code) |
58 |
|
* |
59 |
|
* Revision 1.13 2003/04/04 02:37:14 jonen |
60 |
|
* _query[action] == write |
61 |
|
* |
62 |
|
* Revision 1.12 2003/03/29 08:00:48 joko |
63 |
|
* modified ErrorBoxing |
64 |
|
* |
65 |
|
* Revision 1.11 2003/03/28 06:45:26 joko |
66 |
|
* VERBOSE mode |
67 |
|
* |
68 |
|
* Revision 1.10 2003/03/28 03:01:02 joko |
69 |
|
* more fancy debugging-output |
70 |
|
* |
71 |
|
* Revision 1.9 2003/03/27 16:24:26 jonen |
72 |
|
* + mugled namespace |
73 |
|
* + added enhanced 'queryData' |
74 |
|
* |
75 |
|
* Revision 1.8 2003/03/20 07:22:14 jonen |
76 |
|
* + modified case 'object' to 'objects' |
77 |
|
* (cause its loads all *objects* of a given classname) |
78 |
|
* |
79 |
|
* Revision 1.7 2003/03/11 01:43:00 joko |
80 |
|
* + fixed metadata for phpDocumentor |
81 |
|
* |
82 |
|
* Revision 1.6 2003/03/11 01:22:25 joko |
83 |
|
* + fixed metadata for phpDocumentor |
84 |
|
* |
85 |
|
* Revision 1.5 2003/03/11 00:12:49 joko |
86 |
|
* + fixed metadata for phpDocumentor |
87 |
|
* |
88 |
|
* Revision 1.4 2003/03/10 23:25:03 joko |
89 |
|
* + fixed metadata for phpDocumentor |
90 |
|
* |
91 |
|
* Revision 1.3 2003/03/09 15:50:36 joko |
92 |
|
* + additional metadata for Autodia |
93 |
|
* |
94 |
|
* Revision 1.2 2003/03/05 17:28:43 joko |
95 |
|
* updated docu (phpDocumentor testing....) |
96 |
|
* |
97 |
* Revision 1.1 2003/03/05 12:04:00 joko |
* Revision 1.1 2003/03/05 12:04:00 joko |
98 |
* + initial commit, from GenericDataSource |
* + initial commit, from GenericDataSource |
99 |
* |
* |
121 |
* Revision 1.1 2003/03/01 03:10:40 joko |
* Revision 1.1 2003/03/01 03:10:40 joko |
122 |
* + initial commit |
* + initial commit |
123 |
* |
* |
|
* |
|
124 |
*/ |
*/ |
125 |
|
|
126 |
/** |
/** |
147 |
// require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC? |
// require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC? |
148 |
// require_once("DB.php"); |
// require_once("DB.php"); |
149 |
|
|
150 |
|
|
151 |
|
loadModule('DesignPattern::Proxy'); |
152 |
|
loadModule('DesignPattern::TransparentProxy'); |
153 |
|
loadModule('DesignPattern::RemoteProxy'); |
154 |
|
|
155 |
|
//class GenericDataSource extends MemoryDataSource { |
156 |
|
//class GenericDataSource extends DesignPattern_Proxy { |
157 |
|
//class GenericDataSource extends DesignPattern_RemoteProxy { |
158 |
|
//class GenericDataSource extends DesignPattern_TransparentProxy { |
159 |
|
|
160 |
|
//class GenericDataSource extends MemoryDataSource { |
161 |
|
//loadModule("DataSource::Proxy::Memory"); |
162 |
|
//class GenericDataSource extends DataSource_Proxy_Memory { |
163 |
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
164 |
|
//class DataSource_GenericDataSource extends DesignPattern_Proxy { |
165 |
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
166 |
|
|
167 |
|
// now independent!!! new class-inheritance-tree possible now! |
168 |
|
// solved by having an Adapter *and* a Proxy here! |
169 |
|
//class GenericDataSource { |
170 |
|
|
171 |
|
loadModule('DesignPattern::AdapterProxy'); |
172 |
|
|
173 |
|
|
174 |
|
|
175 |
/** |
/** |
176 |
* This GenericDataSource child class is *completely* independent |
* This GenericDataSource child class is *completely* independent |
177 |
* of a specific storage implementation and intended to be a wrapper |
* of a specific storage implementation and intended to be a wrapper |
178 |
* class on the way from phpHtmlLib to Xyz. |
* class on the way from phpHtmlLib to Xyz. <br> |
179 |
* ("Yyz" gets represented by Data::Storage by now.....) |
* ("Yyz" gets represented by Data::Storage by now.....) |
180 |
* |
* |
181 |
* GenericDataSource interacts with an intermediate "proxy" object |
* GenericDataSource interacts with an intermediate "proxy" object |
182 |
* (e.g. Data::Driver::Proxy) when doing queries. |
* (e.g. Data::Driver::Proxy) when doing queries. <br> |
183 |
|
* <pre> |
184 |
* Don't mix this up with a persistent database handle which gets |
* Don't mix this up with a persistent database handle which gets |
185 |
* reused each and every time for different queries. |
* reused each and every time for different queries. |
186 |
* Here *is* a new instance of Data::Driver::Proxy for *each* query. |
* Here *is* a new instance of Data::Driver::Proxy for *each* query. |
187 |
|
* </pre> |
188 |
* |
* |
189 |
* But the point is: Caching! The actual *data* isn't read redundant! |
* But the point is: Caching! The actual *data* isn't read redundant! |
190 |
* |
* |
191 |
|
* <pre> |
192 |
|
* --- snipped into here from above --- |
193 |
|
* that may use arbitrary code modules as database handlers. |
194 |
|
* It's aims are to get together: |
195 |
|
* o phpHtmlLibs "source-handlers" |
196 |
|
* o PEAR's database handlers |
197 |
|
* o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server) |
198 |
|
* --- snipped into here from above --- |
199 |
|
* </pre> |
200 |
* |
* |
201 |
|
* <p> |
202 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
203 |
* |
* |
204 |
* Data::Driver::Proxy instantiates "handlers" below itself |
* Data::Driver::Proxy instantiates "handlers" below itself |
208 |
* One worker already implemented is Data::Driver::RPC::Remote, which |
* One worker already implemented is Data::Driver::RPC::Remote, which |
209 |
* talks to a RPC::XML server (todo: talk SOAP!) using PEAR::XML::RPC. |
* talks to a RPC::XML server (todo: talk SOAP!) using PEAR::XML::RPC. |
210 |
* |
* |
211 |
|
* <pre> |
212 |
* --- refactored here, but: redundant somehow --- |
* --- refactored here, but: redundant somehow --- |
213 |
* Data::Driver::Proxy uses a PEAR XML::RPC object to actually |
* Data::Driver::Proxy uses a PEAR XML::RPC object to actually |
214 |
* talk HTTP and serialize data chunks to and from XML, |
* talk HTTP and serialize data chunks to and from XML, |
216 |
* It "proxies" arbitrary data chunks a) inside a native php4 session, |
* It "proxies" arbitrary data chunks a) inside a native php4 session, |
217 |
* b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache. |
* b) by talking to a rdbms (single proxy-table) or c) [TODO] using PEAR::Cache. |
218 |
* --- refactored here, but: redundant somehow --- |
* --- refactored here, but: redundant somehow --- |
219 |
|
* </pre> |
220 |
* |
* |
221 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
222 |
|
* </p> |
223 |
* |
* |
224 |
* |
* |
225 |
* How to use? |
* <p> |
226 |
|
* <b>How to use?</b> |
227 |
* |
* |
228 |
* Pass an array holding "locator metadata" to the constructor. |
* Pass an array holding "locator metadata" to the constructor. |
229 |
* GenericDataSource takes care of the rest. |
* GenericDataSource takes care of the rest. |
230 |
* |
* |
231 |
|
* <pre> |
232 |
* Pass an array to the constructor: (e.g.) |
* Pass an array to the constructor: (e.g.) |
233 |
* |
* |
234 |
* 1. doing rpc-calls.... |
* 1. doing rpc-calls.... |
235 |
|
* <code> |
236 |
* $locator = array( |
* $locator = array( |
237 |
* type => 'rpc', |
* type => 'rpc', |
238 |
* metadata => array( Host => 'localhost', Port => '8765' ), |
* metadata => array( Host => 'localhost', Port => '8765' ), |
239 |
* ); |
* ); |
240 |
* $source = new GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
241 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
242 |
|
* </code> |
243 |
* |
* |
244 |
* 2. [proposal] common datahandles.... |
* 2. [proposal] common datahandles.... |
245 |
|
* <code> |
246 |
* $locator = array( |
* $locator = array( |
247 |
* type => 'mysql', |
* type => 'mysql', |
248 |
* dsn => 'known dsn markup', |
* dsn => 'known dsn markup', |
249 |
* ); |
* ); |
250 |
* $source = new GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
251 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
252 |
|
* </code> |
253 |
|
* </pre> |
254 |
|
* </p> |
255 |
* |
* |
256 |
|
* |
257 |
|
* @link http://www.netfrag.org/~joko/ |
258 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
259 |
|
* |
260 |
|
* @link http://www.netfrag.org/~jonen/ |
261 |
* @author Sebastian Utz <seut@tunemedia.de> |
* @author Sebastian Utz <seut@tunemedia.de> |
262 |
|
* |
263 |
* @copyright (c) 2003 - All Rights reserved. |
* @copyright (c) 2003 - All Rights reserved. |
264 |
|
* |
265 |
|
* @link http://www.gnu.org/licenses/lgpl.txt |
266 |
* @license GNU LGPL (GNU Lesser General Public License) |
* @license GNU LGPL (GNU Lesser General Public License) |
267 |
* |
* |
|
* @author-url http://www.netfrag.org/~joko/ |
|
|
* @author-url http://www.netfrag.org/~jonen/ |
|
|
* @license-url http://www.gnu.org/licenses/lgpl.txt |
|
268 |
* |
* |
269 |
* @package phpHtmlLib |
* @package org.netfrag.glib |
270 |
* @module GenericDataSource |
* @subpackage DataSource |
271 |
|
* @name DataSource::Generic |
272 |
|
* |
273 |
|
* @todo this: |
274 |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
275 |
|
* o implement another Data::Driver::Proxy container |
276 |
|
* |
277 |
|
* <pre> |
278 |
|
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
279 |
|
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
280 |
|
* |
281 |
|
* THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy |
282 |
|
* inheritance trees at the same time, which is *not* possible at |
283 |
|
* declare-time. We *do* need some runtime-infrastructure to solve this! |
284 |
|
* |
285 |
|
* TODO: move build- and check-locator stuff from ObjectList to this place!!! |
286 |
|
* |
287 |
|
* ABOUT: |
288 |
|
* 1. otherwhere: WebApp - scope: |
289 |
|
* x handles page vs. block vs. widget; dispatches MVC-View |
290 |
|
* 2. here: DataSource - scope: |
291 |
|
* x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.)) |
292 |
|
* o clean implementation using a DesignPattern::AdapterProxy |
293 |
|
* </pre> |
294 |
* |
* |
|
*/ |
|
|
|
|
|
/** |
|
|
* Todo: |
|
|
* |
|
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
|
|
* o implement another Data::Driver::Proxy container |
|
295 |
* |
* |
296 |
*/ |
*/ |
|
|
|
|
|
|
|
// !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
|
|
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
|
|
// |
|
|
// THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy |
|
|
// inheritance trees at the same time, which is *not* possible at |
|
|
// declare-time. We *do* need some runtime-infrastructure to solve this! |
|
|
// |
|
|
// TODO: move build- and check-locator stuff from ObjectList to this place!!! |
|
|
// |
|
|
// ABOUT: |
|
|
// 1. otherwhere: WebApp - scope: |
|
|
// x handles page vs. block vs. widget; dispatches MVC-View |
|
|
// 2. here: DataSource - scope: |
|
|
// x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.)) |
|
|
// o clean implementation using a DesignPattern::AdapterProxy |
|
|
// |
|
|
|
|
|
loadModule('DesignPattern::Proxy'); |
|
|
loadModule('DesignPattern::TransparentProxy'); |
|
|
loadModule('DesignPattern::RemoteProxy'); |
|
|
|
|
|
//class GenericDataSource extends MemoryDataSource { |
|
|
//class GenericDataSource extends DesignPattern_Proxy { |
|
|
//class GenericDataSource extends DesignPattern_RemoteProxy { |
|
|
//class GenericDataSource extends DesignPattern_TransparentProxy { |
|
|
|
|
|
//class GenericDataSource extends MemoryDataSource { |
|
|
//loadModule("DataSource::Proxy::Memory"); |
|
|
//class GenericDataSource extends DataSource_Proxy_Memory { |
|
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
|
|
//class DataSource_GenericDataSource extends DesignPattern_Proxy { |
|
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
|
|
|
|
|
// now independent!!! new class-inheritance-tree possible now! |
|
|
// solved by having an Adapter *and* a Proxy here! |
|
|
//class GenericDataSource { |
|
|
|
|
|
loadModule('DesignPattern::AdapterProxy'); |
|
297 |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
298 |
|
|
299 |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
316 |
* other presets. |
* other presets. |
317 |
* |
* |
318 |
* See '_buildLocator' which acts as a dispatcher |
* See '_buildLocator' which acts as a dispatcher |
319 |
* depending on $_options[datasource]. |
* depending on $_options[transport]. |
320 |
* (main dispatching level) |
* (main dispatching level) |
321 |
* |
* |
322 |
* The structure of a full blown locator looks like this: |
* The structure of a full blown locator looks like this: |
405 |
function DataSource_Generic( &$locator, $query ) { |
function DataSource_Generic( &$locator, $query ) { |
406 |
|
|
407 |
// copy parameter from query to locator |
// copy parameter from query to locator |
408 |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_'); |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_'); |
409 |
//$this->_locator->_datasource_type = $query[datasource]; |
//$this->_locator->_datasource_type = $query[transport]; |
410 |
//$locator[_datasource_type] = $query[datasource]; |
//$locator[_datasource_type] = $query[transport]; |
411 |
|
|
412 |
|
/** |
413 |
|
* <!-- Autodia --> |
414 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
415 |
|
* $this->_locator = new DataSource_Locator() |
416 |
|
* |
417 |
|
*/ |
418 |
|
|
419 |
// build master locator |
// build master locator |
420 |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) ); |
421 |
//exit; |
//exit; |
422 |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
423 |
|
|
454 |
// pre-flight: check locator metadata |
// pre-flight: check locator metadata |
455 |
//$locator->build(); |
//$locator->build(); |
456 |
if (!$this->_locator->check()) { |
if (!$this->_locator->check()) { |
457 |
user_error("locator-check failed."); |
user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) ); |
458 |
exit; |
//exit; |
459 |
//return; |
return; |
460 |
} |
} |
461 |
|
|
462 |
//exit; |
//exit; |
463 |
|
|
464 |
|
|
465 |
|
/** |
466 |
|
* <!-- Autodia --> |
467 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
468 |
|
* $proxy = new DesignPattern_RemoteProxy() |
469 |
|
* |
470 |
|
*/ |
471 |
|
|
472 |
|
|
473 |
// --- Proxy selector/dispatcher ... |
// --- Proxy selector/dispatcher ... |
474 |
|
|
475 |
switch ($this->_locator->_datasource_type) { |
switch ($this->_locator->_datasource_type) { |
515 |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
516 |
|
|
517 |
switch ($locator->_adapter_type) { |
switch ($locator->_adapter_type) { |
518 |
|
|
519 |
case 'phpHtmlLib': |
case 'phpHtmlLib': |
520 |
//$adapter_arguments = $args[title]; |
//$adapter_arguments = $args[title]; |
521 |
|
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource'); |
|
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource'); |
|
522 |
|
|
523 |
// in order to let the Adapter communicate with the Proxy, |
// in order to let the Adapter communicate with the Proxy, |
524 |
// instantiate a wrapper method in a third namespace via |
// instantiate a wrapper method in a third namespace via |
525 |
// Exporter::export_symbol(from, to) |
// Exporter::export_symbol(from, to) |
526 |
$this->set_adapter_options($this); |
$this->set_adapter_options($this); |
527 |
|
break; |
528 |
|
|
529 |
|
// NEW [2003-04-17]: Freedom for the adapter! |
530 |
|
// phpHtmlLib didn't have a tree widget, but PEAR does. |
531 |
|
// So: Free us from the phpHtmlLib-adapter in this case. |
532 |
|
case 'free': |
533 |
|
$this->set_adapter_module('DataSource::Adapter::Free'); |
534 |
|
$this->set_adapter_options($this); |
535 |
break; |
break; |
536 |
|
|
537 |
default: |
default: |
538 |
user_error("DataSource::GenericDataSource: no Adapter could be selected!"); |
user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'"); |
539 |
break; |
break; |
540 |
} |
} |
541 |
|
|
572 |
// $this->create_handler(); |
// $this->create_handler(); |
573 |
|
|
574 |
|
|
575 |
|
/** |
576 |
|
* <!-- Autodia --> |
577 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
578 |
|
* $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource() |
579 |
|
* |
580 |
|
*/ |
581 |
|
|
582 |
// V1: |
// V1: |
583 |
//$this->create_adapter($adapter_module, $this->function, $this->arguments); |
//$this->create_adapter($adapter_module, $this->function, $this->arguments); |
584 |
|
|
730 |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
731 |
switch ($this->_query[metatype]) { |
switch ($this->_query[metatype]) { |
732 |
case 'data': |
case 'data': |
733 |
//$command = 'queryData'; |
$command = 'queryData'; |
734 |
$command = 'getObjects'; // FIXME!!! |
|
735 |
|
//$command = 'getObjects'; // FIXME!!! |
736 |
//$this->_locator->set_option('metadata.command', $command); |
//$this->_locator->set_option('metadata.command', $command); |
737 |
|
/* |
738 |
$args = array(); |
$args = array(); |
739 |
switch ($this->_query[vartype]) { |
switch ($this->_query[vartype]) { |
740 |
case 'object': |
case 'objects': |
741 |
if (!$this->_query[classname]) { |
if (!$this->_query[classname]) { |
742 |
$msg = "_query[vartype] == 'object' requires _query[classname]"; |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
743 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
744 |
} |
} |
745 |
array_push($args, $this->_query[classname]); |
array_push($args, $this->_query[classname]); |
746 |
break; |
break; |
747 |
} |
} |
748 |
break; |
*/ |
749 |
|
$query_args = array(); |
750 |
|
|
751 |
|
$msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: "; |
752 |
|
switch ($this->_query[abstract_type]) { |
753 |
|
case 'item': |
754 |
|
if (!$this->_query[nodename] && $this->_query[action] != 'create') { |
755 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
756 |
|
user_error($msg_prefix . $msg); |
757 |
|
} elseif($this->_query[action] == 'create' && $this->_query[parent]) { |
758 |
|
if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; } |
759 |
|
if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; } |
760 |
|
$query_args[nodename] = $this->_query[ident]; |
761 |
|
$query_args[parent][guid] = $this->_query[parent][guid]; |
762 |
|
$query_args[parent][nodename] = $this->_query[parent][nodename]; |
763 |
|
} elseif($this->_query[parent]) { |
764 |
|
$query_args[guid] = $this->_query[ident]; |
765 |
|
$query_args[nodename] = $this->_query[nodename]; |
766 |
|
$query_args[parent][guid] = $this->_query[parent][guid]; |
767 |
|
$query_args[parent][nodename] = $this->_query[parent][nodename]; |
768 |
|
} else { |
769 |
|
$query_args[guid] = $this->_query[ident]; |
770 |
|
$query_args[nodename] = $this->_query[nodename]; |
771 |
|
// 2003-11-17 NEW: use expand flag for real obj expand at backend |
772 |
|
if ($this->_query[expand]) {$query_args[expand] = 1; } |
773 |
|
} |
774 |
|
//print "generic_source->debug: args " . Dumper($query_args) . "<br>"; |
775 |
|
break; |
776 |
|
case 'list': |
777 |
|
if (!$this->_query[nodename]) { |
778 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
779 |
|
user_error($msg_prefix . $msg); |
780 |
|
} elseif($this->_query[parent]) { |
781 |
|
//if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; } |
782 |
|
//if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; } |
783 |
|
//$query_args[nodename] = $this->_query[ident]; |
784 |
|
$query_args[parent][guid] = $this->_query[parent][guid]; |
785 |
|
$query_args[parent][nodename] = $this->_query[parent][nodename]; |
786 |
|
} |
787 |
|
//array_push($query_args, $this->_query[nodename]); |
788 |
|
$query_args[nodename] = $this->_query[nodename]; |
789 |
|
if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; } |
790 |
|
break; |
791 |
|
case 'tree': |
792 |
|
/* |
793 |
|
if (!$this->_query[nodename]) { |
794 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
795 |
|
user_error($msg_prefix . $msg); |
796 |
|
} |
797 |
|
*/ |
798 |
|
$query_args[guid] = $this->_query[ident]; |
799 |
|
//$query_args[nodename] = $this->_query[nodename]; |
800 |
|
break; |
801 |
|
default: |
802 |
|
$msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'."; |
803 |
|
user_error($msg_prefix . $msg); |
804 |
|
break; |
805 |
|
} |
806 |
|
|
807 |
|
// filter??? |
808 |
|
//print "Filter: " . Dumper($this->_query[filter]) . "<br>"; |
809 |
|
if ($this->_query[filter]) { |
810 |
|
$query_args[filter] = $this->_query[filter]; |
811 |
|
} |
812 |
|
|
813 |
|
// dispatch action |
814 |
|
//print "Action: " . $this->_query[action] . "<br>"; |
815 |
|
if ($this->_query[action] == 'write') { |
816 |
|
$query_args[action] = $this->_query[action]; |
817 |
|
$query_args[data] = $this->_query[data]; |
818 |
|
} elseif ($this->_query[action] == 'delete') { |
819 |
|
$query_args[action] = $this->_query[action]; |
820 |
|
} elseif ($this->_query[action] == 'create') { |
821 |
|
$query_args[action] = $this->_query[action]; |
822 |
|
} elseif ($this->_query[action] == 'select') { |
823 |
|
$query_args[action] = $this->_query[action]; |
824 |
|
} |
825 |
|
|
826 |
|
$args = array( |
827 |
|
'data_type' => $this->_query[abstract_type], |
828 |
|
'query_args' => $query_args |
829 |
|
); |
830 |
|
break; |
831 |
|
|
832 |
|
// querySchema |
833 |
case 'schema': |
case 'schema': |
834 |
|
//print "Testing schema:" . "<br>"; |
835 |
$command = 'querySchema'; |
$command = 'querySchema'; |
836 |
|
$args = array( $this->_query[filter] ); |
837 |
break; |
break; |
838 |
|
|
839 |
|
// remoteMethod |
840 |
|
case 'method': |
841 |
|
$command = $this->_query[method]; |
842 |
|
//$args = $this->_query[args]; |
843 |
|
// FIX |
844 |
|
$args = array( $this->_query[args] ); |
845 |
|
break; |
846 |
|
|
847 |
} |
} |
848 |
|
|
849 |
|
|
850 |
|
// FIXME: bad behaviour? |
851 |
|
if (!is_array($args)) { $args = array( $args ); } |
852 |
|
|
853 |
|
//print Dumper($args); |
854 |
|
|
855 |
/* |
/* |
856 |
$this->_query[rpc_command] = $command; |
$this->_query[rpc_command] = $command; |
883 |
|
|
884 |
} |
} |
885 |
|
|
886 |
|
|
887 |
|
|
888 |
function &fetch_result() { |
function &fetch_result() { |
889 |
|
|
890 |
|
//print Dumper($this); |
891 |
|
|
892 |
$this->datasource_handler_buildoptions(); |
$this->datasource_handler_buildoptions(); |
893 |
|
|
894 |
$method = $this->_locator->_call[_method]; |
$call = $this->_locator->get_call(); |
895 |
$args = $this->_locator->_call[_arguments]; |
|
896 |
|
//print Dumper($call); |
897 |
|
//return; |
898 |
|
|
899 |
// pre-flight checks |
// pre-flight checks |
900 |
if (!$method) { |
if (!$call[method]) { |
901 |
$msg = "Remote command could not be resolved, please pass in or check configuration."; |
$msg = "Remote method is empty, please pass in proper metadata or check configuration."; |
902 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
903 |
return; |
return; |
904 |
} |
} |
905 |
|
|
907 |
|
|
908 |
// do remote call here and get result |
// do remote call here and get result |
909 |
// FIXME: handle synchronous/asynchronous mode here!!! |
// FIXME: handle synchronous/asynchronous mode here!!! |
910 |
$this->datasource_handler_call($method, $args); |
$this->datasource_handler_call($call[method], $call[args]); |
911 |
|
|
912 |
|
|
913 |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
918 |
$this->_result_count = sizeof($this->_result); |
$this->_result_count = sizeof($this->_result); |
919 |
|
|
920 |
// trace |
// trace |
921 |
if ($this->_debug[notice]) { |
//if (constants::get('VERBOSE') && $this->_debug[notice]) { |
922 |
|
if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) { |
923 |
//print "_result = " . Dumper($this->_result); |
//print "_result = " . Dumper($this->_result); |
924 |
print "DataSource::Generic->_result_count = " . $this->_result_count . "<br/>"; |
//print "<div><b><font color=\"darkgreen\">Debug:</font></b> DataSource::Generic->_result_count = <b>" . $this->_result_count . "</b></div>"; |
925 |
|
$this->draw_status_box(); |
926 |
} |
} |
927 |
|
|
928 |
return $this->_result; |
return $this->_result; |
929 |
|
|
930 |
} |
} |
931 |
|
|
932 |
|
function draw_status_box() { |
933 |
|
|
934 |
|
static $boxcount; |
935 |
|
|
936 |
|
$boxcount++; |
937 |
|
|
938 |
|
$box = container(); |
939 |
|
|
940 |
|
// box style |
941 |
|
$style = container( |
942 |
|
html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'), |
943 |
|
html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }') |
944 |
|
); |
945 |
|
$box->add( $style ); |
946 |
|
|
947 |
|
// box content |
948 |
|
$statusbox = html_div('box_dsg'); |
949 |
|
$statusbox->add( html_b("DataSource::Generic"), html_br() ); |
950 |
|
$locatorbox = html_div('box_dsg'); |
951 |
|
$locatorbox->set_id("locatorbox_$boxcount"); |
952 |
|
$locatorbox->add( Dumper($this->_locator) ); |
953 |
|
|
954 |
|
// FIXME: ie/mozilla? |
955 |
|
//$locatorbox->set_style('display:none;'); |
956 |
|
//$locatorbox->set_style('visibility:hidden;'); |
957 |
|
// already duplicate inside Tracer!!! |
958 |
|
$locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;'); |
959 |
|
|
960 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() ); |
961 |
|
$call = $this->_locator->get_call(); |
962 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() ); |
963 |
|
if (sizeof($call[args])) { |
964 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() ); |
965 |
|
} |
966 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() ); |
967 |
|
$box->add( $statusbox ); |
968 |
|
|
969 |
|
//print $box->render(); |
970 |
|
trace( $box ); |
971 |
|
|
972 |
|
} |
973 |
|
|
974 |
|
|
975 |
function &query_data() { |
function &query_data() { |
976 |
//print "query!<br/>"; |
//print "query!<br/>"; |
986 |
function &get_result() { |
function &get_result() { |
987 |
return $this->_result; |
return $this->_result; |
988 |
} |
} |
989 |
|
|
990 |
|
function get_result_count() { |
991 |
|
return $this->_result_count; |
992 |
|
} |
993 |
|
|
994 |
} |
} |
995 |
|
|