/[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.7 by joko, Mon Mar 10 23:30:30 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     *
9   *   *
10   */   */
11    
12  /**  
13    /**
14     *
15     *
16     * <b>Cvs-Log:</b>
17     *
18     * <pre>
19   * $Id$   * $Id$
20   *   *
21   * $Log$   * $Log$
22     * Revision 1.7  2003/03/10 23:30:30  joko
23     * + fixed metadata for phpDocumentor
24     *
25     * Revision 1.6  2003/03/10 22:31:56  joko
26     * + fixed metadata for phpDocumentor
27     *
28     * Revision 1.5  2003/03/05 17:28:43  joko
29     * updated docu (phpDocumentor testing....)
30     *
31     * Revision 1.4  2003/03/05 16:32:18  joko
32     * updated docu (phpDocumentor testing....)
33     *
34     * Revision 1.3  2003/03/05 16:10:17  joko
35     * updated docu (phpDocumentor testing....)
36     *
37     * Revision 1.2  2003/03/05 12:12:42  joko
38     * re-renamed methods and privates: _handler becomes _proxy again
39     *
40   * Revision 1.1  2003/03/03 22:05:25  joko   * Revision 1.1  2003/03/03 22:05:25  joko
41   * abstract implementation...  ;-)   * abstract implementation...  ;-)
42     * </pre>
43     *
44   *   *
45     */
46    
47    
48    /**
49     * Load required modules:
50   *   *
51   */   */
52    loadModule('Class::Logger');
53    
54    
55  /**  /**
56   * --- An attempt to implement some software design patterns...   * An attempt to implement some software design patterns...
57   * --- ProxyPattern   * --- ProxyPattern
58   *   *
59   * --- http://c2.com/cgi-bin/wiki?ProxyPattern   * @link http://c2.com/cgi-bin/wiki?ProxyPattern
60   *   *
61   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
62     * @link http://www.netfrag.org/~joko/
63     *
64   * @copyright (c) 2003 - All Rights reserved.   * @copyright (c) 2003 - All Rights reserved.
65   * @license GNU LGPL (GNU Lesser General Public License)   * @license GNU LGPL (GNU Lesser General Public License)
66   *   * @link http://www.gnu.org/licenses/lgpl.txt
  * @author-url http://www.netfrag.org/~joko/  
  * @license-url http://www.gnu.org/licenses/lgpl.txt  
67   *   *
68   * @package org.netfrag.glib   * @package org.netfrag.glib
69   * @module DesignPattern::Proxy   * @subpackage DesignPattern
70   *   * @name DesignPattern::Proxy
  */  
   
 /**  
  * Todo:  
  *  
  *    x DesignPattern::DecoratorProxy  (->decorate)  
  *    x DesignPattern::TransparentProxy  (->make_transparent)  
  *    o DesignPattern::MultiProxy   (->both???) (diamond inheritance? possible in php?)  
  *    o DesignPattern::GenericAdapterProxy???  
  *      o no 'locator/query' or 'type/component'  
  *      o even more generic: just 'adapter_metadata'    (-> global adapter registry?)  
   
   
71   *   *
72     * @todo (x) DesignPattern::DecoratorProxy  (->decorate)
73     * @todo (x) DesignPattern::TransparentProxy  (->make_transparent)
74     * @todo (o) DesignPattern::MultiProxy   (->both???) (diamond inheritance? possible in php?)
75     * @todo (o) DesignPattern::GenericAdapterProxy???
76     * @todo   (o) no 'locator/query' or 'type/component'
77     * @todo   (o) even more generic: just 'adapter_metadata'    (-> global adapter registry?)
78   *   *
79   */   */
   
 /**  
  * Load required modules:  
  *  
  */  
 loadModule('Class::Logger');  
   
80  class DesignPattern_Proxy extends Class_Logger {  class DesignPattern_Proxy extends Class_Logger {
81    
82    /**    /**
# Line 65  class DesignPattern_Proxy extends Class_ Line 84  class DesignPattern_Proxy extends Class_
84     *     *
85     */     */
86    var $_debug = array(    var $_debug = array(
87      notice => 0,      notice => 1,
88      trace => 0,      trace => 1,
89      payload => 0,      payload => 1,
90    );    );
91    
92    var $_component_name;    var $_component_name;
# Line 84  class DesignPattern_Proxy extends Class_ Line 103  class DesignPattern_Proxy extends Class_
103     * ... or others! (these are just proposals for convenience)     * ... or others! (these are just proposals for convenience)
104     *     *
105     */     */
106    var $_handler = NULL;    var $_proxy = NULL;
107        
108        
109    /**    /**
# Line 97  class DesignPattern_Proxy extends Class_ Line 116  class DesignPattern_Proxy extends Class_
116     *  );     *  );
117     *     *
118     */     */
119    var $_handler_options = NULL;    var $_proxy_options = NULL;
120    
121    
122    function about() {    function about() {
# Line 117  ABOUT; Line 136  ABOUT;
136    
137    function constructor($handler = array()) {    function constructor($handler = array()) {
138      if (sizeof($handler)) {      if (sizeof($handler)) {
139        $this->set_handler($handler);        $this->set_proxy($handler);
140      }      }
141      $this->create_handler();      $this->create_proxy();
142      $this->call_handler();      $this->call_proxy();
143    }    }
144                    
145    /*    /*
# Line 138  ABOUT; Line 157  ABOUT;
157    * @param Handler object - &$handler    * @param Handler object - &$handler
158    *    *
159    */    */
160    function set_handler( &$handler ) {    function set_proxy( &$handler ) {
161        $this->_handler = &$handler;        $this->_proxy = &$handler;
162    }    }
163    
164    function &get_handler() {    function &get_proxy() {
165        return $this->_handler;        return $this->_proxy;
166    }    }
167    
168    function call_handler() {    function call_proxy() {
169      $this->_abstract_method('call_handler', 'DesignPattern::Proxy');      $this->_abstract_method('call_proxy', 'DesignPattern::Proxy');
170    }    }
171    
172    function set_component_name($name) {    function set_component_name($name) {
# Line 156  ABOUT; Line 175  ABOUT;
175    function get_component_name() {    function get_component_name() {
176      return $this->_component_name;      return $this->_component_name;
177    }    }
178    function set_component_options($options) {    function set_component_options_v1() {
179      $this->_component_options= $options;      $options = func_get_args();
180        if (is_array($options)) {
181          if (is_hash($options)) {
182            $this->_component_options = $options;
183          } else {
184            $this->_component_options = array();
185            foreach ($options as $option) {
186              array_push($this->_component_options, $option);
187            }
188          }
189        } else {
190          $this->_component_options = $options;
191        }
192      }
193      function set_component_options() {
194        $options = func_get_args();
195        if (sizeof($options) >= 1) {
196          $this->_component_options = array();
197          foreach ($options as $option) {
198            array_push($this->_component_options, $option);
199          }
200        } else {
201          $this->_component_options = $options;
202        }
203    }    }
204    function get_component_options() {    function get_component_options() {
205      return $this->_component_options;      return $this->_component_options;
206    }    }
207    
208    function create_handler() {    function create_proxy() {
209      //print "DesignPattern::Proxy->create_handler<br/>";      //print "DesignPattern::Proxy->create_proxy<br/>";
210      //print "comp: " . $this->get_component_name() . "<br/>";      //print "comp: " . $this->get_component_name() . "<br/>";
211      //print "comp: " . $this->get_component_options() . "<br/>";      //print "comp: " . $this->get_component_options() . "<br/>";
212      $handler = php::mkComponent( $this->get_component_name(), $this->get_component_options() );      $handler = php::mkComponent( $this->get_component_name(), $this->get_component_options() );
213      //print Dumper($handler);      //print Dumper($handler);
214      //exit;      //exit;
215            
216      $this->set_handler( $handler );      $this->set_proxy( $handler );
217    }    }
218    
219    

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

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