Thinkphp 3.2 Gets all the function method names, as well as comments, that are fully operational

Source: Internet
Author: User

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)!

  • 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.