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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Wed Mar 5 17:28:43 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.4: +5 -1 lines
updated docu (phpDocumentor testing....)

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

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