自定义实例化class

class ExecuteHelper
{
    /**
     * @param string $classPath 实例化类名路径
     * @param string $method 方法
     * @param array $params 参数
     * @throws NotFoundHttpException
     */
    public static function map($classPath, $method, $params)
    {
        if (!class_exists($classPath))
        {
            throw new NotFoundHttpException($classPath . '未找到');
        }

        /* @var $class \backend\interfaces\WechatMessageInterface */
        $class = new $classPath;
        if (!method_exists($class, $method))
        {
            throw new NotFoundHttpException($classPath . '/' . $method . ' 方法未找到');
        }

        return $class->run($params);
    }
}

  

posted @ 2019-03-28 11:15  百事可口  阅读(109)  评论(0编辑  收藏  举报