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