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

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