Add support for calling methods on object instance's.

Allows users to pass an instance of a class in to the Flight routes function, and invoke methods on it in a non-static context.

Example usage:

$obj = new Obj();
Flight::route('/myMethod', array($obj,'myMethod'));
pull/13/head
Bag 13 years ago
parent fc10a50ca3
commit b8dc7ae4f3

@ -176,19 +176,21 @@ class Dispatcher {
public static function invokeMethod($func, array &$params = array()) { public static function invokeMethod($func, array &$params = array()) {
list($class, $method) = $func; list($class, $method) = $func;
$instance = is_object($class);
switch (count($params)) { switch (count($params)) {
case 0: case 0:
return $class::$method(); return ($instance) ? $class->$method() : $class::$method();
case 1: case 1:
return $class::$method($params[0]); return ($instance) ? $class->$method($params[0]) : $class::$method($params[0]);
case 2: case 2:
return $class::$method($params[0], $params[1]); return ($instance) ? $class->$method($params[0], $params[1]) : $class::$method($params[0], $params[1]);
case 3: case 3:
return $class::$method($params[0], $params[1], $params[2]); return ($instance) ? $class->$method($params[0], $params[1], $params[2]) : $class::$method($params[0], $params[1], $params[2]);
case 4: case 4:
return $class::$method($params[0], $params[1], $params[2], $params[3]); return ($instance) ? $class->$method($params[0], $params[1], $params[2], $params[3]) : $class::$method($params[0], $params[1], $params[2], $params[3]);
case 5: case 5:
return $class::$method($params[0], $params[1], $params[2], $params[3], $params[4]); return ($instance) ? $class->$method($params[0], $params[1], $params[2], $params[3], $params[4]) : $class::$method($params[0], $params[1], $params[2], $params[3], $params[4]);
default: default:
return call_user_func_array($func, $params); return call_user_func_array($func, $params);
} }

Loading…
Cancel
Save