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