/[cvs]/nfo/php/libs/org.netfrag.glib/DesignPattern/Proxy.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.glib/DesignPattern/Proxy.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Mon Mar 3 22:05:25 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
abstract implementation...  ;-)

1 <?php
2
3 /**
4 * This file contains the DesignPattern::Proxy class.
5 *
6 * @author Andreas Motl <andreas.motl@ilo.de>
7 * @module DesignPattern::Proxy
8 *
9 */
10
11 /**
12 * $Id: MVC.php,v 1.4 2003/03/01 22:44:54 joko Exp $
13 *
14 * $Log: MVC.php,v $
15 *
16 */
17
18
19 /**
20 * --- An attempt to implement some software design patterns...
21 * --- ProxyPattern
22 *
23 * --- http://c2.com/cgi-bin/wiki?ProxyPattern
24 *
25 * @author Andreas Motl <andreas.motl@ilo.de>
26 * @copyright (c) 2003 - All Rights reserved.
27 * @license GNU LGPL (GNU Lesser General Public License)
28 *
29 * @author-url http://www.netfrag.org/~joko/
30 * @license-url http://www.gnu.org/licenses/lgpl.txt
31 *
32 * @package org.netfrag.glib
33 * @module DesignPattern::Proxy
34 *
35 */
36
37 /**
38 * Todo:
39 *
40 * x DesignPattern::DecoratorProxy (->decorate)
41 * x DesignPattern::TransparentProxy (->make_transparent)
42 * o DesignPattern::MultiProxy (->both???) (diamond inheritance? possible in php?)
43 * o DesignPattern::GenericAdapterProxy???
44 * o no 'locator/query' or 'type/component'
45 * o even more generic: just 'adapter_metadata' (-> global adapter registry?)
46
47
48 *
49 *
50 */
51
52 /**
53 * Load required modules:
54 *
55 */
56 loadModule('Class::Logger');
57
58 class DesignPattern_Proxy extends Class_Logger {
59
60 /**
61 * This holds some information about the tracing level.
62 *
63 */
64 var $_debug = array(
65 notice => 0,
66 trace => 0,
67 payload => 0,
68 );
69
70 var $_component_name;
71 var $_component_options;
72
73 /**
74 * This var holds the Handler object
75 * that is used to do the work.
76 * It acts as a dispatcher combining result caching.
77 * It is assumed that this provides 4 methods:
78 * queryData() - execute a query against a data storage
79 * querySchema() - execute a query against underlying storage metadata
80 * sendCommand() - send a command against an arbitrary execution engine
81 * ... or others! (these are just proposals for convenience)
82 *
83 */
84 var $_handler = NULL;
85
86
87 /**
88 * This var holds options fed to the Proxy object
89 * These are built from locator metadata (_locator) and query arguments (_query)
90 * It's a simple structured hash:
91 * $proxy_options = array(
92 * method => '<remote-method-name>',
93 * args => array('list', 'of', 'arguments')
94 * );
95 *
96 */
97 var $_handler_options = NULL;
98
99
100 function about() {
101 $this->_about =
102 <<<ABOUT
103 * --- DesignPattern::Proxy
104 * --- http://cvs.netfrag.org/nfo/php/libs/org.netfrag.glib/DesignPattern/Proxy.php
105 *
106 * http://c2.com/cgi-bin/wiki?ProxyPattern says...
107 * Intent: Provide a surrogate or placeholder for another object to control access to it.
108 * http://www.fluffycat.com/java/patterns.html says...
109 * One class controls the creation of and access to objects in another class.
110
111 ABOUT;
112 }
113
114
115 function constructor($handler = array()) {
116 if (sizeof($handler)) {
117 $this->set_handler($handler);
118 }
119 $this->create_handler();
120 $this->call_handler();
121 }
122
123 /*
124 function _abstract_method($method) {
125 $package = get_class($this);
126 $package_p = get_parent_class($this);
127 user_error("DesignPattern::Proxy.$package_p.$package: Please implement method '$method'.");
128 }
129 */
130
131
132 /**
133 * Directly inject a Handler instance to use.
134 *
135 * @param Handler object - &$handler
136 *
137 */
138 function set_handler( &$handler ) {
139 $this->_handler = &$handler;
140 }
141
142 function &get_handler() {
143 return $this->_handler;
144 }
145
146 function call_handler() {
147 $this->_abstract_method('call_handler', 'DesignPattern::Proxy');
148 }
149
150 function set_component_name($name) {
151 $this->_component_name = $name;
152 }
153 function get_component_name() {
154 return $this->_component_name;
155 }
156 function set_component_options($options) {
157 $this->_component_options= $options;
158 }
159 function get_component_options() {
160 return $this->_component_options;
161 }
162
163 function create_handler() {
164 //print "DesignPattern::Proxy->create_handler<br/>";
165 //print "comp: " . $this->get_component_name() . "<br/>";
166 //print "comp: " . $this->get_component_options() . "<br/>";
167 $handler = php::mkComponent( $this->get_component_name(), $this->get_component_options() );
168 //print Dumper($handler);
169 //exit;
170
171 $this->set_handler( $handler );
172 }
173
174
175 }
176
177 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed