* @day: 2020/9/12 */ namespace app\controller\admin; use crmeb\basic\BaseController; use think\helper\Str; class Test extends BaseController { public function index() { } public function rule() { $this->app = app(); $rule = request()->get('rule', 'storeapi'); $this->app->route->setTestMode(true); $this->app->route->clear(); $path = $this->app->getRootPath() . 'route' . DIRECTORY_SEPARATOR; $files = is_dir($path) ? scandir($path) : []; foreach ($files as $file) { if (strpos($file, '.php')) { include $path . $file; } } $ruleList = $this->app->route->getRuleList(); $ruleNewList = []; foreach ($ruleList as $item) { if (Str::contains($item['rule'], $rule)) { $ruleNewList[] = $item; } } foreach ($ruleNewList as $key => &$value) { $only = $value['option']['only'] ?? []; $route = is_string($value['route']) ? explode('/', $value['route']) : []; $value['route'] = is_string($value['route']) ? $value['route'] : ''; $action = $route[count($route) - 1] ?? null; if ($only && $action && !in_array($action, $only)) { unset($ruleNewList[$key]); } $except = $value['option']['except'] ?? []; if ($except && $action && in_array($action, $except)) { unset($ruleNewList[$key]); } } echo " 路由地址列表
路由地址列表
"; $allAction = ['delete', 'index', 'update', 'edit', 'save', 'create', 'read']; foreach ($ruleNewList as $route) { $option = $route['option']['real_name'] ?? null; if (is_array($option)) { foreach ($allAction as $action) { if (Str::contains($route['route'], $action)) { $real_name = $option[$action] ?? ''; } } } else { $real_name = $option; } $rule = $route['rule']; echo ""; } echo "
请求方式 接口地址 接口名称 接口方法
$route[method] " . htmlspecialchars($rule) . " $real_name $route[route]
"; } }