讨论数量:
@cnguu get_declared_classes()
只能获取当前class下引用到的类 哈哈 ,咋整 ,比如我请求的是名为user的controller ,那么获取的就是这个控制器用到的类 ,如图
获取模块中所有控制器:
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;
}
}
把所有需要的模块列出来,循环获取控制器,每个控制器循环获取里面的操作,再拼接成路由
@JeffLi
get_declared_classes()
get_class_methods()