/** * URL路由检测(根据PATH_INFO) * @access public * @param \think\Request $request * @param array $config * @throws Exception */ public static function route($request, array $config) { define('__INFO__', $request->pathinfo()); define('__EXT__', $request->ext()); // 检测URL禁用后缀 if ($config['url_deny_suffix'] && preg_match('/\\.(' . $config['url_deny_suffix'] . ')$/i', __INFO__)) { throw new Exception('url suffix deny'); } $_SERVER['PATH_INFO'] = $request->path(); $depr = $config['pathinfo_depr']; $result = false; // 路由检测 if (APP_ROUTE_ON && !empty($config['url_route_on'])) { // 开启路由 if (!empty($config['route'])) { // 导入路由配置 Route::import($config['route']); } // 路由检测(根据路由定义返回不同的URL调度) $result = Route::check($request, $_SERVER['PATH_INFO'], $depr, !IS_CLI ? $config['url_domain_deploy'] : false); if (APP_ROUTE_MUST && false === $result && $config['url_route_must']) { // 路由无效 throw new Exception('route not define '); } } if (false === $result) { // 路由无效默认分析为模块/控制器/操作/参数...方式URL $result = Route::parseUrl($_SERVER['PATH_INFO'], $depr); } //保证$_REQUEST正常取值 $_REQUEST = array_merge($_POST, $_GET, $_COOKIE); // 注册调度机制 return $request->dispatch($result); }