Thinkphp 3.2 Gets all the function method names, as well as comments, that are fully operational
Getcontroller ($module); foreach ($all _controller as $controller) {$controller _name = $controller; $all _action = $this->getaction ($module, $controller _name); foreach ($all _action as $action) {$data [$i] = array (' name ' = = $module. ') /'. $controller. '/' . $action, ' status ' = 1, ' desc ' = $this->get_cc_desc ($module, $control Ler, $action)); $i + +; }}} ' echo ''; Print_r ($data); /** * @cc Get all Controller names * * @param $module * * @return array|null */protected function Getcon Troller ($module) {if (empty ($module)) return null; $module _path = App_path. '/' . $module. '/controller/'; Controller path if (!is_dir ($module _path)) return null; $module _path. = '/*.class.php '; $ary _files = glob ($module _path); foreach ($ary _files as $file) {if (Is_dir ($file)) {continue; }else {$files [] = basename ($file, C (' Default_c_layer '). Class.php '); }} return $files; /** * @cc Get all method names * * @param $module * @param $controller * * @return array|null */P rotected function Getaction ($module, $controller) {if (empty ($controller)) return null; $content = file_get_contents (App_path. '/'. $module. ' /controller/'. $controller. ' Controller.class.php '); Preg_match_all ("/.*? public.*?function (. *?) \ (. *?\)/I ", $content, $matches); $functions = $matches [1]; Exclude partial methods $inherents _functions = Array ( ' _before_index ' , ' _initialize ', ' __construct ', ' getactionname ', ' isajax ', ' Display ', ' show ', ' fetch ', ' buildhtml ', ' Assign ', ' __set ', ' Get ', ' __get ', ' __isset ', ' __call ', ' Error ', ' success ', ' Ajaxreturn ', ' redirect ', ' __destruct ', ' _empty '); foreach ($functions as $func) {$func = Trim ($func); if (!in_array ($func, $inherents _functions)) {if (strlen ($func) >0) $customer _functions[] = $func; }} return $customer _functions; }/** * @cc get comment of function * * @param $module Home * @param $controller Auth * @param $action Index * * @return String Comment * */protected function Get_cc_desc ($module, $controller, $action) {$desc = $module. ' \controller\\ '. $controller. ' Controller '; $func = new \reflectionmethod (new $desc (), $action); $tmp = $func->getdoccomment (); $flag = Preg_match_all ([email protected] (. *?) \n/', $tmp, $tmp); $tmp = Trim ($tmp [1][0]); $tmp = $tmp! = "? $tmp: ' None '; return $tmp; }}
Where annotations must be in a fixed format,
/* * * @cc Index homepage */
Suitable for thinkphp 3.2.2, suitable for auth authentication, directly extracts all controller and method name, can obtain the annotation. Very convenient.
Reference:
1, http://www.thinkphp.cn/code/718.html
2, http://www.thinkphp.cn/topic/10357.html