123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace daswork;
- use \daswork\Route;
- use \daswork\Config;
- class App
- {
- /**
- * 运行控制器和方法
- * @throws \Exception
- */
- public static function run(Request $request = null)
- {
- is_null($request) && $request = Request::instance();
- $route = new Route();
- $model = $route->model;
- $ctrlClass = '\\app\\' . $model . '\\' . "controller" . '\\' . $route->ctrl;
- $action = $route->action;
- $ctrl = new $ctrlClass();
- $data = $ctrl->$action();
- // var_dump($data);
- // is_null($request) && $request = Request::instance();
- // 请求缓存检查
- // $request->cache($config['request_cache'], $config['request_cache_expire'], $config['request_cache_except']);
- // 输出数据到客户端
- if ($data instanceof Response) {
- $response = $data;
- } elseif (!is_null($data)) {
- // 默认自动识别响应输出类型
- // $isAjax = $request->isAjax();
- // $type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
- $type = 'html';
- $response = Response::create($data, $type);
- } else {
- $response = Response::create();
- }
- $response->send();
- }
- }
- // /**
- // * 执行应用程序
- // * @access public
- // * @param Request $request Request对象
- // * @return Response
- // * @throws Exception
- // */
- // public static function run(Request $request = null)
- // {
- // is_null($request) && $request = Request::instance();
- // try {
- // $config = self::initCommon();
- // if (defined('BIND_MODULE')) {
- // // 模块/控制器绑定
- // BIND_MODULE && Route::bind(BIND_MODULE);
- // } elseif ($config['auto_bind_module']) {
- // // 入口自动绑定
- // $name = pathinfo($request->baseFile(), PATHINFO_FILENAME);
- // if ($name && 'index' != $name && is_dir(APP_PATH . $name)) {
- // Route::bind($name);
- // }
- // }
- // $request->filter($config['default_filter']);
- // // 默认语言
- // Lang::range($config['default_lang']);
- // if ($config['lang_switch_on']) {
- // // 开启多语言机制 检测当前语言
- // Lang::detect();
- // }
- // $request->langset(Lang::range());
- // // 加载系统语言包
- // Lang::load([
- // THINK_PATH . 'lang' . DS . $request->langset() . EXT,
- // APP_PATH . 'lang' . DS . $request->langset() . EXT,
- // ]);
- // // 获取应用调度信息
- // $dispatch = self::$dispatch;
- // if (empty($dispatch)) {
- // // 进行URL路由检测
- // $dispatch = self::routeCheck($request, $config);
- // }
- // // 记录当前调度信息
- // $request->dispatch($dispatch);
- // // 记录路由和请求信息
- // if (self::$debug) {
- // Log::record('[ ROUTE ] ' . var_export($dispatch, true), 'info');
- // Log::record('[ HEADER ] ' . var_export($request->header(), true), 'info');
- // Log::record('[ PARAM ] ' . var_export($request->param(), true), 'info');
- // }
- // // 监听app_begin
- // Hook::listen('app_begin', $dispatch);
- // // 请求缓存检查
- // $request->cache($config['request_cache'], $config['request_cache_expire'], $config['request_cache_except']);
- // $data = self::exec($dispatch, $config);
- // } catch (HttpResponseException $exception) {
- // $data = $exception->getResponse();
- // }
- // // 清空类的实例化
- // Loader::clearInstance();
- // // 输出数据到客户端
- // if ($data instanceof Response) {
- // $response = $data;
- // } elseif (!is_null($data)) {
- // // 默认自动识别响应输出类型
- // $isAjax = $request->isAjax();
- // $type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
- // $response = Response::create($data, $type);
- // } else {
- // $response = Response::create();
- // }
- // // 监听app_end
- // Hook::listen('app_end', $response);
- // return $response;
- // }
|