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 |
|
* <b>Cvs-Log:</b> |
13 |
|
* |
14 |
|
* <pre> |
15 |
* $Id$ |
* $Id$ |
16 |
* |
* |
17 |
* $Log$ |
* $Log$ |
18 |
|
* Revision 1.9 2003/03/27 16:24:26 jonen |
19 |
|
* + mugled namespace |
20 |
|
* + added enhanced 'queryData' |
21 |
|
* |
22 |
|
* Revision 1.8 2003/03/20 07:22:14 jonen |
23 |
|
* + modified case 'object' to 'objects' |
24 |
|
* (cause its loads all *objects* of a given classname) |
25 |
|
* |
26 |
|
* Revision 1.7 2003/03/11 01:43:00 joko |
27 |
|
* + fixed metadata for phpDocumentor |
28 |
|
* |
29 |
|
* Revision 1.6 2003/03/11 01:22:25 joko |
30 |
|
* + fixed metadata for phpDocumentor |
31 |
|
* |
32 |
|
* Revision 1.5 2003/03/11 00:12:49 joko |
33 |
|
* + fixed metadata for phpDocumentor |
34 |
|
* |
35 |
|
* Revision 1.4 2003/03/10 23:25:03 joko |
36 |
|
* + fixed metadata for phpDocumentor |
37 |
|
* |
38 |
|
* Revision 1.3 2003/03/09 15:50:36 joko |
39 |
|
* + additional metadata for Autodia |
40 |
|
* |
41 |
|
* Revision 1.2 2003/03/05 17:28:43 joko |
42 |
|
* updated docu (phpDocumentor testing....) |
43 |
|
* |
44 |
* Revision 1.1 2003/03/05 12:04:00 joko |
* Revision 1.1 2003/03/05 12:04:00 joko |
45 |
* + initial commit, from GenericDataSource |
* + initial commit, from GenericDataSource |
46 |
* |
* |
67 |
* |
* |
68 |
* Revision 1.1 2003/03/01 03:10:40 joko |
* Revision 1.1 2003/03/01 03:10:40 joko |
69 |
* + initial commit |
* + initial commit |
70 |
* |
* </pre> |
71 |
* |
* |
72 |
*/ |
*/ |
73 |
|
|
95 |
// require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC? |
// require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC? |
96 |
// require_once("DB.php"); |
// require_once("DB.php"); |
97 |
|
|
98 |
|
|
99 |
|
loadModule('DesignPattern::Proxy'); |
100 |
|
loadModule('DesignPattern::TransparentProxy'); |
101 |
|
loadModule('DesignPattern::RemoteProxy'); |
102 |
|
|
103 |
|
//class GenericDataSource extends MemoryDataSource { |
104 |
|
//class GenericDataSource extends DesignPattern_Proxy { |
105 |
|
//class GenericDataSource extends DesignPattern_RemoteProxy { |
106 |
|
//class GenericDataSource extends DesignPattern_TransparentProxy { |
107 |
|
|
108 |
|
//class GenericDataSource extends MemoryDataSource { |
109 |
|
//loadModule("DataSource::Proxy::Memory"); |
110 |
|
//class GenericDataSource extends DataSource_Proxy_Memory { |
111 |
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
112 |
|
//class DataSource_GenericDataSource extends DesignPattern_Proxy { |
113 |
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
114 |
|
|
115 |
|
// now independent!!! new class-inheritance-tree possible now! |
116 |
|
// solved by having an Adapter *and* a Proxy here! |
117 |
|
//class GenericDataSource { |
118 |
|
|
119 |
|
loadModule('DesignPattern::AdapterProxy'); |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
/** |
/** |
124 |
* This GenericDataSource child class is *completely* independent |
* This GenericDataSource child class is *completely* independent |
125 |
* of a specific storage implementation and intended to be a wrapper |
* of a specific storage implementation and intended to be a wrapper |
126 |
* class on the way from phpHtmlLib to Xyz. |
* class on the way from phpHtmlLib to Xyz. <br> |
127 |
* ("Yyz" gets represented by Data::Storage by now.....) |
* ("Yyz" gets represented by Data::Storage by now.....) |
128 |
* |
* |
129 |
* GenericDataSource interacts with an intermediate "proxy" object |
* GenericDataSource interacts with an intermediate "proxy" object |
130 |
* (e.g. Data::Driver::Proxy) when doing queries. |
* (e.g. Data::Driver::Proxy) when doing queries. <br> |
131 |
|
* <pre> |
132 |
* Don't mix this up with a persistent database handle which gets |
* Don't mix this up with a persistent database handle which gets |
133 |
* reused each and every time for different queries. |
* reused each and every time for different queries. |
134 |
* Here *is* a new instance of Data::Driver::Proxy for *each* query. |
* Here *is* a new instance of Data::Driver::Proxy for *each* query. |
135 |
|
* </pre> |
136 |
* |
* |
137 |
* But the point is: Caching! The actual *data* isn't read redundant! |
* But the point is: Caching! The actual *data* isn't read redundant! |
138 |
* |
* |
139 |
|
* <pre> |
140 |
|
* --- snipped into here from above --- |
141 |
|
* that may use arbitrary code modules as database handlers. |
142 |
|
* It's aims are to get together: |
143 |
|
* o phpHtmlLibs "source-handlers" |
144 |
|
* o PEAR's database handlers |
145 |
|
* o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server) |
146 |
|
* --- snipped into here from above --- |
147 |
|
* </pre> |
148 |
* |
* |
149 |
|
* <p> |
150 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
151 |
* |
* |
152 |
* Data::Driver::Proxy instantiates "handlers" below itself |
* Data::Driver::Proxy instantiates "handlers" below itself |
156 |
* One worker already implemented is Data::Driver::RPC::Remote, which |
* One worker already implemented is Data::Driver::RPC::Remote, which |
157 |
* 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. |
158 |
* |
* |
159 |
|
* <pre> |
160 |
* --- refactored here, but: redundant somehow --- |
* --- refactored here, but: redundant somehow --- |
161 |
* Data::Driver::Proxy uses a PEAR XML::RPC object to actually |
* Data::Driver::Proxy uses a PEAR XML::RPC object to actually |
162 |
* talk HTTP and serialize data chunks to and from XML, |
* talk HTTP and serialize data chunks to and from XML, |
164 |
* It "proxies" arbitrary data chunks a) inside a native php4 session, |
* It "proxies" arbitrary data chunks a) inside a native php4 session, |
165 |
* 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. |
166 |
* --- refactored here, but: redundant somehow --- |
* --- refactored here, but: redundant somehow --- |
167 |
|
* </pre> |
168 |
* |
* |
169 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
170 |
|
* </p> |
171 |
* |
* |
172 |
* |
* |
173 |
* How to use? |
* <p> |
174 |
|
* <b>How to use?</b> |
175 |
* |
* |
176 |
* Pass an array holding "locator metadata" to the constructor. |
* Pass an array holding "locator metadata" to the constructor. |
177 |
* GenericDataSource takes care of the rest. |
* GenericDataSource takes care of the rest. |
178 |
* |
* |
179 |
|
* <pre> |
180 |
* Pass an array to the constructor: (e.g.) |
* Pass an array to the constructor: (e.g.) |
181 |
* |
* |
182 |
* 1. doing rpc-calls.... |
* 1. doing rpc-calls.... |
183 |
|
* <code> |
184 |
* $locator = array( |
* $locator = array( |
185 |
* type => 'rpc', |
* type => 'rpc', |
186 |
* metadata => array( Host => 'localhost', Port => '8765' ), |
* metadata => array( Host => 'localhost', Port => '8765' ), |
187 |
* ); |
* ); |
188 |
* $source = new GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
189 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
190 |
|
* </code> |
191 |
* |
* |
192 |
* 2. [proposal] common datahandles.... |
* 2. [proposal] common datahandles.... |
193 |
|
* <code> |
194 |
* $locator = array( |
* $locator = array( |
195 |
* type => 'mysql', |
* type => 'mysql', |
196 |
* dsn => 'known dsn markup', |
* dsn => 'known dsn markup', |
197 |
* ); |
* ); |
198 |
* $source = new GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
199 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
200 |
|
* </code> |
201 |
|
* </pre> |
202 |
|
* </p> |
203 |
* |
* |
204 |
|
* |
205 |
|
* @link http://www.netfrag.org/~joko/ |
206 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
207 |
|
* |
208 |
|
* @link http://www.netfrag.org/~jonen/ |
209 |
* @author Sebastian Utz <seut@tunemedia.de> |
* @author Sebastian Utz <seut@tunemedia.de> |
210 |
|
* |
211 |
* @copyright (c) 2003 - All Rights reserved. |
* @copyright (c) 2003 - All Rights reserved. |
|
* @license GNU LGPL (GNU Lesser General Public License) |
|
212 |
* |
* |
213 |
* @author-url http://www.netfrag.org/~joko/ |
* @link http://www.gnu.org/licenses/lgpl.txt |
214 |
* @author-url http://www.netfrag.org/~jonen/ |
* @license GNU LGPL (GNU Lesser General Public License) |
|
* @license-url http://www.gnu.org/licenses/lgpl.txt |
|
215 |
* |
* |
|
* @package phpHtmlLib |
|
|
* @module GenericDataSource |
|
216 |
* |
* |
217 |
*/ |
* @package org.netfrag.glib |
218 |
|
* @subpackage DataSource |
219 |
/** |
* @name DataSource::Generic |
220 |
* Todo: |
* |
221 |
|
* @todo this: |
222 |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
223 |
|
* o implement another Data::Driver::Proxy container |
224 |
|
* |
225 |
|
* <pre> |
226 |
|
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
227 |
|
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
228 |
|
* |
229 |
|
* THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy |
230 |
|
* inheritance trees at the same time, which is *not* possible at |
231 |
|
* declare-time. We *do* need some runtime-infrastructure to solve this! |
232 |
|
* |
233 |
|
* TODO: move build- and check-locator stuff from ObjectList to this place!!! |
234 |
|
* |
235 |
|
* ABOUT: |
236 |
|
* 1. otherwhere: WebApp - scope: |
237 |
|
* x handles page vs. block vs. widget; dispatches MVC-View |
238 |
|
* 2. here: DataSource - scope: |
239 |
|
* x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.)) |
240 |
|
* o clean implementation using a DesignPattern::AdapterProxy |
241 |
|
* </pre> |
242 |
* |
* |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
|
|
* o implement another Data::Driver::Proxy container |
|
243 |
* |
* |
244 |
*/ |
*/ |
|
|
|
|
|
|
|
// !!!!!!!! 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'); |
|
245 |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
246 |
|
|
247 |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
357 |
//$this->_locator->_datasource_type = $query[datasource]; |
//$this->_locator->_datasource_type = $query[datasource]; |
358 |
//$locator[_datasource_type] = $query[datasource]; |
//$locator[_datasource_type] = $query[datasource]; |
359 |
|
|
360 |
|
/** |
361 |
|
* <!-- Autodia --> |
362 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
363 |
|
* $this->_locator = new DataSource_Locator() |
364 |
|
* |
365 |
|
*/ |
366 |
|
|
367 |
// build master locator |
// build master locator |
368 |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
369 |
//exit; |
//exit; |
410 |
//exit; |
//exit; |
411 |
|
|
412 |
|
|
413 |
|
/** |
414 |
|
* <!-- Autodia --> |
415 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
416 |
|
* $proxy = new DesignPattern_RemoteProxy() |
417 |
|
* |
418 |
|
*/ |
419 |
|
|
420 |
|
|
421 |
// --- Proxy selector/dispatcher ... |
// --- Proxy selector/dispatcher ... |
422 |
|
|
423 |
switch ($this->_locator->_datasource_type) { |
switch ($this->_locator->_datasource_type) { |
466 |
case 'phpHtmlLib': |
case 'phpHtmlLib': |
467 |
//$adapter_arguments = $args[title]; |
//$adapter_arguments = $args[title]; |
468 |
|
|
469 |
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataListSource'); |
$this->set_adapter_module('DataSource::Adapter::phpHtmlLib::DataSource'); |
470 |
|
|
471 |
// in order to let the Adapter communicate with the Proxy, |
// in order to let the Adapter communicate with the Proxy, |
472 |
// instantiate a wrapper method in a third namespace via |
// instantiate a wrapper method in a third namespace via |
513 |
// $this->create_handler(); |
// $this->create_handler(); |
514 |
|
|
515 |
|
|
516 |
|
/** |
517 |
|
* <!-- Autodia --> |
518 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
519 |
|
* $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource() |
520 |
|
* |
521 |
|
*/ |
522 |
|
|
523 |
// V1: |
// V1: |
524 |
//$this->create_adapter($adapter_module, $this->function, $this->arguments); |
//$this->create_adapter($adapter_module, $this->function, $this->arguments); |
525 |
|
|
671 |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
// FIXME: abstract this some more (e.g. via a CommandMapper|Registry) |
672 |
switch ($this->_query[metatype]) { |
switch ($this->_query[metatype]) { |
673 |
case 'data': |
case 'data': |
674 |
//$command = 'queryData'; |
$command = 'queryData'; |
675 |
$command = 'getObjects'; // FIXME!!! |
//$command = 'getObjects'; // FIXME!!! |
676 |
//$this->_locator->set_option('metadata.command', $command); |
//$this->_locator->set_option('metadata.command', $command); |
677 |
|
/* |
678 |
$args = array(); |
$args = array(); |
679 |
switch ($this->_query[vartype]) { |
switch ($this->_query[vartype]) { |
680 |
case 'object': |
case 'objects': |
681 |
if (!$this->_query[classname]) { |
if (!$this->_query[classname]) { |
682 |
$msg = "_query[vartype] == 'object' requires _query[classname]"; |
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
683 |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
user_error("GenericDataSource::query_data() - failed: " . $msg); |
684 |
} |
} |
685 |
array_push($args, $this->_query[classname]); |
array_push($args, $this->_query[classname]); |
686 |
break; |
break; |
687 |
} |
} |
688 |
break; |
*/ |
689 |
|
$query_args = array(); |
690 |
|
switch ($this->_query[abstract_type]) { |
691 |
|
case 'list': |
692 |
|
if (!$this->_query[classname]) { |
693 |
|
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
694 |
|
user_error("GenericDataSource::query_data() - failed: " . $msg); |
695 |
|
} |
696 |
|
//array_push($query_args, $this->_query[classname]); |
697 |
|
$query_args[classname] = $this->_query[classname]; |
698 |
|
break; |
699 |
|
case 'item': |
700 |
|
if (!$this->_query[classname]) { |
701 |
|
$msg = "_query[vartype] == 'objects' requires _query[classname]"; |
702 |
|
user_error("GenericDataSource::query_data() - failed: " . $msg); |
703 |
|
} |
704 |
|
$query_args[guid] = $this->_query[ident]; |
705 |
|
$query_args[classname] = $this->_query[classname]; |
706 |
|
break; |
707 |
|
} |
708 |
|
$args = array( |
709 |
|
'data_type' => $this->_query[abstract_type], |
710 |
|
'query_args' => $query_args |
711 |
|
); |
712 |
|
break; |
713 |
|
|
714 |
|
// querySchema |
715 |
case 'schema': |
case 'schema': |
716 |
|
//print "Testing schema:" . "<br>"; |
717 |
$command = 'querySchema'; |
$command = 'querySchema'; |
718 |
break; |
break; |
719 |
} |
} |