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 |
|
|
12 |
* $Id$ |
* $Id$ |
13 |
* |
* |
14 |
* $Log$ |
* $Log$ |
15 |
|
* Revision 1.5 2003/03/11 00:12:49 joko |
16 |
|
* + fixed metadata for phpDocumentor |
17 |
|
* |
18 |
|
* Revision 1.4 2003/03/10 23:25:03 joko |
19 |
|
* + fixed metadata for phpDocumentor |
20 |
|
* |
21 |
|
* Revision 1.3 2003/03/09 15:50:36 joko |
22 |
|
* + additional metadata for Autodia |
23 |
|
* |
24 |
|
* Revision 1.2 2003/03/05 17:28:43 joko |
25 |
|
* updated docu (phpDocumentor testing....) |
26 |
|
* |
27 |
* Revision 1.1 2003/03/05 12:04:00 joko |
* Revision 1.1 2003/03/05 12:04:00 joko |
28 |
* + initial commit, from GenericDataSource |
* + initial commit, from GenericDataSource |
29 |
* |
* |
78 |
// require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC? |
// require_once("PEAR.php"); // FIXME: what about PEAR::XML::RPC? |
79 |
// require_once("DB.php"); |
// require_once("DB.php"); |
80 |
|
|
81 |
|
|
82 |
|
loadModule('DesignPattern::Proxy'); |
83 |
|
loadModule('DesignPattern::TransparentProxy'); |
84 |
|
loadModule('DesignPattern::RemoteProxy'); |
85 |
|
|
86 |
|
//class GenericDataSource extends MemoryDataSource { |
87 |
|
//class GenericDataSource extends DesignPattern_Proxy { |
88 |
|
//class GenericDataSource extends DesignPattern_RemoteProxy { |
89 |
|
//class GenericDataSource extends DesignPattern_TransparentProxy { |
90 |
|
|
91 |
|
//class GenericDataSource extends MemoryDataSource { |
92 |
|
//loadModule("DataSource::Proxy::Memory"); |
93 |
|
//class GenericDataSource extends DataSource_Proxy_Memory { |
94 |
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
95 |
|
//class DataSource_GenericDataSource extends DesignPattern_Proxy { |
96 |
|
//class DataSource_GenericDataSource extends DataSource_Proxy_Memory { |
97 |
|
|
98 |
|
// now independent!!! new class-inheritance-tree possible now! |
99 |
|
// solved by having an Adapter *and* a Proxy here! |
100 |
|
//class GenericDataSource { |
101 |
|
|
102 |
|
loadModule('DesignPattern::AdapterProxy'); |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
/** |
/** |
107 |
* This GenericDataSource child class is *completely* independent |
* This GenericDataSource child class is *completely* independent |
108 |
* of a specific storage implementation and intended to be a wrapper |
* of a specific storage implementation and intended to be a wrapper |
109 |
* class on the way from phpHtmlLib to Xyz. |
* class on the way from phpHtmlLib to Xyz. <br> |
110 |
* ("Yyz" gets represented by Data::Storage by now.....) |
* ("Yyz" gets represented by Data::Storage by now.....) |
111 |
* |
* |
112 |
* GenericDataSource interacts with an intermediate "proxy" object |
* GenericDataSource interacts with an intermediate "proxy" object |
113 |
* (e.g. Data::Driver::Proxy) when doing queries. |
* (e.g. Data::Driver::Proxy) when doing queries. <br> |
114 |
|
* <pre> |
115 |
* Don't mix this up with a persistent database handle which gets |
* Don't mix this up with a persistent database handle which gets |
116 |
* reused each and every time for different queries. |
* reused each and every time for different queries. |
117 |
* Here *is* a new instance of Data::Driver::Proxy for *each* query. |
* Here *is* a new instance of Data::Driver::Proxy for *each* query. |
118 |
|
* </pre> |
119 |
* |
* |
120 |
* But the point is: Caching! The actual *data* isn't read redundant! |
* But the point is: Caching! The actual *data* isn't read redundant! |
121 |
* |
* |
122 |
|
* <pre> |
123 |
|
* --- snipped into here from above --- |
124 |
|
* that may use arbitrary code modules as database handlers. |
125 |
|
* It's aims are to get together: |
126 |
|
* o phpHtmlLibs "source-handlers" |
127 |
|
* o PEAR's database handlers |
128 |
|
* o custom ones (e.g. Data::Driver::Proxy object, which talks to a remote rpc server) |
129 |
|
* --- snipped into here from above --- |
130 |
|
* </pre> |
131 |
|
* |
132 |
* |
* |
133 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
134 |
* |
* |
139 |
* One worker already implemented is Data::Driver::RPC::Remote, which |
* One worker already implemented is Data::Driver::RPC::Remote, which |
140 |
* 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. |
141 |
* |
* |
142 |
|
* <pre> |
143 |
* --- refactored here, but: redundant somehow --- |
* --- refactored here, but: redundant somehow --- |
144 |
* Data::Driver::Proxy uses a PEAR XML::RPC object to actually |
* Data::Driver::Proxy uses a PEAR XML::RPC object to actually |
145 |
* talk HTTP and serialize data chunks to and from XML, |
* talk HTTP and serialize data chunks to and from XML, |
147 |
* It "proxies" arbitrary data chunks a) inside a native php4 session, |
* It "proxies" arbitrary data chunks a) inside a native php4 session, |
148 |
* 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. |
149 |
* --- refactored here, but: redundant somehow --- |
* --- refactored here, but: redundant somehow --- |
150 |
|
* </pre> |
151 |
* |
* |
152 |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
* !!!!!! refactor this to Data::Driver::Proxy !!!!!! <----------------- |
153 |
* |
* |
154 |
* |
* |
155 |
* How to use? |
* <b>How to use?</b> |
156 |
* |
* |
157 |
* Pass an array holding "locator metadata" to the constructor. |
* Pass an array holding "locator metadata" to the constructor. |
158 |
* GenericDataSource takes care of the rest. |
* GenericDataSource takes care of the rest. |
160 |
* Pass an array to the constructor: (e.g.) |
* Pass an array to the constructor: (e.g.) |
161 |
* |
* |
162 |
* 1. doing rpc-calls.... |
* 1. doing rpc-calls.... |
163 |
|
* <code> |
164 |
* $locator = array( |
* $locator = array( |
165 |
* type => 'rpc', |
* type => 'rpc', |
166 |
* metadata => array( Host => 'localhost', Port => '8765' ), |
* metadata => array( Host => 'localhost', Port => '8765' ), |
167 |
* ); |
* ); |
168 |
* $source = new GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
169 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
170 |
|
* </code> |
171 |
* |
* |
172 |
* 2. [proposal] common datahandles.... |
* 2. [proposal] common datahandles.... |
173 |
|
* <code> |
174 |
* $locator = array( |
* $locator = array( |
175 |
* type => 'mysql', |
* type => 'mysql', |
176 |
* dsn => 'known dsn markup', |
* dsn => 'known dsn markup', |
177 |
* ); |
* ); |
178 |
* $source = new GenericDataSource($locator); |
* $source = ne w GenericDataSource($locator); |
179 |
* $this->set_data_source( &$source ); |
* $this->set_data_source( &$source ); |
180 |
|
* </code> |
181 |
* |
* |
182 |
|
* @link http://www.netfrag.org/~joko/ |
183 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
184 |
|
* |
185 |
|
* @link http://www.netfrag.org/~jonen/ |
186 |
* @author Sebastian Utz <seut@tunemedia.de> |
* @author Sebastian Utz <seut@tunemedia.de> |
187 |
|
* |
188 |
* @copyright (c) 2003 - All Rights reserved. |
* @copyright (c) 2003 - All Rights reserved. |
|
* @license GNU LGPL (GNU Lesser General Public License) |
|
189 |
* |
* |
190 |
* @author-url http://www.netfrag.org/~joko/ |
* @link http://www.gnu.org/licenses/lgpl.txt |
191 |
* @author-url http://www.netfrag.org/~jonen/ |
* @license GNU LGPL (GNU Lesser General Public License) |
|
* @license-url http://www.gnu.org/licenses/lgpl.txt |
|
192 |
* |
* |
|
* @package phpHtmlLib |
|
|
* @module GenericDataSource |
|
193 |
* |
* |
194 |
*/ |
* @package org.netfrag.glib |
195 |
|
* @subpackage DataSource |
196 |
/** |
* @name DataSource::Generic |
197 |
* Todo: |
* |
198 |
|
* @todo this: |
199 |
|
* |
200 |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
201 |
|
* o implement another Data::Driver::Proxy container |
202 |
|
* |
203 |
|
* <pre> |
204 |
|
* !!!!!!!! THIS IS THE PROBLEM !!!!!!!! |
205 |
|
* !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
206 |
|
* |
207 |
|
* THE CONFLICT: Beeing in phpHtmlLib *and* DesignPattern::TransparentProxy |
208 |
|
* inheritance trees at the same time, which is *not* possible at |
209 |
|
* declare-time. We *do* need some runtime-infrastructure to solve this! |
210 |
|
* |
211 |
|
* TODO: move build- and check-locator stuff from ObjectList to this place!!! |
212 |
|
* |
213 |
|
* ABOUT: |
214 |
|
* 1. otherwhere: WebApp - scope: |
215 |
|
* x handles page vs. block vs. widget; dispatches MVC-View |
216 |
|
* 2. here: DataSource - scope: |
217 |
|
* x handles bridge to frameworks (e.g. phpHtmlLib) vs. actual data driver libs (PEAR, etc.)) |
218 |
|
* o clean implementation using a DesignPattern::AdapterProxy |
219 |
|
* </pre> |
220 |
* |
* |
|
* o mungle this to be able to be wrapped around phpHtmlLib's own storage-handles |
|
|
* o implement another Data::Driver::Proxy container |
|
221 |
* |
* |
222 |
*/ |
*/ |
|
|
|
|
|
|
|
// !!!!!!!! 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'); |
|
223 |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
class DataSource_Generic extends DesignPattern_AdapterProxy { |
224 |
|
|
225 |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
// !!!!!!!! here is it where we have to break inheritance again !!!!!!!! |
335 |
//$this->_locator->_datasource_type = $query[datasource]; |
//$this->_locator->_datasource_type = $query[datasource]; |
336 |
//$locator[_datasource_type] = $query[datasource]; |
//$locator[_datasource_type] = $query[datasource]; |
337 |
|
|
338 |
|
/** |
339 |
|
* <!-- Autodia --> |
340 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
341 |
|
* $this->_locator = new DataSource_Locator() |
342 |
|
* |
343 |
|
*/ |
344 |
|
|
345 |
// build master locator |
// build master locator |
346 |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
$this->_locator = php::mkComponent('DataSource::Locator', $locator, array( datasource_type => $query[datasource] ) ); |
347 |
//exit; |
//exit; |
388 |
//exit; |
//exit; |
389 |
|
|
390 |
|
|
391 |
|
/** |
392 |
|
* <!-- Autodia --> |
393 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
394 |
|
* $proxy = new DesignPattern_RemoteProxy() |
395 |
|
* |
396 |
|
*/ |
397 |
|
|
398 |
|
|
399 |
// --- Proxy selector/dispatcher ... |
// --- Proxy selector/dispatcher ... |
400 |
|
|
401 |
switch ($this->_locator->_datasource_type) { |
switch ($this->_locator->_datasource_type) { |
491 |
// $this->create_handler(); |
// $this->create_handler(); |
492 |
|
|
493 |
|
|
494 |
|
/** |
495 |
|
* <!-- Autodia --> |
496 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
497 |
|
* $adapter = new DataSource_Adapter_phpHtmlLib_DataListSource() |
498 |
|
* |
499 |
|
*/ |
500 |
|
|
501 |
// V1: |
// V1: |
502 |
//$this->create_adapter($adapter_module, $this->function, $this->arguments); |
//$this->create_adapter($adapter_module, $this->function, $this->arguments); |
503 |
|
|