tp6 获取所有类方法和注解

全屏阅读
  • 基本信息
  • 作者:
  • 作者已发布:924篇文章
  • 发布时间:2023年01月13日 22:11:20
  • 所属分类:PHP+MySql, THINKPHP
  • 阅读次数:435次阅读
  • 标签:
function getControllers($dir)
{
    $pathList = glob($dir . '/*.php');
    $res = [];
    foreach($pathList as $key => $value) {
        $res[] = basename($value, '.php');
    }
    return $res;
}
function getActions($className, $base='\app\BaseController')
{
    $className = '\app\controller\\'.$className;
    $methods = array();
    $baseMethods = array();
    $rMethods = (new \ReflectionClass($className))->getMethods();
    $rbMethods = (new \ReflectionClass($base))->getMethods();
    foreach ($rMethods as $m) {
        $doc = $m->getDocComment();
        $s = cc_get_desc($doc);
        array_push($methods, $m->getName().'/'.$s);
    }
    foreach ($rbMethods as $m) {
        $doc = $m->getDocComment();
        $s = cc_get_desc($doc);
        array_push($baseMethods, $m->getName().'/'.$s);
    }
    $res = array_diff($methods, $baseMethods);
    return $res;
}

function cc_get_desc($doc)
{
    $tmp = array();
    preg_match_all('/@test(.*?)[\r\n|\n]/', $doc, $tmp);
    return trim($tmp[1][0] ?? "");
}

// 类注解
/**
* class function quanxian 方法注解
* @test 权限
*/

// 调用
$result = getControllers('../app/controller');
dump($result);
foreach ($result as $v) {
    $m = getActions($v);
    dump($m);
}

顶一下
(0)
100%
订阅 回复
踩一下
(0)
100%
» 郑重声明:本文由mpxq168发布,所有内容仅代表个人观点。版权归恒富网mpxq168共有,欢迎转载, 但未经作者同意必须保留此段声明,并给出文章连接,否则保留追究法律责任的权利! 如果本文侵犯了您的权益,请留言。

目前有 0 条留言 其中:访客:0 条, 博主:0 条

给我留言

您必须 [ 登录 ] 才能发表留言!