$value) { // 获取控制器$value的所有方法 $methods = (new ReflectionClass($value))->getMethods(); // 注册路由 foreach ($methods as $method) { // 获取方法注释 @Method $docComment = $method->getDocComment(); if ($method->name === '__construct' || preg_match('/@Method\s+(NO)\b/', $docComment, $matches)) { continue; } $httpMethod = 'any'; // 查询 @Method GET 或者 @Method POST if (preg_match('/@Method\s+(GET|POST|PUT|DELETE|PATCH|OPTIONS|HEAD|ANY)\b/', $docComment, $matches)) { $httpMethod = $matches[1]; } Illuminate\Support\Facades\Route::$httpMethod( $key. '/'. cc_camel_case_to_dash($method->getName()), [$value, conjunction_symbol_processing($method->name)] ); } } } } /** * 连赐福转换小驼峰 * @param $string * @return string */ if(!function_exists('conjunction_symbol_processing')) { function conjunction_symbol_processing($string): string { $string = str_replace('-', ' ', $string); // 将连字符替换为空格 $string = ucwords($string); // 将每个单词的首字母大写 $string = str_replace(' ', '', $string); // 空格删除 $string[0] = lcfirst($string)[0]; // 首字母小写 return $string; } } // 小驼峰转换- if ( !function_exists('cc_camel_case_to_dash') ) { function cc_camel_case_to_dash($str): string { return strtolower(preg_replace('/([a-z])([A-Z])/', '$1-$2', $str)); } }