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 ', ' _after_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 ('/@cc (. *?) \n/', $tmp, $tmp); $tmp = Trim ($tmp [1][0]); $tmp = $tmp! = "? $tmp: ' None '; return $tmp; }}
Where annotations must be in a fixed format,
/** * @cc Index Main Page */
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, WWW.THINKPHP.CN/CODE/718.HTML2, www.thinkphp.cn/topic/10357.html
The above describes the thinkphp 3.2 to get all the function method name, as well as comments, complete can run, including aspects of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!