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. Centos7-yum部署配置LNMP+php-fgm,一台机器上部署

    一.简介 1.了解nginx特性 请参考,https://www.cnblogs.com/zhangxingeng/p/10150955.html 2.LNMP:linux+nginx+mysql+p ...

  2. 第一册:lesson 103.

    原文:The French text. How was the exam, Richard? Not too bad. I think I passed in English and Mathemat ...

  3. (4)Maven快速入门_4在Spring+SpringMVC+MyBatis+Oracle+Maven框架整合运行在Tomcat8中

    利用Maven 创建Spring+SpringMVC+MyBatis+Oracle 项目 分了三个项目  Dao   (jar)   Service (jar)   Controller (web) ...

  4. AI书单

    1.<TensorFlow实战>   黄文坚 2.<Machine Learning> [美]Tom Mitchell 3.<机器学习> 周志华  

  5. CentOS7 yum方式安装MySQL5.7

    转载至博客:https://www.cnblogs.com/bigbrotherer/p/7241845.html 在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要 ...

  6. jQuery 父iframe与子iframe 相互调用传值

    来自:https://blog.csdn.net/wd4871/article/details/50517597 侵删 父页面中的iframe :如下 <iframe name="su ...

  7. float与double

    对数值类型的细节了解在大学里就是一带而过,自己始终也没好好看过.这是在csdn上看到的一篇文章,挺好的,记录下来. https://blog.csdn.net/Demon__Hunter/articl ...

  8. IDEA修改Git账户和密码

    找到c盘中git目录的.gitconfig文件可以直接修改name和邮箱   

  9. macos 常用快捷键及操作

    通用: 拷贝相当于window下的复制非苹果键盘(command == win option == alt control == ctrl)Command + C 拷贝(Copy)Command + ...

  10. bug优先级别

    https://www.cnblogs.com/evablogs/p/6785083.html bug缺陷的优先级别 首先需要对一个版本进行冒烟测试,确定基本功能测试,如果不通过的话进行后期的测试已经 ...