From b8dc7ae4f346c2a591da904689609ee4c499ab3e Mon Sep 17 00:00:00 2001 From: Bag Date: Mon, 30 Jul 2012 19:49:23 +0100 Subject: [PATCH] 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')); --- flight/core/Dispatcher.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index 89b9813..0d5eb32 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -176,19 +176,21 @@ class Dispatcher { public static function invokeMethod($func, array &$params = array()) { list($class, $method) = $func; + $instance = is_object($class); + switch (count($params)) { case 0: - return $class::$method(); + return ($instance) ? $class->$method() : $class::$method(); case 1: - return $class::$method($params[0]); + return ($instance) ? $class->$method($params[0]) : $class::$method($params[0]); 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: - 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: - 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: - 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: return call_user_func_array($func, $params); }