This article describes how to obtain the names and comments of all function methods in ThinkPHP3.2, which can be fully run. For more information about PHP tutorials, see. Obtain all function method names and comments in ThinkPHP 3.2, and run the following command:
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 ('/@ cc (.*?) \ 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、www.thinkphp1.cn/code/718.html2、www.thinkphp1.cn/topic/10357.html
The above describes how to obtain the names and comments of all function methods in ThinkPHP 3.2, which is fully runable, including related content. For more information, see PHP Chinese network (www.php1.cn )!