<?php

/**
 * Description of Debug
 * 已经不用amfphp作为传输层了.所以删除了其框架,
 * 但是,其BackOffice的调试页面比较习惯,故此仿写了一个.
 * @author gwang (mail@wanggangzero.cn)
 */
class Debug
{

    //put your code here
    public static function listMethod($class)
    {
        $class_name = is_string($class) ? $class : get_class($class);

        if (class_exists($class_name)) {
            echo "\n <b>$class_name</b>";
            echo "\n<ul>";
            $methods = get_class_methods($class_name);
            $reflector = new ReflectionClass($class_name);
            $methods = $reflector->getMethods();

            foreach ($methods as $method) {

                if (substr($method->name, 0, 1) == '_') {
                    //methods starting with a '_' as they are reserved, so filter them out
                    continue;
                }
                $mname = $method->name;
                echo "<script type='text/javascript' >" . " params_$mname=" . json_encode($method->getParameters()) . ';</script>';
                echo "\n <li><a onclick='updateCallDialog(\"" . urlencode($class_name) . "\",\"" . $mname . "\", params_$mname );' >  $mname  </a></li>";
            }
            echo "\n</ul>";
        }
    }

    /**
     * 调用函数
     * @param type $class
     * @param type $method
     * @return type
     */
    public static function fire_theme_method($class, $method)
    {
        $fire_args = array();

        $reflection = new ReflectionMethod($class, $method);

        foreach ($reflection->getParameters() AS $arg) {
            $fire_args[] = $arg->name;
        }

        return call_user_func_array(array($class, $method), $fire_args);
    }

}
