| 13 |
* $Id$ |
* $Id$ |
| 14 |
* |
* |
| 15 |
* $Log$ |
* $Log$ |
| 16 |
|
* Revision 1.6 2003/04/04 17:33:49 joko |
| 17 |
|
* updated/enhanced/fixed behaviour of 'function create_stub_function' |
| 18 |
|
* |
| 19 |
|
* Revision 1.5 2003/03/28 03:05:20 joko |
| 20 |
|
* minor update: fixed labels, modified debugging level |
| 21 |
|
* |
| 22 |
|
* Revision 1.4 2003/03/10 22:58:45 joko |
| 23 |
|
* + fixed metadata for phpDocumentor |
| 24 |
|
* |
| 25 |
* Revision 1.3 2003/03/05 23:16:46 joko |
* Revision 1.3 2003/03/05 23:16:46 joko |
| 26 |
* updated docu - phpDocumentor is very strict about its 'blocks'... |
* updated docu - phpDocumentor is very strict about its 'blocks'... |
| 27 |
* |
* |
| 48 |
* This tries to mimic a very small subset of the |
* This tries to mimic a very small subset of the |
| 49 |
* functionality of CPAN's Exporter. |
* functionality of CPAN's Exporter. |
| 50 |
* |
* |
| 51 |
|
* <pre> |
| 52 |
* x export_symbol |
* x export_symbol |
| 53 |
* x export_symbols |
* x export_symbols |
| 54 |
* |
* |
|
* <pre> |
|
| 55 |
* Synopsis: |
* Synopsis: |
| 56 |
* <code> |
* <code> |
| 57 |
* define('EXPORT_OK', 'loadModule mkInstance' ); |
* define('EXPORT_OK', 'loadModule mkInstance' ); |
| 86 |
* |
* |
| 87 |
* @link http://search.cpan.org/author/JHI/perl-5.8.0/lib/Exporter.pm |
* @link http://search.cpan.org/author/JHI/perl-5.8.0/lib/Exporter.pm |
| 88 |
* |
* |
| 89 |
* @todo |
* @todo (x) look at http://www.php.net/manual/en/function.method-exists.php |
| 90 |
* <pre> |
* @todo (x) $bool_exists = (in_array(strtolower($methodName), get_class_methods($className))); |
| 91 |
* x look at http://www.php.net/manual/en/function.method-exists.php |
* @todo (x) -> implemented in php::class_has_method |
|
* x $bool_exists = (in_array(strtolower($methodName), get_class_methods($className))); |
|
|
* x -> implemented in php::class_has_method |
|
|
* </pre> |
|
| 92 |
* |
* |
| 93 |
*/ |
*/ |
| 94 |
class Exporter { |
class Exporter { |
| 206 |
static $target_cache; |
static $target_cache; |
| 207 |
|
|
| 208 |
if (!php::class_has_method($source_class, $source_name)) { |
if (!php::class_has_method($source_class, $source_name)) { |
| 209 |
user_error("Exporter error: class '$source_class' does not implement method '$source_name', will skip exporting this symbol."); |
user_error("Exporter::create_stub_function - Error: class '$source_class' does not implement method '$source_name', will skip exporting this symbol."); |
| 210 |
return; |
return; |
| 211 |
} |
} |
| 212 |
|
|
| 213 |
// prevent redeclarations |
// prevent redeclarations |
| 214 |
if ($target_cache[$target_name]) { |
if ($target_cache[$target_name]) { |
| 215 |
$msg = "php::create_stub_function: already declared: $target_name"; |
$msg = "Exporter::create_stub_function - Warning: already declared: $target_name"; |
| 216 |
php::append_log($msg, PEAR_LOG_ERR); |
php::append_log($msg, PEAR_LOG_DEBUG); |
| 217 |
return 1; |
return 1; |
| 218 |
} else { |
} else { |
| 219 |
$target_cache[$target_name]++; |
$target_cache[$target_name]++; |
| 226 |
//function &$target_name() { \$args = func_get_args(); return call_user_func_array(array($source_class, $source_name), &\$args); } |
//function &$target_name() { \$args = func_get_args(); return call_user_func_array(array($source_class, $source_name), &\$args); } |
| 227 |
//function &$target_name() { \$args = php::array_shrink(func_get_args()); return call_user_func_array(array($source_class, $source_name), &\$args); } |
//function &$target_name() { \$args = php::array_shrink(func_get_args()); return call_user_func_array(array($source_class, $source_name), &\$args); } |
| 228 |
//function &$target_name() { \$args = Exporter::wrap_args(func_get_args()); return call_user_func_array(array($source_class, $source_name), &\$args); } |
//function &$target_name() { \$args = Exporter::wrap_args(func_get_args()); return call_user_func_array(array($source_class, $source_name), &\$args); } |
| 229 |
|
|
| 230 |
|
// taha that's it! |
| 231 |
$stub = |
$stub = |
| 232 |
<<<TPL_FUNC |
<<<TPL_FUNC |
| 233 |
function &$target_name() { |
function &$target_name() { |
| 234 |
\$args = php::array_shrink(func_get_args()); |
\$passthru = php::array_shrink(func_get_args()); |
| 235 |
return call_user_func_array(array('$source_class', '$source_name'), &\$args); |
if (is_array(\$passthru)) { |
| 236 |
|
return call_user_func_array(array('$source_class', '$source_name'), &\$passthru); |
| 237 |
|
} else { |
| 238 |
|
return call_user_func(array('$source_class', '$source_name'), &\$passthru); |
| 239 |
|
} |
| 240 |
} |
} |
| 241 |
|
// signal good |
| 242 |
|
return 1; |
| 243 |
TPL_FUNC; |
TPL_FUNC; |
| 244 |
|
|
| 245 |
/* |
/* |
| 246 |
// alternative |
// possible alternative? not yet... |
| 247 |
$function = <<<TPL_FUNC |
$function = <<<TPL_FUNC |
| 248 |
class $target_class() { |
class $target_class() { |
| 249 |
function &$target_name() { return $source_class::$source_name(func_get_args()); } |
function &$target_name() { return $source_class::$source_name(func_get_args()); } |
| 254 |
// debug |
// debug |
| 255 |
//print "selected stub: <br/>$stub<br/>"; |
//print "selected stub: <br/>$stub<br/>"; |
| 256 |
|
|
| 257 |
eval($stub); |
// V1 |
| 258 |
|
//eval($stub); |
| 259 |
|
//return 1; |
| 260 |
|
|
| 261 |
return 1; |
// V2 |
| 262 |
|
return eval($stub); |
| 263 |
|
|
| 264 |
} |
} |
| 265 |
|
|