ThinkPHP 3.2 中获取所有函数方法名,以及注释,完整可运行
<?php
namespace Home\Controller;
use Common\Controller\BaseController;
class AuthController extends BaseController{
/**
* @cc index主页面
*/
public function index(){
$modules = array ( 'Home' ); //模块名称
$i = 0;
foreach ( $modules as $module ) {
$all_controller = $this ->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 '<pre>' ;
print_r( $data );
}
/**
* @cc 获取所有控制器名称
*
* @param $module
*
* @return array|null
*/
protected function getController( $module ){
if ( empty ( $module )) return null;
$module_path = APP_PATH . '/' . $module . '/Controller/' ; //控制器路径
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 获取所有方法名称
*
* @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];
//排除部分方法
$inherents_functions = array (<span style= "color: #6a8759;" > '_before_index' <span style= "color: #cc7832;" >,<span style= "color: #6a8759;" > '_after_index' <span style= "color: #cc7832;" >,</span></span></span></span> '_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 获取函数的注释
*
* @param $module Home
* @param $controller Auth
* @param $action index
*
* @return string 注释
*
*/
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 : '无' ;
return $tmp ;
}
}
|
其中注释必须采用固定格式,
/*** @cc index主页面*/
适用于ThinkPHP 3.2.2 ,适合用auth 认证时,直接提取所有的控制器及方法名,可以获取注释。非常方便。
参考:
1、http://www.thinkphp.cn/code/718.html
2、http://www.thinkphp.cn/topic/10357.html
转载于:https://www.cnblogs.com/you-jia/p/4249596.html
ThinkPHP 3.2 中获取所有函数方法名,以及注释,完整可运行相关推荐
- Java中获取当前函数名
Java中获取当前函数名 博客分类: Java JavathreadJDKIDEA 有时候我们需要在程序中获取当前运行的函数名,如何简单的做到这点呢?我们可以用getStackTrace轻松搞定. ...
- Linux-C基础知识学习:C语言作业-将5个学生成绩保存在一个数组中,单独实现一个计算平均成绩的average函数, 在main函数中获取该函数返回的平均值,并打印。
Linux基础知识学习 C语言作业:将5个学生成绩保存在一个数组中,单独实现一个计算平均成绩的average函数, 在main函数中获取该函数返回的平均值,并打印. #include <stdi ...
- java 获取当前方法的名称_Java中获取当前函数名
有时候我们需要在程序中获取当前运行的函数名,如何简单的做到这点呢?我们可以用getStackTrace轻松搞定. 一提到getStatckTrace多数人会联想到Thowable中的getStackT ...
- linux内核中测量时间的方法,Linux内核中获取时间函数do_gettimeofday
内核代码能一直获取一个当前时间的表示, 通过查看 jifies 的值. 常常地, 这个值只代表从最后一次启动以来的时间, 这个事实对驱动来说无关, 因为它的生命周期受限于系统的 uptime. 如所示 ...
- C++中获取日期函数gmtime和localtime区别
函数gmtime和localtime的声明如下: struct tm * gmtime (const time_t * timer); struct tm * localtime (const tim ...
- php 获取子类的方法名,php获取分类下的所有子类方法
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 获取分类下面的所有子类方法: static function getMenuTree($arrCat, $parent_i ...
- tp框架获取控制器和方法名
$controller = request()->controller(); $action = request()->action();
- legend3---laravel中获取控制器名称和方法名称
legend3---laravel中获取控制器名称和方法名称 一.总结 一句话总结: \Route::current()->getActionName();会有完整的当前控制器名和方法名 pub ...
- 【Qt】Scene中获取指定类型的自定义图元
通过阅读 Qt 官方文档中的"Elastic Nodes Example"例子,学习到如何在场景(Scene)中获取某个类型的自定义图元. 官方Demo运行效果: 该文档中,作者自 ...
最新文章
- Delphi FastReport动态加载图片
- C语言头文件为什么要加#ifndef #define #endif(防止头文件重复包含)
- 西安电子科技大学第16届程序设计竞赛 F题
- c4.5算法python实现_算法:用Python实现—最优化算法
- VMware15.5安装Linux虚拟机(Centos7)图文教程
- 相信自己, 许自己一个未来
- Windows XP Embedded 官方下载地址
- 中缀表达式——表达式树
- 【柒】企业分析利器——强大企业模型
- HTML中如何使用JavaScript创建链接?
- 红米android刷机在哪,红米手机怎么刷机 红米手机刷机教程大全
- 《Miss Talk》第08期:对话桥吧英语联合创始人兼CTO 于双印
- 位地址和字节地址换算_IP地址详解
- html页面长按保存图片,h5长按保存图片
- linux中用c语言编写一个经纬度转换大地坐标
- 蓝桥杯 2014年真题
- “贵系万花筒”:探秘清华计算机系背后的“酒井”文化
- 用Python实现文本内容生成二维码
- 项目工时管理遇难题?看看这套工时管理系统解决方案
- iOS中gif图片的分解与显示