00001 <?php
00007 namespace Habari;
00008
00013 class Method
00014 {
00015 public $class;
00016 public $method;
00017
00024 public static function create($class, $method) {
00025 $instance = new Method($class, $method);
00026 return $instance;
00027 }
00028
00035 public function __construct($class, $method) {
00036 $this->class = $class;
00037 $this->method = $method;
00038 }
00039
00044 public function exists() {
00045 return function_exists($this->method_array());
00046 }
00047
00054 public static function dispatch($method, $multiple_optional_args = null)
00055 {
00056 $args = func_get_args();
00057 array_shift($args);
00058 return self::dispatch_array($method, $args);
00059 }
00060
00067 public static function dispatch_array($method, $args = array())
00068 {
00069 if(is_callable($method)) {
00070 return call_user_func_array($method, $args);
00071 }
00072 elseif(is_string($method)) {
00073 array_unshift($args, $method, false);
00074 return call_user_func_array(Method::create('\Habari\Plugins', 'filter'), $args);
00075 }
00076 return false;
00077 }
00078
00083 public function method_array()
00084 {
00085
00086 if(!is_object($this->class) && strpos($this->class, '\\') === false && !class_exists($this->class, true)) {
00087 if(class_exists('\\Habari\\' . $this->class)) {
00088 $this->class = '\\Habari\\' . $this->class;
00089 }
00090 }
00091 return array($this->class, $this->method);
00092 }
00093
00103 public function __invoke() {
00104
00105 $args = func_get_args();
00106 return call_user_func_array($this->method_array(), $args);
00107 }
00108 }