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

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

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