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