Obtain the names and comments of all function methods in ThinkPHP3.2. you can run the <;? PhpnamespaceHomeController; useCommonControllerBaseController; classAuthControllerextendsBaseController {*** @ ccindex obtain all function method names and comments from ThinkPHP 3.2 on the home page, which can be fully run.
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, $ controller, $ action); $ I ++ ;}}} echo''; Print_r ($ data );} /*** @ cc get all controller names ** @ param $ module ** @ return array | null */protected function getController ($ 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 */protected 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 some 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 function annotation ** @ param $ module Home * @ param $ controller Auth * @ param $ action index ** @ return string annotation **/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 ;}}
The annotations must be in a fixed format,
/*** @ Cc index homepage */
Applicable to ThinkPHP 3.2.2. it is suitable for extracting all controllers and method names directly for auth authentication and obtaining comments. Very convenient.
Refer:
1. http://www.thinkphp1.cn/code/718.html
2. http://www.thinkphp1.cn/topic/10357.html