Obtain the method names and comments of all functions in ThinkPHP3.2.

Source: Internet
Author: User
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 )!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.