搜索
系统检测到您的用户名不符合规范:

获取所有控制器,方法,注释

浏览:2944 发布日期:2016年11月02日 分类:功能实现 关键字: 获取所有控制器 方法 注释
获取所有控制器,方法,注释
<?php

/**
* @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++;
}
}
}
return $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('_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 获取函数的注释
*
* @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;
}

?>
评论() 相关
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
收藏
onlyquan
积分:3740 等级:LV4
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /