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