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