| 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 | //  Revision 1.6  2003/02/28 04:18:13  joko | 
| 10 | //  + special-case-handling for single argument pass-in | //  + special-case-handling for single argument pass-in | 
| 11 | //  + testing with constructor autocalling: not used for now since weird sideeffects occoured! | //  + testing with constructor autocalling: not used for now since weird sideeffects occoured! | 
| 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 | // patch arglist if all arguments are passed in as a single array | 
| 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 | } | } |