/[cvs]/nfo/php/libs/org.netfrag.glib/Class/Inner.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.glib/Class/Inner.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Tue Mar 11 01:42:59 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.3: +35 -30 lines
+ fixed metadata for phpDocumentor

1 <?
2 /**
3 * This file contains the Class::Inner class.
4 *
5 * @author Andreas Motl <andreas.motl@ilo.de>
6 * @package org.netfrag.glib
7 * @name Class::Inner
8 *
9 */
10
11 /**
12 * <pre>
13 * ---------------------------------------------------------------------------
14 * $Id: Inner.php,v 1.3 2003/03/11 01:12:53 joko Exp $
15 * ---------------------------------------------------------------------------
16 * $Log: Inner.php,v $
17 * Revision 1.3 2003/03/11 01:12:53 joko
18 * + fixed metadata for phpDocumentor
19 *
20 * Revision 1.2 2003/03/05 18:54:43 joko
21 * updated docu - phpDocumentor is very strict about its 'blocks'...
22 *
23 * Revision 1.1 2003/03/03 21:26:30 joko
24 * refactored from DesignPattern::Bridge
25 *
26 * Revision 1.5 2003/02/27 18:09:56 joko
27 * mungled mechanism to shift in and pass on arguments
28 *
29 * Revision 1.4 2003/02/09 17:07:53 joko
30 * + minor update related to new log level constants
31 * + generic argument merger to show full constructor args
32 *
33 * Revision 1.3 2003/02/03 14:46:57 joko
34 * + wrapped calls to available initializers (constructors, declared startup methods)
35 * - moved logger-code to DesignPattern::Logger
36 *
37 * Revision 1.2 2003/02/03 05:01:27 joko
38 * + now attributes can get passed in to the constructors
39 *
40 * Revision 1.1 2003/02/03 03:33:48 joko
41 * + initial commit
42 *
43 * ---------------------------------------------------------------------------
44 * </pre>
45 */
46
47 /**
48 * This requires DesignPattern::Facade as a base class
49 *
50 */
51 loadModule('DesignPattern::Facade');
52
53 /**
54 * Class::Inner
55 *
56 * @author Andreas Motl <andreas.motl@ilo.de>
57 * @copyright (c) 2003 - All Rights reserved.
58 * @license GNU LGPL (GNU Lesser General Public License)
59 *
60 * @link http://www.netfrag.org/~joko/
61 * @link http://www.gnu.org/licenses/lgpl.txt
62 *
63 * @subpackage Class
64 * @name Class::Inner
65 *
66 */
67 class Class_Inner extends DesignPattern_Facade {
68
69 /*
70 var $_parent_class;
71 var $_inner_classes;
72 var $_inner_objects;
73 var $_call_constructor;
74 */
75
76 function perform($args) {
77 $this->__create_inners($args);
78 }
79
80 function __call_constructor($objectname, $method) {
81 if (method_exists($this->$objectname, $method)) {
82 $this->log( get_class($this) . "->__call_constructor: autocalling \$this->" . $objectname . "->$method()" );
83 $this->$objectname->$method();
84 }
85 }
86
87 function __create_inners($args) {
88
89 $this->log( get_parent_class($this) . "->__create_inners( parent='" . $args[parent_name] . "' )", PEAR_LOG_INFO );
90 //$this->log( get_parent_class($this) . "->_init_helpers: instantiating helper objects below '" . get_class($this) . "::'" );
91
92 //print Dumper($args);
93
94 foreach ($args[class_names] as $classname) {
95
96 // build objectname from classname
97 // - make lowercase
98 // - strip leading "Xyz_" ('Site_' here)
99 $objectname = $classname;
100 $objectname = str_replace('Site_', '', $objectname); // FIXME!!!
101 $objectname = strtolower($objectname);
102
103 // create new instance of helper object by classname
104 // V1:
105 //$this->$objectname = &$this->_mkInstance($classname);
106 // V2:
107 $this->$objectname = &php::mkInstance($classname);
108
109 // create additional references to helper object with other names if requested
110 // the intention is (e.g.) to migrate objects over to new reference-names when development progresses and ...
111 // ... refactoring the object hierarchy is needed, but ...
112 // ... you wanna provide the old reference names as "fallbacks" for old code using the libs
113 if (is_array($args[ref_names])) {
114 foreach ($args[ref_names] as $ref_name) {
115 //print "mkRef: $ref_name<br>";
116 $this->$ref_name = &$this->$objectname;
117 }
118 }
119
120 // helper gets reference to ourselves as a parent
121 $this->$objectname->$args[parent_name] = &$this;
122
123 $this->__call_constructor($objectname, 'constructor');
124 if ( $method = $args[run] ) {
125 $this->__call_constructor($objectname, $method);
126 }
127
128 }
129
130 }
131
132
133
134 // --- old code
135
136 function DesignPattern_Bridge_old() {
137
138 $arg_list = func_get_args();
139 $classname = array_shift($arg_list);
140
141 // expand single argument
142 if (count($arg_list) == 1) {
143 $arg_list = $arg_list[0];
144 }
145 $attributes = &$arg_list;
146
147 //print Dumper($attributes);
148
149 //print "init_bridge!<br>";
150 //return $this->_mkInstance($classname, $attributes);
151 //$this->_init_logger("../core/var/log/logfile.txt", 1);
152 //parent::constructor();
153
154 // V1:
155 $this = $this->_mkInstance($classname, $attributes);
156 // V2: (don't do that - will crash your apache!!! - hehe - it's an infinite loop)
157 //$this = php::mkInstance($classname, $attributes);
158
159 //parent::constructor();
160 // $this->_init_logger("../core/var/log/logfile.txt", 1);
161 //print Dumper($this);
162
163 //return $this;
164 }
165
166 function &_mkInstance_old($classname, $attributes = null) {
167 parent::constructor();
168 $this->log( get_class($this) . "->_mkInstance( classname $classname )" );
169 if (isset($attributes)) {
170 //print Dumper($attributes);
171
172 /*
173 // pass single argument 1:1
174 if (count($attributes) == 1) {
175 $attributes_merged = $attributes[0];
176
177
178
179 // pass hash 1:1
180 } elseif (is_hash($attributes)) {
181 $attributes_merged = $attributes;
182
183 } else {
184 $attributes_merged = $attributes;
185 }
186 */
187
188 $args_pass = array();
189 for ($i=0; $i<=count($attributes); $i++) {
190 array_push($args_pass, '$attributes[' . $i . ']');
191 }
192
193 $arg_string = join(', ', $args_pass);
194
195 /*
196 // merge entries of numerical indexed arrays together into one hash
197 } else {
198 $attributes_merged = array();
199 foreach ($attributes as $entry) {
200 $attributes_merged = array_merge($attributes_merged, $entry);
201 }
202 }
203 */
204
205 //print Dumper($attributes_merged);
206 //print Dumper($attributes);
207 //$instance = new $classname($attributes_merged);
208 //$instance = new $classname($attributes[0]);
209 $evalstr = 'return new $classname(' . $arg_string . ');';
210 $instance = eval($evalstr);
211 //print $evalstr . "<br>";
212 } else {
213 $instance = new $classname;
214 }
215 //$this->log("ok");
216 return $instance;
217 }
218
219 }
220
221
222
223
224 ?>

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