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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Mon Mar 3 22:05:25 2003 UTC revision 1.4 by joko, Wed Mar 5 16:32:18 2003 UTC
# Line 1  Line 1 
1  <?php  <?php
   
2  /**  /**
3   * This file contains the DesignPattern::Proxy class.   * This file contains the DesignPattern::Proxy class
4   *   *
5   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
6   * @module DesignPattern::Proxy   * @package org.netfrag.glib
7     * @name DesignPattern::Proxy
8     * @filesource
9   *   *
10   */   *
11     *
12  /**   *
13     * <b>Cvs-Log:</b>
14     *
15     * <pre>
16   * $Id$   * $Id$
17   *   *
18   * $Log$   * $Log$
19     * Revision 1.4  2003/03/05 16:32:18  joko
20     * updated docu (phpDocumentor testing....)
21     *
22     * Revision 1.3  2003/03/05 16:10:17  joko
23     * updated docu (phpDocumentor testing....)
24     *
25     * Revision 1.2  2003/03/05 12:12:42  joko
26     * re-renamed methods and privates: _handler becomes _proxy again
27     *
28   * Revision 1.1  2003/03/03 22:05:25  joko   * Revision 1.1  2003/03/03 22:05:25  joko
29   * abstract implementation...  ;-)   * abstract implementation...  ;-)
30     * </pre>
31   *   *
32   *   *
33   */   */
34    
35    
36  /**  /**
37   * --- An attempt to implement some software design patterns...   * Load required modules:
38     *
39     */
40    loadModule('Class::Logger');
41    
42    
43    /**
44     * An attempt to implement some software design patterns...
45   * --- ProxyPattern   * --- ProxyPattern
46   *   *
47   * --- http://c2.com/cgi-bin/wiki?ProxyPattern   * @link http://c2.com/cgi-bin/wiki?ProxyPattern
48   *   *
49   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
50     * @link http://www.netfrag.org/~joko/
51     *
52   * @copyright (c) 2003 - All Rights reserved.   * @copyright (c) 2003 - All Rights reserved.
53   * @license GNU LGPL (GNU Lesser General Public License)   * @license GNU LGPL (GNU Lesser General Public License)
54   *   * @link http://www.gnu.org/licenses/lgpl.txt
  * @author-url http://www.netfrag.org/~joko/  
  * @license-url http://www.gnu.org/licenses/lgpl.txt  
55   *   *
56   * @package org.netfrag.glib   * @package org.netfrag.glib
57   * @module DesignPattern::Proxy   * @name DesignPattern::Proxy
  *  
  */  
   
 /**  
  * Todo:  
58   *   *
59     * @todo
60     * <pre>
61   *    x DesignPattern::DecoratorProxy  (->decorate)   *    x DesignPattern::DecoratorProxy  (->decorate)
62   *    x DesignPattern::TransparentProxy  (->make_transparent)   *    x DesignPattern::TransparentProxy  (->make_transparent)
63   *    o DesignPattern::MultiProxy   (->both???) (diamond inheritance? possible in php?)   *    o DesignPattern::MultiProxy   (->both???) (diamond inheritance? possible in php?)
64   *    o DesignPattern::GenericAdapterProxy???   *    o DesignPattern::GenericAdapterProxy???
65   *      o no 'locator/query' or 'type/component'   *      o no 'locator/query' or 'type/component'
66   *      o even more generic: just 'adapter_metadata'    (-> global adapter registry?)   *      o even more generic: just 'adapter_metadata'    (-> global adapter registry?)
67     * </pre>
   
  *  
68   *   *
69   */   */
   
 /**  
  * Load required modules:  
  *  
  */  
 loadModule('Class::Logger');  
   
70  class DesignPattern_Proxy extends Class_Logger {  class DesignPattern_Proxy extends Class_Logger {
71    
72    /**    /**
# Line 65  class DesignPattern_Proxy extends Class_ Line 74  class DesignPattern_Proxy extends Class_
74     *     *
75     */     */
76    var $_debug = array(    var $_debug = array(
77      notice => 0,      notice => 1,
78      trace => 0,      trace => 1,
79      payload => 0,      payload => 1,
80    );    );
81    
82    var $_component_name;    var $_component_name;
# Line 84  class DesignPattern_Proxy extends Class_ Line 93  class DesignPattern_Proxy extends Class_
93     * ... or others! (these are just proposals for convenience)     * ... or others! (these are just proposals for convenience)
94     *     *
95     */     */
96    var $_handler = NULL;    var $_proxy = NULL;
97        
98        
99    /**    /**
# Line 97  class DesignPattern_Proxy extends Class_ Line 106  class DesignPattern_Proxy extends Class_
106     *  );     *  );
107     *     *
108     */     */
109    var $_handler_options = NULL;    var $_proxy_options = NULL;
110    
111    
112    function about() {    function about() {
# Line 117  ABOUT; Line 126  ABOUT;
126    
127    function constructor($handler = array()) {    function constructor($handler = array()) {
128      if (sizeof($handler)) {      if (sizeof($handler)) {
129        $this->set_handler($handler);        $this->set_proxy($handler);
130      }      }
131      $this->create_handler();      $this->create_proxy();
132      $this->call_handler();      $this->call_proxy();
133    }    }
134                    
135    /*    /*
# Line 138  ABOUT; Line 147  ABOUT;
147    * @param Handler object - &$handler    * @param Handler object - &$handler
148    *    *
149    */    */
150    function set_handler( &$handler ) {    function set_proxy( &$handler ) {
151        $this->_handler = &$handler;        $this->_proxy = &$handler;
152    }    }
153    
154    function &get_handler() {    function &get_proxy() {
155        return $this->_handler;        return $this->_proxy;
156    }    }
157    
158    function call_handler() {    function call_proxy() {
159      $this->_abstract_method('call_handler', 'DesignPattern::Proxy');      $this->_abstract_method('call_proxy', 'DesignPattern::Proxy');
160    }    }
161    
162    function set_component_name($name) {    function set_component_name($name) {
# Line 156  ABOUT; Line 165  ABOUT;
165    function get_component_name() {    function get_component_name() {
166      return $this->_component_name;      return $this->_component_name;
167    }    }
168    function set_component_options($options) {    function set_component_options_v1() {
169      $this->_component_options= $options;      $options = func_get_args();
170        if (is_array($options)) {
171          if (is_hash($options)) {
172            $this->_component_options = $options;
173          } else {
174            $this->_component_options = array();
175            foreach ($options as $option) {
176              array_push($this->_component_options, $option);
177            }
178          }
179        } else {
180          $this->_component_options = $options;
181        }
182      }
183      function set_component_options() {
184        $options = func_get_args();
185        if (sizeof($options) >= 1) {
186          $this->_component_options = array();
187          foreach ($options as $option) {
188            array_push($this->_component_options, $option);
189          }
190        } else {
191          $this->_component_options = $options;
192        }
193    }    }
194    function get_component_options() {    function get_component_options() {
195      return $this->_component_options;      return $this->_component_options;
196    }    }
197    
198    function create_handler() {    function create_proxy() {
199      //print "DesignPattern::Proxy->create_handler<br/>";      //print "DesignPattern::Proxy->create_proxy<br/>";
200      //print "comp: " . $this->get_component_name() . "<br/>";      //print "comp: " . $this->get_component_name() . "<br/>";
201      //print "comp: " . $this->get_component_options() . "<br/>";      //print "comp: " . $this->get_component_options() . "<br/>";
202      $handler = php::mkComponent( $this->get_component_name(), $this->get_component_options() );      $handler = php::mkComponent( $this->get_component_name(), $this->get_component_options() );
203      //print Dumper($handler);      //print Dumper($handler);
204      //exit;      //exit;
205            
206      $this->set_handler( $handler );      $this->set_proxy( $handler );
207    }    }
208    
209    

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

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