| 3 |
// $Id$ |
// $Id$ |
| 4 |
// --------------------------------------------------------------------------- |
// --------------------------------------------------------------------------- |
| 5 |
// $Log$ |
// $Log$ |
| 6 |
|
// Revision 1.7 2003/03/01 21:13:39 joko |
| 7 |
|
// modified loadModule (take care!) |
| 8 |
|
// |
| 9 |
|
// Revision 1.6 2003/02/28 04:18:13 joko |
| 10 |
|
// + special-case-handling for single argument pass-in |
| 11 |
|
// + testing with constructor autocalling: not used for now since weird sideeffects occoured! |
| 12 |
|
// o however: rethink it completely! |
| 13 |
|
// |
| 14 |
// Revision 1.5 2003/02/27 16:36:02 joko |
// Revision 1.5 2003/02/27 16:36:02 joko |
| 15 |
// re-allowed underscores ('_') in php classnames |
// re-allowed underscores ('_') in php classnames |
| 16 |
// does this break something? |
// does this break something? |
| 40 |
|
|
| 41 |
function _ns2file($nsName) { |
function _ns2file($nsName) { |
| 42 |
if ($filename = str_replace('::', '/', $nsName)) { |
if ($filename = str_replace('::', '/', $nsName)) { |
|
$filename .= '.php'; |
|
| 43 |
return $filename; |
return $filename; |
| 44 |
} |
} |
| 45 |
} |
} |
| 46 |
|
|
| 47 |
function mkObject() { |
function &mkObject() { |
| 48 |
$arg_list = func_get_args(); |
$arg_list = func_get_args(); |
| 49 |
|
|
| 50 |
|
// patch arglist if all arguments are passed in as a single array |
| 51 |
|
if (count($arg_list) == 1 && is_array($arg_list[0])) { |
| 52 |
|
$arg_list = $arg_list[0]; |
| 53 |
|
} |
| 54 |
|
|
| 55 |
//print Dumper($arg_list); |
//print Dumper($arg_list); |
| 56 |
$namespacedClassname = array_shift($arg_list); |
$namespacedClassname = array_shift($arg_list); |
| 57 |
if (strstr($namespacedClassname, '_')) { |
if (strstr($namespacedClassname, '_')) { |
| 66 |
$classname = str_replace('/', '_', $classname); |
$classname = str_replace('/', '_', $classname); |
| 67 |
} |
} |
| 68 |
$obj = new DesignPattern_Bridge($classname, $attributes); |
$obj = new DesignPattern_Bridge($classname, $attributes); |
| 69 |
|
|
| 70 |
|
// call constructor if possible |
| 71 |
|
// FIXME: take care for side-effects!!! |
| 72 |
|
/* |
| 73 |
|
if (method_exists($obj, 'constructor')) { |
| 74 |
|
$obj->constructor(); |
| 75 |
|
} |
| 76 |
|
*/ |
| 77 |
|
|
| 78 |
return $obj; |
return $obj; |
| 79 |
} |
} |
| 80 |
|
|
| 81 |
function loadModule($namespacedClassname) { |
function loadModule($namespacedClassname, $extension = 'php') { |
| 82 |
if ($filename = _ns2file($namespacedClassname)) { |
if ($filename = _ns2file($namespacedClassname)) { |
| 83 |
require_once($filename); |
if ($extension) { |
| 84 |
|
$filename .= ".$extension"; |
| 85 |
|
} |
| 86 |
|
|
| 87 |
|
// V1: just require |
| 88 |
|
//require_once($filename); |
| 89 |
|
|
| 90 |
|
// V2: check file for existance (didn't work!!! problem with path-style conversion regarding platform running on?) |
| 91 |
|
/* |
| 92 |
|
if (file_exists($filename)) { |
| 93 |
|
require_once($filename); |
| 94 |
|
} else { |
| 95 |
|
//user_error("Could not load module '$namespacedClassname', file '$filename' does not exist."); |
| 96 |
|
} |
| 97 |
|
*/ |
| 98 |
|
|
| 99 |
|
// V3: wrapped through eval (weird) |
| 100 |
|
/* |
| 101 |
|
$evalstring = "return include_once('$filename');"; |
| 102 |
|
$result = eval($evalstring); |
| 103 |
|
if (!$result) { |
| 104 |
|
user_error("DesignPattern::Object: Could not load module '$namespacedClassname', file '$filename' does not exist."); |
| 105 |
|
return; |
| 106 |
|
} |
| 107 |
|
*/ |
| 108 |
|
|
| 109 |
|
// V4: just include |
| 110 |
|
if (!include_once($filename)) { |
| 111 |
|
// TODO: do stack-backtracing here to determine function called two or three levels before!!! |
| 112 |
|
user_error("DesignPattern::Object: Could not load module '$namespacedClassname', file '$filename' does not exist."); |
| 113 |
|
return; |
| 114 |
|
} |
| 115 |
|
|
| 116 |
return 1; |
return 1; |
| 117 |
} |
} |
| 118 |
} |
} |