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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show 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 <?
2 // ---------------------------------------------------------------------------
3 // $Id: Bridge.php,v 1.2 2003/02/03 05:01:27 joko Exp $
4 // ---------------------------------------------------------------------------
5 // $Log: Bridge.php,v $
6 // Revision 1.2 2003/02/03 05:01:27 joko
7 // + now attributes can get passed in to the constructors
8 //
9 // Revision 1.1 2003/02/03 03:33:48 joko
10 // + initial commit
11 //
12 // ---------------------------------------------------------------------------
13
14
15 class DesignPattern_Bridge extends DesignPattern_Logger {
16
17 function DesignPattern_Bridge($classname, $attributes = null) {
18 //print "init_bridge!<br>";
19 //return $this->_mkInstance($classname, $attributes);
20 //$this->_init_logger("../core/var/log/logfile.txt", 1);
21 //parent::constructor();
22 $this = $this->_mkInstance($classname, $attributes);
23 //parent::constructor();
24 // $this->_init_logger("../core/var/log/logfile.txt", 1);
25 //print Dumper($this);
26 //parent::DesignPattern_Logger();
27 //return $this;
28 }
29
30 function &_mkInstance($classname, $attributes = null) {
31 parent::constructor();
32 $this->log( get_class($this) . "->_mkInstance( classname $classname )", LOG_DEBUG );
33 if (isset($attributes)) {
34 $instance = new $classname($attributes);
35 } else {
36 $instance = new $classname;
37 }
38 //$this->log("ok", LOG_DEBUG);
39 return $instance;
40 }
41
42 function _mkEmbeddedObjects($args) {
43
44 $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
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 $this->_call_initializer($objectname, 'constructor');
74 if ( $method = $args[run] ) {
75 $this->_call_initializer($objectname, $method);
76 }
77
78 }
79
80 }
81
82 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 }
88
89
90 }
91 ?>

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