Skip to content

Commit b8337f2

Browse files
committed
新增多个插件行为
新增多语言错误提示
1 parent 77a2ed4 commit b8337f2

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ FastAdmin插件模块
55
http://doc.fastadmin.net/docs/addons.html
66

77
## 特别感谢
8-
特别感谢https://github.com/5ini99/think-addons
8+
https://github.com/5ini99/think-addons

src/addons/Route.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,38 @@ public function execute($addon = null, $controller = null, $action = null)
2424
// 是否自动转换控制器和操作名
2525
$convert = Config::get('url_convert');
2626
$filter = $convert ? 'strtolower' : 'trim';
27-
27+
2828
$addon = $addon ? call_user_func($filter, $addon) : '';
2929
$controller = $controller ? call_user_func($filter, $controller) : 'index';
3030
$action = $action ? call_user_func($filter, $action) : 'index';
3131

32+
Hook::listen('addon_begin', $request);
33+
3234
if (!empty($addon) && !empty($controller) && !empty($action))
3335
{
3436
$info = get_addon_info($addon);
3537
if (!$info)
3638
{
37-
throw new HttpException(404, 'addon not exists:' . $addon);
39+
throw new HttpException(404, __('addon %s not found', $addon));
3840
}
3941
if (!$info['state'])
4042
{
41-
throw new HttpException(500, 'the addon is disabled:' . $addon);
43+
throw new HttpException(500, __('addon %s is disabled', $addon));
4244
}
4345
// 设置当前请求的控制器、操作
4446
$request->controller($controller)->action($action);
4547

48+
// 监听addon_module_init
49+
Hook::listen('addon_module_init', $request);
50+
// 兼容旧版本行为,即将移除,不建议使用
51+
Hook::listen('addons_init', $request);
52+
4653
$class = get_addon_class($addon, 'controller', $controller);
4754
if (!$class)
4855
{
49-
throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1));
56+
throw new HttpException(404, __('addon controller %s not found', Loader::parseName($controller, 1)));
5057
}
5158

52-
// 监听addons_init
53-
Hook::listen('addons_init', $request);
54-
5559
$instance = new $class($request);
5660

5761
$vars = [];
@@ -69,10 +73,10 @@ public function execute($addon = null, $controller = null, $action = null)
6973
else
7074
{
7175
// 操作不存在
72-
throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()');
76+
throw new HttpException(404, __('addon action %s not found', get_class($instance) . '->' . $action . '()'));
7377
}
7478

75-
Hook::listen('action_begin', $call);
79+
Hook::listen('addon_action_begin', $call);
7680

7781
return call_user_func_array($call, $vars);
7882
}

src/common.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
// 注册类的根命名空间
2424
Loader::addNamespace('addons', ADDON_PATH);
2525

26+
// 监听addon_init
27+
Hook::listen('addon_init');
28+
2629
// 闭包自动识别插件目录配置
2730
Hook::add('app_init', function () {
2831
// 获取开关

0 commit comments

Comments
 (0)