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