Skip to content

Commit

Permalink
1、新增自动读取插件配置
Browse files Browse the repository at this point in the history
2、优化了debug获取方式
3、规范统一use命名空间类
  • Loading branch information
byron committed Mar 28, 2017
1 parent c0cab1e commit 3802d96
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,24 @@
$config = (array)Config::get('addons');
// 读取插件目录及钩子列表
$base = get_class_methods("\\think\\Addons");
// 读取插件目录中的php文件
foreach (glob(ADDON_PATH . '*/*.php') as $addons_file) {
// 格式化路径信息
$info = pathinfo($addons_file);
// 获取插件目录名
$name = pathinfo($info['dirname'], PATHINFO_FILENAME);
// 找到插件入口文件
if (strtolower($info['filename']) == strtolower($name)) {
// 读取出所有公共方法
$methods = (array)get_class_methods("\\addons\\" . $name . "\\" . $info['filename']);
// 跟插件基类方法做比对,得到差异结果
$hooks = array_diff($methods, $base);
// 循环将钩子方法写入配置中
foreach ($hooks as $hook) {
if (!isset($config['hooks'][$hook])) {
$config['hooks'][$hook] = [];
}
// 兼容手动配置项
if (is_string($config['hooks'][$hook])) {
$config['hooks'][$hook] = explode(',', $config['hooks'][$hook]);
}
Expand Down

0 comments on commit 3802d96

Please sign in to comment.