include_once $filename;
}
- public static function loadFunction($function)
+ public static function callFunction($function, array $args)
{
- if (function_exists($function))
- return;
-
- if (preg_match('/^(\w+)::\w+$/', $function, $m))
- return; // nothing to do. autoloader will load a class.
-
- $elts = explode('_', $function);
- array_pop($elts);
- $file = '/' . strtolower(implode(DIRECTORY_SEPARATOR, $elts)).'.php';
-
- self::include_existing(IPF::$settings['ipf_path'] . $file);
- self::include_existing(IPF::$settings['project_path'] . $file);
-
- if (!function_exists($function))
- throw new IPF_Exception('Impossible to load the function: '.$function.' in '.$file);
+ if (is_array($function)) {
+ // object/class method
+ $callable = $function;
+ } elseif (preg_match('/^(\w+)::(\w+)$/', $function, $m)) {
+ // static method
+ $callable = array($m[1], $m[2]);
+ } else {
+ // plain function
+ if (!function_exists($function)) {
+ $elts = explode('_', $function);
+ array_pop($elts);
+ $file = '/' . strtolower(implode(DIRECTORY_SEPARATOR, $elts)).'.php';
+
+ self::include_existing(IPF::$settings['ipf_path'] . $file);
+ self::include_existing(IPF::$settings['project_path'] . $file);
+
+ if (!function_exists($function))
+ throw new IPF_Exception('Impossible to load the function: '.$function.' in '.$file);
+ }
+ $callable = $function;
+ }
+ return call_user_func_array($callable, $args);
}
public static function getUploadPath()
if ($request) {
$params = array_merge(array('request' => $request), $params);
foreach (IPF::get('template_context_processors', array()) as $proc) {
- IPF::loadFunction($proc);
- $params = array_merge($proc($request), $params);
+ $c = IPF::callFunction($proc, array($request));
+ $params = array_merge($c, $params);
}
foreach (IPF_Project::getInstance()->appList() as $app) {
$params = array_merge($app->templateContext($request), $params);
if ($func) {
try {
- IPF::loadFunction($func);
- $r = $func($req, $match);
+ $r = IPF::callFunction($func, array($req, $match));
if (!is_a($r, 'IPF_HTTP_Response')) {
return self::response500(new IPF_Exception('function '.$func.'() must return IPF_HTTP_Response instance'));
}