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.21 2003/05/10 18:14:50 jonen |
18 |
|
* + implements 'create' of item (query mapping part) |
19 |
|
* |
20 |
|
* Revision 1.20 2003/04/19 16:07:15 jonen |
21 |
|
* + added '_query[list_meta]' at 'queryData' needed for meta query args |
22 |
|
* (e.g. at UserManagment) |
23 |
|
* |
24 |
|
* Revision 1.19 2003/04/18 15:40:51 joko |
25 |
|
* NEW: tree data handling |
26 |
|
* introduced new adapter: DataSource::Adapter::Free |
27 |
|
* enhanced datasource_handler_buildoptions: now handles a) case 'tree' b) _query[filter] |
28 |
|
* |
29 |
|
* Revision 1.18 2003/04/11 00:55:49 joko |
30 |
|
* updated 'datasource_handler_buildoptions': action dispatcher now aware of 'delete' |
31 |
|
* |
32 |
|
* Revision 1.17 2003/04/09 02:07:33 joko |
33 |
|
* CHANGE: renamed key 'classname' through 'nodename' |
34 |
|
* |
35 |
|
* Revision 1.16 2003/04/08 17:55:20 joko |
36 |
|
* CHANGE: renamed property 'datasource' to 'transport' |
37 |
|
* NEW: new case 'method' in 'function datasource_handler_buildoptions' |
38 |
|
* minor fixes: updated logging/debugging messages |
39 |
|
* |
40 |
|
* Revision 1.15 2003/04/06 04:46:33 joko |
41 |
|
* renamed linking function |
42 |
|
* mozilla fixes |
43 |
|
* |
44 |
|
* Revision 1.14 2003/04/04 21:19:21 joko |
45 |
|
* modified exception handling (enhanced, purged redundant code) |
46 |
|
* |
47 |
|
* Revision 1.13 2003/04/04 02:37:14 jonen |
48 |
|
* _query[action] == write |
49 |
|
* |
50 |
|
* Revision 1.12 2003/03/29 08:00:48 joko |
51 |
|
* modified ErrorBoxing |
52 |
|
* |
53 |
|
* Revision 1.11 2003/03/28 06:45:26 joko |
54 |
|
* VERBOSE mode |
55 |
|
* |
56 |
|
* Revision 1.10 2003/03/28 03:01:02 joko |
57 |
|
* more fancy debugging-output |
58 |
|
* |
59 |
|
* Revision 1.9 2003/03/27 16:24:26 jonen |
60 |
|
* + mugled namespace |
61 |
|
* + added enhanced 'queryData' |
62 |
|
* |
63 |
|
* Revision 1.8 2003/03/20 07:22:14 jonen |
64 |
|
* + modified case 'object' to 'objects' |
65 |
|
* (cause its loads all *objects* of a given classname) |
66 |
|
* |
67 |
|
* Revision 1.7 2003/03/11 01:43:00 joko |
68 |
|
* + fixed metadata for phpDocumentor |
69 |
|
* |
70 |
|
* Revision 1.6 2003/03/11 01:22:25 joko |
71 |
|
* + fixed metadata for phpDocumentor |
72 |
|
* |
73 |
|
* Revision 1.5 2003/03/11 00:12:49 joko |
74 |
|
* + fixed metadata for phpDocumentor |
75 |
|
* |
76 |
|
* Revision 1.4 2003/03/10 23:25:03 joko |
77 |
|
* + fixed metadata for phpDocumentor |
78 |
|
* |
79 |
|
* Revision 1.3 2003/03/09 15:50:36 joko |
80 |
|
* + additional metadata for Autodia |
81 |
|
* |
82 |
|
* Revision 1.2 2003/03/05 17:28:43 joko |
83 |
|
* updated docu (phpDocumentor testing....) |
84 |
|
* |
85 |
* Revision 1.1 2003/03/05 12:04:00 joko |
* Revision 1.1 2003/03/05 12:04:00 joko |
86 |
* + initial commit, from GenericDataSource |
* + initial commit, from GenericDataSource |
87 |
* |
* |
109 |
* Revision 1.1 2003/03/01 03:10:40 joko |
* Revision 1.1 2003/03/01 03:10:40 joko |
110 |
* + initial commit |
* + initial commit |
111 |
* |
* |
|
* |
|
112 |
*/ |
*/ |
113 |
|
|
114 |
/** |
/** |
135 |
// require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC? |
// require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC? |
136 |
// require_once("DB.php"); |
// require_once("DB.php"); |
137 |
|
|
138 |
|
|
139 |
|
loadModule('DesignPattern::Proxy'); |
140 |
|
loadModule('DesignPattern::TransparentProxy'); |
141 |
|
loadModule('DesignPattern::RemoteProxy'); |
142 |
|
|
143 |
|
//class GenericDataSource extends MemoryDataSource { |
144 |
|
//class GenericDataSource extends DesignPattern_Proxy { |
145 |
|
//class GenericDataSource extends DesignPattern_RemoteProxy { |
146 |
|
//class GenericDataSource extends DesignPattern_TransparentProxy { |
147 |
|
|
148 |
|
//class GenericDataSource extends MemoryDataSource { |
149 |
|
//loadModule("DataSource::Proxy::Memory"); |
150 |
|
//class GenericDataSource extends DataSource_Proxy_Memory { |
151 |
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
152 |
|
//class DataSource_GenericDataSource extends DesignPattern_Proxy { |
153 |
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
154 |
|
|
155 |
|
// now independent!!! new class-inheritance-tree possible now! |
156 |
|
// solved by having an Adapter *and* a Proxy here! |
157 |
|
//class GenericDataSource { |
158 |
|
|
159 |
|
loadModule('DesignPattern::AdapterProxy'); |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
/** |
/** |
164 |
* This GenericDataSource child class is *completely* independent |
* This GenericDataSource child class is *completely* independent |
165 |
* of a specific storage implementation and intended to be a wrapper |
* of a specific storage implementation and intended to be a wrapper |
166 |
* class on the way from phpHtmlLib to Xyz. |
* class on the way from phpHtmlLib to Xyz. <br> |
167 |
* ("Yyz" gets represented by Data::Storage by now.....) |
* ("Yyz" gets represented by Data::Storage by now.....) |
168 |
* |
* |
169 |
* GenericDataSource interacts with an intermediate "proxy" object |
* GenericDataSource interacts with an intermediate "proxy" object |
170 |
* (e.g. Data::Driver::Proxy) when doing queries. |
* (e.g. Data::Driver::Proxy) when doing queries. <br> |
171 |
|
* <pre> |
172 |
* Don't mix this up with a persistent database handle which gets |
* Don't mix this up with a persistent database handle which gets |
173 |
* reused each and every time for different queries. |
* reused each and every time for different queries. |
174 |
* Here *is* a new instance of Data::Driver::Proxy for *each* query. |
* Here *is* a new instance of Data::Driver::Proxy for *each* query. |
175 |
|
* </pre> |
176 |
* |
* |
177 |
* But the point is: Caching! The actual *data* isn't read redundant! |
* But the point is: Caching! The actual *data* isn't read redundant! |
178 |
* |
* |
179 |
|
* <pre> |
180 |
|
* --- snipped into here from above --- |
181 |
|
* that may use arbitrary code modules as database handlers. |
182 |
|
* It's aims are to get together: |
183 |
|
* o phpHtmlLibs "source-handlers" |
184 |
|
* o PEAR's database handlers |
185 |
|
* o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server) |
186 |
|
* --- snipped into here from above --- |
187 |
|
* </pre> |
188 |
* |
* |
189 |
|
* <p> |
190 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
191 |
* |
* |
192 |
* Data::Driver::Proxy instantiates "handlers" below itself |
* Data::Driver::Proxy instantiates "handlers" below itself |
196 |
* One worker already implemented is Data::Driver::RPC::Remote, which |
* One worker already implemented is Data::Driver::RPC::Remote, which |
197 |
* 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. |
198 |
* |
* |
199 |
|
* <pre> |
200 |
* --- refactored here, but: redundant somehow --- |
* --- refactored here, but: redundant somehow --- |
201 |
* Data::Driver::Proxy uses a PEAR XML::RPC object to actually |
* Data::Driver::Proxy uses a PEAR XML::RPC object to actually |
202 |
* talk HTTP and serialize data chunks to and from XML, |
* talk HTTP and serialize data chunks to and from XML, |
204 |
* It "proxies" arbitrary data chunks a) inside a native php4 session, |
* It "proxies" arbitrary data chunks a) inside a native php4 session, |
205 |
* 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. |
206 |
* --- refactored here, but: redundant somehow --- |
* --- refactored here, but: redundant somehow --- |
207 |
|
* </pre> |
208 |
* |
* |
209 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
210 |
|
* </p> |
211 |
* |
* |
212 |
* |
* |
213 |
* How to use? |
* <p> |
214 |
|
* <b>How to use?</b> |
215 |
* |
* |
216 |
* Pass an array holding "locator metadata" to the constructor. |
* Pass an array holding "locator metadata" to the constructor. |
217 |
* GenericDataSource takes care of the rest. |
* GenericDataSource takes care of the rest. |
218 |
* |
* |
219 |
|
* <pre> |
220 |
* Pass an array to the constructor: (e.g.) |
* Pass an array to the constructor: (e.g.) |
221 |
* |
* |
222 |
* 1. doing rpc-calls.... |
* 1. doing rpc-calls.... |
223 |
|
* <code> |
224 |
* $locator = array( |
* $locator = array( |
225 |
* type => 'rpc', |
* type => 'rpc', |
226 |
* metadata => array( Host => 'localhost', Port => '8765' ), |
* metadata => array( Host => 'localhost', Port => '8765' ), |
227 |
* ); |
* ); |
228 |
* $source = new GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
229 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
230 |
|
* </code> |
231 |
* |
* |
232 |
* 2. [proposal] common datahandles.... |
* 2. [proposal] common datahandles.... |
233 |
|
* <code> |
234 |
* $locator = array( |
* $locator = array( |
235 |
* type => 'mysql', |
* type => 'mysql', |
236 |
* dsn => 'known dsn markup', |
* dsn => 'known dsn markup', |
237 |
* ); |
* ); |
238 |
* $source = new GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
239 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
240 |
|
* </code> |
241 |
|
* </pre> |
242 |
|
* </p> |
243 |
* |
* |
244 |
|
* |
245 |
|
* @link http://www.netfrag.org/~joko/ |
246 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
247 |
|
* |
248 |
|
* @link http://www.netfrag.org/~jonen/ |
249 |
* @author Sebastian Utz <seut@tunemedia.de> |
* @author Sebastian Utz <seut@tunemedia.de> |
250 |
|
* |
251 |
* @copyright (c) 2003 - All Rights reserved. |
* @copyright (c) 2003 - All Rights reserved. |
252 |
|
* |
253 |
|
* @link http://www.gnu.org/licenses/lgpl.txt |
254 |
* @license GNU LGPL (GNU Lesser General Public License) |
* @license GNU LGPL (GNU Lesser General Public License) |
255 |
* |
* |
|
* @author-url http://www.netfrag.org/~joko/ |
|
|
* @author-url http://www.netfrag.org/~jonen/ |
|
|
* @license-url http://www.gnu.org/licenses/lgpl.txt |
|
256 |
* |
* |
257 |
* @package phpHtmlLib |
* @package org.netfrag.glib |
258 |
* @module GenericDataSource |
* @subpackage DataSource |
259 |
|
* @name DataSource::Generic |
260 |
|
* |
261 |
|
* @todo this: |
262 |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
263 |
|
* o implement another Data::Driver::Proxy container |
264 |
|
* |
265 |
|
* <pre> |
266 |
|
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
267 |
|
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
268 |
|
* |
269 |
|
* THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy |
270 |
|
* inheritance trees at the same time, which is *not* possible at |
271 |
|
* declare-time. We *do* need some runtime-infrastructure to solve this! |
272 |
|
* |
273 |
|
* TODO: move build- and check-locator stuff from ObjectList to this place!!! |
274 |
|
* |
275 |
|
* ABOUT: |
276 |
|
* 1. otherwhere: WebApp - scope: |
277 |
|
* x handles page vs. block vs. widget; dispatches MVC-View |
278 |
|
* 2. here: DataSource - scope: |
279 |
|
* x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.)) |
280 |
|
* o clean implementation using a DesignPattern::AdapterProxy |
281 |
|
* </pre> |
282 |
* |
* |
|
*/ |
|
|
|
|
|
/** |
|
|
* Todo: |
|
|
* |
|
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
|
|
* o implement another Data::Driver::Proxy container |
|
283 |
* |
* |
284 |
*/ |
*/ |
|
|
|
|
|
|
|
// !!!!!!!! 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'); |
|
285 |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
286 |
|
|
287 |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
304 |
* other presets. |
* other presets. |
305 |
* |
* |
306 |
* See '_buildLocator' which acts as a dispatcher |
* See '_buildLocator' which acts as a dispatcher |
307 |
* depending on $_options[datasource]. |
* depending on $_options[transport]. |
308 |
* (main dispatching level) |
* (main dispatching level) |
309 |
* |
* |
310 |
* The structure of a full blown locator looks like this: |
* The structure of a full blown locator looks like this: |
393 |
function DataSource_Generic( &$locator, $query ) { |
function DataSource_Generic( &$locator, $query ) { |
394 |
|
|
395 |
// copy parameter from query to locator |
// copy parameter from query to locator |
396 |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[datasource] ), '_'); |
//$this->_locator->merge_to($this->_locator, array( datasource_type => $query[transport] ), '_'); |
397 |
//$this->_locator->_datasource_type = $query[datasource]; |
//$this->_locator->_datasource_type = $query[transport]; |
398 |
//$locator[_datasource_type] = $query[datasource]; |
//$locator[_datasource_type] = $query[transport]; |
399 |
|
|
400 |
|
/** |
401 |
|
* <!-- Autodia --> |
402 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
403 |
|
* $this->_locator = new DataSource_Locator() |
404 |
|
* |
405 |
|
*/ |
406 |
|
|
407 |
// build master locator |
// build master locator |
408 |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[transport] ) ); |
409 |
//exit; |
//exit; |
410 |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
//$this->_locator = php::mkComponent('DataSource::Locator'); |
411 |
|
|
442 |
// pre-flight: check locator metadata |
// pre-flight: check locator metadata |
443 |
//$locator->build(); |
//$locator->build(); |
444 |
if (!$this->_locator->check()) { |
if (!$this->_locator->check()) { |
445 |
user_error("locator-check failed."); |
user_error("DataSource::Generic: locator-check failed." . "<br/>" . "Locator was: " . Dumper($this->_locator) ); |
446 |
exit; |
//exit; |
447 |
//return; |
return; |
448 |
} |
} |
449 |
|
|
450 |
//exit; |
//exit; |
451 |
|
|
452 |
|
|
453 |
|
/** |
454 |
|
* <!-- Autodia --> |
455 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
456 |
|
* $proxy = new DesignPattern_RemoteProxy() |
457 |
|
* |
458 |
|
*/ |
459 |
|
|
460 |
|
|
461 |
// --- Proxy selector/dispatcher ... |
// --- Proxy selector/dispatcher ... |
462 |
|
|
463 |
switch ($this->_locator->_datasource_type) { |
switch ($this->_locator->_datasource_type) { |
503 |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
// ... resolves this._modules.adapter._id to this._modules.adapter._module |
504 |
|
|
505 |
switch ($locator->_adapter_type) { |
switch ($locator->_adapter_type) { |
506 |
|
|
507 |
case 'phpHtmlLib': |
case 'phpHtmlLib': |
508 |
//$adapter_arguments = $args[title]; |
//$adapter_arguments = $args[title]; |
509 |
|
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource'); |
|
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource'); |
|
510 |
|
|
511 |
// in order to let the Adapter communicate with the Proxy, |
// in order to let the Adapter communicate with the Proxy, |
512 |
// instantiate a wrapper method in a third namespace via |
// instantiate a wrapper method in a third namespace via |
513 |
// Exporter::export_symbol(from, to) |
// Exporter::export_symbol(from, to) |
514 |
$this->set_adapter_options($this); |
$this->set_adapter_options($this); |
515 |
|
break; |
516 |
|
|
517 |
|
// NEW [2003-04-17]: Freedom for the adapter! |
518 |
|
// phpHtmlLib didn't have a tree widget, but PEAR does. |
519 |
|
// So: Free us from the phpHtmlLib-adapter in this case. |
520 |
|
case 'free': |
521 |
|
$this->set_adapter_module('DataSource::Adapter::Free'); |
522 |
|
$this->set_adapter_options($this); |
523 |
break; |
break; |
524 |
|
|
525 |
default: |
default: |
526 |
user_error("DataSource::GenericDataSource: no Adapter could be selected!"); |
user_error("DataSource::Generic: no Adapter could be selected: \$locator->_adapter_type='$locator->_adapter_type'"); |
527 |
break; |
break; |
528 |
} |
} |
529 |
|
|
560 |
// $this->create_handler(); |
// $this->create_handler(); |
561 |
|
|
562 |
|
|
563 |
|
/** |
564 |
|
* <!-- Autodia --> |
565 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
566 |
|
* $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource() |
567 |
|
* |
568 |
|
*/ |
569 |
|
|
570 |
// V1: |
// V1: |
571 |
//$this->create_adapter($adapter_module, $this->function, $this->arguments); |
//$this->create_adapter($adapter_module, $this->function, $this->arguments); |
572 |
|
|
718 |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
719 |
switch ($this->_query[metatype]) { |
switch ($this->_query[metatype]) { |
720 |
case 'data': |
case 'data': |
721 |
//$command = 'queryData'; |
$command = 'queryData'; |
722 |
$command = 'getObjects'; // FIXME!!! |
|
723 |
|
//$command = 'getObjects'; // FIXME!!! |
724 |
//$this->_locator->set_option('metadata.command', $command); |
//$this->_locator->set_option('metadata.command', $command); |
725 |
|
/* |
726 |
$args = array(); |
$args = array(); |
727 |
switch ($this->_query[vartype]) { |
switch ($this->_query[vartype]) { |
728 |
case 'object': |
case 'objects': |
729 |
if (!$this->_query[classname]) { |
if (!$this->_query[classname]) { |
730 |
$msg = "_query[vartype] == 'object' requires _query[classname]"; |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
731 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
732 |
} |
} |
733 |
array_push($args, $this->_query[classname]); |
array_push($args, $this->_query[classname]); |
734 |
break; |
break; |
735 |
} |
} |
736 |
break; |
*/ |
737 |
|
$query_args = array(); |
738 |
|
|
739 |
|
$msg_prefix = "DataSource::Generic::datasource_handler_buildoptions failed: "; |
740 |
|
switch ($this->_query[abstract_type]) { |
741 |
|
case 'item': |
742 |
|
if (!$this->_query[nodename] && $this->_query[action] != 'create') { |
743 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
744 |
|
user_error($msg_prefix . $msg); |
745 |
|
} elseif($this->_query[action] == 'create' && $this->_query[parent]) { |
746 |
|
if($this->_query[nodename]) { $query_args[node_class] = $this->_query[nodename]; } |
747 |
|
if($this->_query['hash_key']) { $query_args['hash_key'] = $this->_query['hash_key']; } |
748 |
|
$query_args[nodename] = $this->_query[ident]; |
749 |
|
$query_args[parent][guid] = $this->_query[parent][guid]; |
750 |
|
$query_args[parent][nodename] = $this->_query[parent][nodename]; |
751 |
|
} else { |
752 |
|
$query_args[guid] = $this->_query[ident]; |
753 |
|
$query_args[nodename] = $this->_query[nodename]; |
754 |
|
} |
755 |
|
break; |
756 |
|
case 'list': |
757 |
|
if (!$this->_query[nodename]) { |
758 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
759 |
|
user_error($msg_prefix . $msg); |
760 |
|
} |
761 |
|
//array_push($query_args, $this->_query[nodename]); |
762 |
|
$query_args[nodename] = $this->_query[nodename]; |
763 |
|
if($this->_query[list_meta]) { $query_args[list_meta] = $this->_query[list_meta]; } |
764 |
|
break; |
765 |
|
case 'tree': |
766 |
|
/* |
767 |
|
if (!$this->_query[nodename]) { |
768 |
|
$msg = "_query[vartype] == 'objects' requires _query[nodename]"; |
769 |
|
user_error($msg_prefix . $msg); |
770 |
|
} |
771 |
|
*/ |
772 |
|
$query_args[guid] = $this->_query[ident]; |
773 |
|
//$query_args[nodename] = $this->_query[nodename]; |
774 |
|
break; |
775 |
|
default: |
776 |
|
$msg = "\$this->_query[abstract_type] could not be dispatched as 'item', 'list' or 'tree'."; |
777 |
|
user_error($msg_prefix . $msg); |
778 |
|
break; |
779 |
|
} |
780 |
|
|
781 |
|
// filter??? |
782 |
|
print "Filter: " . Dumper($this->_query[filter]) . "<br>"; |
783 |
|
if ($this->_query[filter]) { |
784 |
|
$query_args[filter] = $this->_query[filter]; |
785 |
|
} |
786 |
|
|
787 |
|
// dispatch action |
788 |
|
print "Action: " . $this->_query[action] . "<br>"; |
789 |
|
if ($this->_query[action] == 'write') { |
790 |
|
$query_args[action] = $this->_query[action]; |
791 |
|
$query_args[data] = $this->_query[data]; |
792 |
|
} elseif ($this->_query[action] == 'delete') { |
793 |
|
$query_args[action] = $this->_query[action]; |
794 |
|
} elseif ($this->_query[action] == 'create') { |
795 |
|
$query_args[action] = $this->_query[action]; |
796 |
|
} |
797 |
|
|
798 |
|
$args = array( |
799 |
|
'data_type' => $this->_query[abstract_type], |
800 |
|
'query_args' => $query_args |
801 |
|
); |
802 |
|
break; |
803 |
|
|
804 |
|
// querySchema |
805 |
case 'schema': |
case 'schema': |
806 |
|
//print "Testing schema:" . "<br>"; |
807 |
$command = 'querySchema'; |
$command = 'querySchema'; |
808 |
|
$args = array( $this->_query[filter] ); |
809 |
break; |
break; |
810 |
|
|
811 |
|
// remoteMethod |
812 |
|
case 'method': |
813 |
|
$command = $this->_query[method]; |
814 |
|
$args = $this->_query[args]; |
815 |
|
break; |
816 |
|
|
817 |
} |
} |
818 |
|
|
819 |
|
|
820 |
|
// FIXME: bad behaviour? |
821 |
|
if (!is_array($args)) { $args = array( $args ); } |
822 |
|
|
823 |
/* |
/* |
824 |
$this->_query[rpc_command] = $command; |
$this->_query[rpc_command] = $command; |
851 |
|
|
852 |
} |
} |
853 |
|
|
854 |
|
|
855 |
|
|
856 |
function &fetch_result() { |
function &fetch_result() { |
857 |
|
|
858 |
|
//print Dumper($this); |
859 |
|
|
860 |
$this->datasource_handler_buildoptions(); |
$this->datasource_handler_buildoptions(); |
861 |
|
|
862 |
$method = $this->_locator->_call[_method]; |
$call = $this->_locator->get_call(); |
863 |
$args = $this->_locator->_call[_arguments]; |
|
864 |
|
//print Dumper($call); |
865 |
|
//return; |
866 |
|
|
867 |
// pre-flight checks |
// pre-flight checks |
868 |
if (!$method) { |
if (!$call[method]) { |
869 |
$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."; |
870 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("DataSource::Generic: query_data() - failed: " . $msg); |
871 |
return; |
return; |
872 |
} |
} |
873 |
|
|
875 |
|
|
876 |
// do remote call here and get result |
// do remote call here and get result |
877 |
// FIXME: handle synchronous/asynchronous mode here!!! |
// FIXME: handle synchronous/asynchronous mode here!!! |
878 |
$this->datasource_handler_call($method, $args); |
$this->datasource_handler_call($call[method], $call[args]); |
879 |
|
|
880 |
|
|
881 |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
// TODO: ... = $this->poll_handler_result and $this->get_handler_result |
886 |
$this->_result_count = sizeof($this->_result); |
$this->_result_count = sizeof($this->_result); |
887 |
|
|
888 |
// trace |
// trace |
889 |
if ($this->_debug[notice]) { |
//if (constants::get('VERBOSE') && $this->_debug[notice]) { |
890 |
|
if (constants::get('VERBOSE') or constants::get('ERRORS_ONLY')) { |
891 |
//print "_result = " . Dumper($this->_result); |
//print "_result = " . Dumper($this->_result); |
892 |
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>"; |
893 |
|
$this->draw_status_box(); |
894 |
} |
} |
895 |
|
|
896 |
return $this->_result; |
return $this->_result; |
897 |
|
|
898 |
} |
} |
899 |
|
|
900 |
|
function draw_status_box() { |
901 |
|
|
902 |
|
static $boxcount; |
903 |
|
|
904 |
|
$boxcount++; |
905 |
|
|
906 |
|
$box = container(); |
907 |
|
|
908 |
|
// box style |
909 |
|
$style = container( |
910 |
|
html_style("text/css", '.boxlabel_darkgreen { color: darkgreen; font-weight:bold; }'), |
911 |
|
html_style("text/css", '.box_dsg { background: #20ab39; color: white; border: 2px black groove; width:640px; padding:10px; margin:40px; }') |
912 |
|
); |
913 |
|
$box->add( $style ); |
914 |
|
|
915 |
|
// box content |
916 |
|
$statusbox = html_div('box_dsg'); |
917 |
|
$statusbox->add( html_b("DataSource::Generic"), html_br() ); |
918 |
|
$locatorbox = html_div('box_dsg'); |
919 |
|
$locatorbox->set_id("locatorbox_$boxcount"); |
920 |
|
$locatorbox->add( Dumper($this->_locator) ); |
921 |
|
|
922 |
|
// FIXME: ie/mozilla? |
923 |
|
//$locatorbox->set_style('display:none;'); |
924 |
|
//$locatorbox->set_style('visibility:hidden;'); |
925 |
|
// already duplicate inside Tracer!!! |
926 |
|
$locatorbox->set_style('visibility:hidden; position:absolute; z-index:1; margin-top:30px; padding:5px;'); |
927 |
|
|
928 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Locator:"), link::js_function( 'toggleVisibility', array("locatorbox_$boxcount"), '[show]'), $locatorbox, html_br() ); |
929 |
|
$call = $this->_locator->get_call(); |
930 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Method:"), $call[method], html_br() ); |
931 |
|
if (sizeof($call[args])) { |
932 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Arguments:"), Dumper($call[args]), html_br() ); |
933 |
|
} |
934 |
|
$statusbox->add( html_span('boxlabel_darkgreen', "Count:"), $this->get_result_count(), html_br() ); |
935 |
|
$box->add( $statusbox ); |
936 |
|
|
937 |
|
//print $box->render(); |
938 |
|
trace( $box ); |
939 |
|
|
940 |
|
} |
941 |
|
|
942 |
|
|
943 |
function &query_data() { |
function &query_data() { |
944 |
//print "query!<br/>"; |
//print "query!<br/>"; |
954 |
function &get_result() { |
function &get_result() { |
955 |
return $this->_result; |
return $this->_result; |
956 |
} |
} |
957 |
|
|
958 |
|
function get_result_count() { |
959 |
|
return $this->_result_count; |
960 |
|
} |
961 |
|
|
962 |
} |
} |
963 |
|
|