private static function module($result, $config)
{
if (APP_MULTI_MODULE) {
// 多模块部署
$module = strtolower($result[0] ?: $config['default_module']);
// 获取模块名称
define('MODULE_NAME', strip_tags($module));
// 模块初始化
if (MODULE_NAME && !in_array(MODULE_NAME, $config['deny_module_list']) && is_dir(APP_PATH . MODULE_NAME)) {
define('MODULE_PATH', APP_PATH . MODULE_NAME . DS);
define('VIEW_PATH', MODULE_PATH . VIEW_LAYER . DS);
// 初始化模块
self::initModule(MODULE_NAME, $config);
} else {
throw new Exception('module [ ' . MODULE_NAME . ' ] not exists ', 10005);
}
} else {
// 单一模块部署
define('MODULE_NAME', '');
define('MODULE_PATH', APP_PATH);
define('VIEW_PATH', MODULE_PATH . VIEW_LAYER . DS);
}
// 获取控制器名
$controllerName = strip_tags($result[1] ?: Config::get('default_controller'));
defined('CONTROLLER_NAME') or define('CONTROLLER_NAME', Config::get('url_controller_convert') ? strtolower($controllerName) : $controllerName);
// 获取操作名
$actionName = strip_tags($result[2] ?: Config::get('default_action'));
defined('ACTION_NAME') or define('ACTION_NAME', Config::get('url_action_convert') ? strtolower($actionName) : $actionName);
// 执行操作
if (!preg_match('/^[A-Za-z](\\/|\\.|\\w)*$/', CONTROLLER_NAME)) {
// 安全检测
throw new Exception('illegal controller name:' . CONTROLLER_NAME, 10000);
}
$instance = Loader::controller(CONTROLLER_NAME, '', Config::get('use_controller_suffix'), Config::get('empty_controller'));
// 获取当前操作名
$action = ACTION_NAME . Config::get('action_suffix');
try {
// 操作方法开始监听
$call = [$instance, $action];
APP_HOOK && Hook::listen('action_begin', $call);
if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
// 非法操作
throw new \ReflectionException('illegal action name :' . ACTION_NAME);
}
// 执行操作方法
$data = self::invokeMethod($call);
} catch (\ReflectionException $e) {
// 操作不存在
if (method_exists($instance, '_empty')) {
$method = new \ReflectionMethod($instance, '_empty');
$data = $method->invokeArgs($instance, [$action, '']);
APP_DEBUG && Log::record('[ RUN ] ' . $method->getFileName(), 'info');
} else {
throw new Exception('method [ ' . (new \ReflectionClass($instance))->getName() . '->' . $action . ' ] not exists ', 10002);
}
}
return $data;
}