tp5自定义一个函数php,有啥方案可以获取 TP5 项目中所有的自定义函数?

获取模块中所有控制器:

private function getControllers($module){

if(empty($module)) {

return null;

}

$modulePath = app()->getAppPath() . $module . '/controller/';

if(!is_dir($modulePath)) {

return null;

}

$modulePath .= '*.php';

$matchFiles = glob($modulePath);

$files = [];

foreach ($matchFiles as $file) {

if(is_dir($file)) {

continue;

} else {

$files[] = basename($file, '.php');

}

}

return $files;

}

获取控制器所有操作:

private function getActions($module, $controller){

if(empty($controller)) {

return null;

}

$customerFunctions = [];

$file = app()->getAppPath() . $module . '/controller/' . $controller . '.php';

if(file_exists($file)) {

$content = file_get_contents($file);

preg_match_all("/.*?public.*?function(.*?)\(.*?\)/i", $content, $matches);

$functions = $matches[1];

$excludeFunc = ['__initialize', '__construct'];

foreach ($functions as $func) {

$func = trim($func);

if(!in_array($func, $excludeFunc)) {

$customerFunctions[] = $func;

}

}

return $customerFunctions;

} else {

Log::record('is not file: ' . $file);

return false;

}

}

把所有需要的模块列出来,循环获取控制器,每个控制器循环获取里面的操作,再拼接成路由

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值