isDir() && !$module->isDot()) { $moduleName = $module->getFilename(); $controllerDir = $module->getPathname() . '/controller'; if (is_dir($controllerDir)) { $controllers = []; $controllerIterator = new DirectoryIterator($controllerDir); foreach ($controllerIterator as $controller) { if ($controller->isFile() && $controller->getExtension() === 'php') { $controllerName = basename($controller->getFilename(), '.php'); if($controllerName ==='Base') continue; $controllerClass = "app\\{$moduleName}\\controller\\{$controllerName}"; require_once $controller->getPathname(); if (class_exists($controllerClass)) { $methods = get_class_methods($controllerClass); $actions = array_filter($methods, function ($method) { return !in_array($method, ['__construct']); }); $controllers[$controllerName] = $actions; // 生成控制器文件注释 generateControllerComment($rootDir.'/extend/lib/'.$moduleName.'/'.strtolower($controller->getFilename()), $actions); } } } if (!empty($controllers)) { $modules[$moduleName] = $controllers; } } } } // 打印结果 echo json_encode($modules, JSON_PRETTY_PRINT); // 生成控制器文件注释 function generateControllerComment($filePath, $actions) { $config=[]; if(file_exists($filePath)){ $config = include $filePath; } $methodDocBlocks = []; foreach ($actions as $action) { if(isset($config[$action])) continue; $methodDocBlocks[] = <<[ 'name'=>'', "msg"=>"", "resplace"=>[], ], DOCBLOCK; } if (empty($methodDocBlocks)) return; // 确保目录存在 $dir = dirname($filePath); if (!is_dir($dir)) { mkdir($dir, 0777, true); } // 如果文件不存在,创建空文件 if (!file_exists($filePath)) { file_put_contents($filePath, '