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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Mon Feb 3 14:46:57 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
Changes since 1.2: +23 -25 lines
+ wrapped calls to available initializers (constructors, declared startup methods)
- moved logger-code to DesignPattern::Logger

1 joko 1.1 <?
2     // ---------------------------------------------------------------------------
3 joko 1.3 // $Id: Bridge.php,v 1.2 2003/02/03 05:01:27 joko Exp $
4 joko 1.1 // ---------------------------------------------------------------------------
5 joko 1.2 // $Log: Bridge.php,v $
6 joko 1.3 // Revision 1.2 2003/02/03 05:01:27 joko
7     // + now attributes can get passed in to the constructors
8     //
9 joko 1.2 // Revision 1.1 2003/02/03 03:33:48 joko
10     // + initial commit
11     //
12 joko 1.1 // ---------------------------------------------------------------------------
13    
14    
15     class DesignPattern_Bridge extends DesignPattern_Logger {
16    
17 joko 1.2 function DesignPattern_Bridge($classname, $attributes = null) {
18 joko 1.3 //print "init_bridge!<br>";
19 joko 1.2 //return $this->_mkInstance($classname, $attributes);
20 joko 1.3 //$this->_init_logger("../core/var/log/logfile.txt", 1);
21     //parent::constructor();
22 joko 1.2 $this = $this->_mkInstance($classname, $attributes);
23 joko 1.3 //parent::constructor();
24     // $this->_init_logger("../core/var/log/logfile.txt", 1);
25     //print Dumper($this);
26     //parent::DesignPattern_Logger();
27 joko 1.2 //return $this;
28 joko 1.1 }
29    
30 joko 1.2 function &_mkInstance($classname, $attributes = null) {
31 joko 1.3 parent::constructor();
32 joko 1.1 $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG );
33 joko 1.2 if (isset($attributes)) {
34     $instance = new $classname($attributes);
35     } else {
36     $instance = new $classname;
37     }
38 joko 1.3 //$this->log("ok", LOG_DEBUG);
39 joko 1.2 return $instance;
40 joko 1.1 }
41    
42     function _mkEmbeddedObjects($args) {
43    
44 joko 1.3 $this->log( get_parent_class($this) . "->_mkEmbeddedObjects( parent='" . $args[parent_name] . "' )", LOG_DEBUG );
45     //$this->log( get_parent_class($this) . "->_init_helpers: instantiating helper objects below '" . get_class($this) . "::'", LOG_DEBUG );
46 joko 1.1
47     foreach ($args[class_names] as $classname) {
48    
49     // build objectname from classname
50     // - make lowercase
51     // - strip leading "Xyz_" ('Site_' here)
52     $objectname = $classname;
53     $objectname = str_replace('Site_', '', $objectname);
54     $objectname = strtolower($objectname);
55    
56     // create new instance of helper object by classname
57     $this->$objectname = &$this->_mkInstance($classname);
58    
59     // create additional references to helper object with other names if requested
60     // the intention is (e.g.) to migrate objects over to new reference-names when development progresses and ...
61     // ... refactoring the object hierarchy is needed, but ...
62     // ... you wanna provide the old reference names as "fallbacks" for old code using the libs
63     if (is_array($args[ref_names])) {
64     foreach ($args[ref_names] as $ref_name) {
65     //print "mkRef: $ref_name<br>";
66     $this->$ref_name = &$this->$objectname;
67     }
68     }
69    
70     // helper gets reference to ourselves as a parent
71     $this->$objectname->$args[parent_name] = &$this;
72    
73 joko 1.3 $this->_call_initializer($objectname, 'constructor');
74 joko 1.1 if ( $method = $args[run] ) {
75 joko 1.3 $this->_call_initializer($objectname, $method);
76 joko 1.1 }
77    
78     }
79    
80     }
81    
82 joko 1.3 function _call_initializer($objectname, $method) {
83     if (method_exists($this->$objectname, $method)) {
84     $this->log( get_class($this) . "->_call_initializer: autocalling \$this->" . $objectname . "->$method()", LOG_DEBUG );
85     $this->$objectname->$method();
86     }
87 joko 1.1 }
88 joko 1.3
89 joko 1.1
90     }
91     ?>

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