From d2b637d803dcaee55503624c72f0332bc6e09995 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 4 Jan 2016 19:01:12 +0800 Subject: [PATCH] =?UTF-8?q?App=E7=B1=BB=E5=A2=9E=E5=8A=A0dispatch=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=8F=AF=E4=BB=A5=E8=BF=9B=E8=A1=8C=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=B0=83=E5=BA=A6=E6=9C=BA=E5=88=B6=20?= =?UTF-8?q?=E6=97=A0=E9=9C=80=E7=BB=8F=E8=BF=87=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 3d024649..559a32ac 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -18,6 +18,11 @@ namespace think; class App { + // 应用调度机制 + private static $dispatch = []; + // 应用调度类型 + private static $type = ''; + /** * 执行应用程序 * @access public @@ -72,37 +77,39 @@ class App Session::init($config['session']); } - // URL路由检测 - $dispatch = self::route($config); + if (empty(self::$type)) { + // 未指定调度类型 则进行URL路由检测 + self::route($config); + } // 监听app_begin APP_HOOK && Hook::listen('app_begin', $dispatch); // 根据类型调度 - switch ($dispatch['type']) { + switch (self::$type) { case 'redirect': // 执行重定向跳转 - header('Location: ' . $dispatch['url'], true, $dispatch['status']); + header('Location: ' . self::$dispatch['url'], true, self::$dispatch['status']); break; case 'module': // 模块/控制器/操作 - $data = self::module($dispatch['data'], $config); + $data = self::module(self::$dispatch['data'], $config); break; case 'action': // 执行操作 - $data = Loader::action($dispatch['action'], $dispatch['params']); + $data = Loader::action(self::$dispatch['action'], self::$dispatch['params']); break; case 'behavior': // 执行行为 - $data = Hook::exec($dispatch['class'], $dispatch['method'], $dispatch['params']); + $data = Hook::exec(self::$dispatch['class'], self::$dispatch['method'], self::$dispatch['params']); break; case 'regex_closure': // 正则闭包 - $data = self::invokeRegex($dispatch['closure'], $dispatch['params']); + $data = self::invokeRegex(self::$dispatch['closure'], self::$dispatch['params']); break; case 'rule_closure': // 规则闭包 - $data = self::invokeRule($dispatch['closure'], $dispatch['params']); + $data = self::invokeRule(self::$dispatch['closure'], self::$dispatch['params']); break; default: throw new Exception('dispatch type not support', 10008); @@ -411,10 +418,10 @@ class App $depr = $config['pathinfo_depr']; // 还原劫持后真实pathinfo $path_info = - (defined('BIND_MODULE') ? BIND_MODULE . $depr : '') . - (defined('BIND_CONTROLLER') ? BIND_CONTROLLER . $depr : '') . - (defined('BIND_ACTION') ? BIND_ACTION . $depr : '') . - $_SERVER['PATH_INFO']; + (defined('BIND_MODULE') ? BIND_MODULE . $depr : '') . + (defined('BIND_CONTROLLER') ? BIND_CONTROLLER . $depr : '') . + (defined('BIND_ACTION') ? BIND_ACTION . $depr : '') . + $_SERVER['PATH_INFO']; // 路由检测 if (!empty($config['url_route_on'])) { @@ -436,7 +443,14 @@ class App $result = Route::parseUrl($path_info, $depr); } } - return $result; + // 注册调度机制 + self::dispatch($result); } + // 指定应用调度类型和参数 + public static function dispatch($dispatch) + { + self::$dispatch = $dispatch; + self::$type = $dispatch['type']; + } }