PHP获取项目所有控制器方法名称

  //获取模块下所有的控制器和方法写入到权限表
public function initperm() {
$modules = array('admin'); //模块名称
$i = 0;
foreach ($modules as $module) {
$all_controller = $this->getController($module);
foreach ($all_controller as $controller) {
$all_action = $this->getAction($module, $controller);
foreach ($all_action as $action) {
$controller = str_replace('Controller', '', $controller);
$data[$i]['module'] = $module;
$data[$i]['controller'] = $controller;
$data[$i]['action'] = $action; //入库
if (!empty($module) && !empty($controller) && !empty($action)) {
$rule_name = $module . '-' . $controller . '-' . $action;
$rule = M()->table('tky_authrule')->where('name="' . strtolower($rule_name) . '"')->find();
if (!$rule) {
$idata = array();
$idata['module'] = strtolower($module . '-' . $controller);
$idata['type'] = "1";
$idata['name'] = strtolower($rule_name);
$idata['title'] = "";
$idata['regex'] = "";
$idata['status'] = "1";
M()->table('tky_authrule')->add($idata);
}
} $i++;
}
}
}
echo '<pre>';
print_r($data);
echo '</pre>';
} //获取所有控制器名称
private function getController($module) {
if (empty($module)) {
return null;
}
$module_path = APP_PATH . '/' . $module . '/controllers/'; //控制器路径
if (!is_dir($module_path)) {
return null;
}
$module_path .= '/*.php';
$ary_files = glob($module_path);
foreach ($ary_files as $file) {
if (is_dir($file)) {
continue;
} else {
$files[] = basename($file, '.php');
}
}
return $files;
} //获取所有方法名称
protected function getAction($module, $controller) {
if (empty($controller)) {
return null;
}
$file = APP_PATH . $module . '/controllers/' . $controller . '.php';
if (file_exists($file)) {
$content = file_get_contents($file);
preg_match_all("/.*?public.*?function(.*?)\(.*?\)/i", $content, $matches);
$functions = $matches[1];
//排除部分方法
$inherents_functions = array('_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)) {
$customer_functions[] = $func;
}
}
return $customer_functions;
} else {
\ticky\Log::record('is not file ' . $file, Log::INFO);
}
return null;
}

 mysql

DROP TABLE IF EXISTS tky_authrule;
CREATE TABLE tky_authrule (
ruleid MEDIUMINT (8) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '编号',
module VARCHAR (20) NOT NULL DEFAULT '' COMMENT '规则所属module',
type TINYINT (1) NOT NULL DEFAULT '1' COMMENT '类型 1-url;2-主菜单',
name CHAR (80) NOT NULL DEFAULT '' COMMENT '规则唯一英文标识',
title CHAR (20) NOT NULL DEFAULT '' COMMENT '规则中文描述',
regex CHAR (100) NOT NULL DEFAULT '' COMMENT '规则表达式',
status TINYINT (1) NOT NULL DEFAULT '1' COMMENT '状态',
PRIMARY KEY (ruleid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT = '规则表';

  

PHP获取项目所有控制器方法名称的更多相关文章

  1. java获取当前运行的方法名称

    // 这种方式获取的话,数组的第一个元素是当前运行方法的名称,第二个元素是调用当前方法的方法名称 StackTraceElement[] stackTrace = new Exception().ge ...

  2. javaweb获取项目路径的方法

    在jsp和class文件中调用的相对路径不同. 在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getPro ...

  3. js获取项目根目录的方法

    getRootPath = function(){ //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp var curWwwPat ...

  4. C#应用程序获取项目路径的方法总结

    一.非Web程序   //基目录,由程序集冲突解决程序用来探测程序集 1.AppDomain.CurrentDomain.BaseDirectory     //当前工作目录的完全限定路径2.Envi ...

  5. 获取DLL中的方法名称

      OpenFileDialog obj = new OpenFileDialog(); if (obj.ShowDialog() == System.Windows.Forms.DialogResu ...

  6. jsp中的js中获取项目路径的方法

    在jsp中加上 <% String path = request.getContextPath(); String basePath = request.getScheme()+":/ ...

  7. Java中动态获取项目根目录的绝对路径

    https://www.cnblogs.com/zhouqing/archive/2012/11/10/2757774.html 序言 在开发过程中经常会用到读写文件,其中就必然涉及路径问题.使用固定 ...

  8. legend3---laravel中获取控制器名称和方法名称

    legend3---laravel中获取控制器名称和方法名称 一.总结 一句话总结: \Route::current()->getActionName();会有完整的当前控制器名和方法名 pub ...

  9. Codeigniter 获取当前的控制器名称和方法名称

    在Codeigniter 可以通过下面两个方法获取当前的控制器名称和方法名称 $this->router->fetch_class(); $this->router->fetc ...

随机推荐

  1. ROS 101

    https://www.clearpathrobotics.com/blog/2014/01/how-to-guide-ros-101/ 什么是ROS ROS(robot operating syst ...

  2. php ip2long负数的问题

    大家可能都知道php提供了ip2long与long2ip方法对ip地址处理.抛砖引玉,说点概念性滴: 1.ip2long — 将一个IPV4的字符串互联网协议转换成数字格式 int ip2long ( ...

  3. 开源前端脚本错误监控及跟踪解决项目BadJS试用

    摘要: 试用BadJS. 原文:开源前端脚本错误监控及跟踪解决项目-BadJS 试用 作者:过错 Fundebug经授权转载,版权归原作者所有. BadJS 是 一个web 前端脚本错误监控及跟踪项目 ...

  4. Laravel Excel 实现 Excel-CSV 文件导入导出功能

    Laravel Excel 是一款基于 PHPExcel 开发的Laravel框架专用的 Excel/CSV 文件导入导出功能的扩展包,用起来的非常方便. 它的 Github 地址是:https:// ...

  5. Bootstrap 实战之响应式个人博客 (一)

    一.示例 1.主页 2.博客详情页 3.在线地址 在线地址:入口 Addition:这里使用github-page将自己的静态项目免费部署到线上. 如果你只是做一些简单的静态项目做展示,付出这么大的时 ...

  6. android找不到aar包

    转载请标明出处,维权必究:https://www.cnblogs.com/tangZH/p/9939663.html  在做项目的时候引入aar包,编译的时候却提示错误(这个错误大概说的是...... ...

  7. ORA-02030: can only select from fixed tables/views

    有时候给一些普通用户授予查询系统对象(例如dynamic performance views)权限时会遇到"ORA-02030: can only select from fixed tab ...

  8. js 学习之路5:使用js在网页中添加水印

    示例: <!DOCTYPE html> <html> <meta http-equiv="Content-Type" content="te ...

  9. Django REST framework基础:分页

    DRF分页组件 为什么要使用分页 我们数据表中可能会有成千上万条数据,当我们访问某张表的所有数据时,我们不太可能需要一次把所有的数据都展示出来,因为数据量很大,对服务端的内存压力比较大还有就是网络传输 ...

  10. Git 生成SSH Key

    背景:服务器是LINUX系统(centos7),使用GitLab管理git代码库.各个客户端通过sourcetree 工具,采用SSH获取.提交代码.使用SSH的方式需要公钥和私钥.下面介绍秘钥的生成 ...