mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-05 22:52:49 +08:00
改进App类的反射异常无法捕获问题
This commit is contained in:
@@ -369,33 +369,28 @@ class App
|
|||||||
// 监听module_init
|
// 监听module_init
|
||||||
Hook::listen('module_init', $request);
|
Hook::listen('module_init', $request);
|
||||||
|
|
||||||
try {
|
$instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
|
||||||
$instance = Loader::controller($controller, $config['url_controller_layer'], $config['controller_suffix'], $config['empty_controller']);
|
if (is_null($instance)) {
|
||||||
if (is_null($instance)) {
|
throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1));
|
||||||
throw new HttpException(404, 'controller not exists:' . Loader::parseName($controller, 1));
|
}
|
||||||
}
|
// 获取当前操作名
|
||||||
// 获取当前操作名
|
$action = $actionName . $config['action_suffix'];
|
||||||
$action = $actionName . $config['action_suffix'];
|
|
||||||
if (!preg_match('/^[A-Za-z](\w)*$/', $action)) {
|
|
||||||
// 非法操作
|
|
||||||
throw new \ReflectionException('illegal action name:' . $actionName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (is_callable([$instance, $action])) {
|
||||||
// 执行操作方法
|
// 执行操作方法
|
||||||
$call = [$instance, $action];
|
$call = [$instance, $action];
|
||||||
Hook::listen('action_begin', $call);
|
} elseif (is_callable([$instance, '_empty'])) {
|
||||||
|
// 空操作
|
||||||
$data = self::invokeMethod($call);
|
$call = [$instance, '_empty'];
|
||||||
} catch (\ReflectionException $e) {
|
} else {
|
||||||
// 操作不存在
|
// 操作不存在
|
||||||
if (method_exists($instance, '_empty')) {
|
throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()');
|
||||||
$reflect = new \ReflectionMethod($instance, '_empty');
|
|
||||||
$data = $reflect->invokeArgs($instance, [$action]);
|
|
||||||
self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info');
|
|
||||||
} else {
|
|
||||||
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Hook::listen('action_begin', $call);
|
||||||
|
|
||||||
|
$data = self::invokeMethod($call);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user