Ejemplo n.º 1
0
 function build($appid)
 {
     $project_path = (\Norma\Config::get('build.project_path') ?: dirname(dirname(FRAME_PATH)) . '/project') . '/' . $appid;
     \Norma\Hook::trigger('build_app', array('project_path' => $project_path, 'buildoption' => ['__dir__' => ['Runtime/cache', 'Runtime/log', 'Runtime/temp', 'Runtime/template', 'Config'], 'demo' => ['__file__' => ['common.php'], '__dir__' => ['behavior', 'controller', 'model', 'view'], 'controller' => ['Index', 'Test', 'UserType'], 'model' => ['User', 'UserType'], 'view' => ['index/index']]]));
     return $this->fetch();
 }
Ejemplo n.º 2
0
 /**
  * 执行应用
  * @static
  * @access public
  */
 public static function listen(Request $request = null, $type = 'web')
 {
     is_null($request) && ($request = Request::instance());
     //请求筛选
     \Norma\Hook::trigger('request_action', [$request]);
     //加载应用独立文件
     if (\Norma\Config::has('extra_config_list')) {
         $extra_config_list = \Norma\Config::get('extra_config_list');
         if (is_string($extra_config_list)) {
             $extra_config_list = explode(',', $extra_config_list);
         }
         foreach ($extra_config_list as $key => $file) {
             \Norma\Config::load(APP_PATH . '/Config/' . $file . '.php');
         }
     }
     // 设置系统时区
     date_default_timezone_set(\Norma\Config::get('default_timezone'));
     // 应用调试模式
     self::$debug = Config::get('app_debug');
     if (!self::$debug) {
         ini_set('display_errors', 'Off');
     } else {
         //重新申请一块比较大的buffer
         if (ob_get_level() > 0) {
             $output = ob_get_clean();
         }
         ob_start();
         if (!empty($output)) {
             echo $output;
         }
     }
     // 注册应用实现类名称空间
     \Norma\App::$loader->addNamespace(\Norma\Config::get('app_namespace') ?: "App", APP_PATH);
     // 加载插件
     \Norma\Hook::loadPlugin(APP_PATH . '/Plugin', \Norma\Config::get('app_namespace'));
     // 开启多语言机制
     if (\Norma\Config::get('lang_switch_on')) {
         // 获取当前语言
         $request->langset(Lang::detect());
         // 加载系统语言包
         Lang::load(FRAME_PATH . '/Ability/Lang' . DIRECTORY_SEPARATOR . $request->langset() . '.php');
         if (!\Norma\Config::get('app_multi_module')) {
             Lang::load(APP_PATH . '/Lang' . DIRECTORY_SEPARATOR . $request->langset() . '.php');
         }
     }
     // 获取应用调度信息
     $dispatch = self::$dispatch;
     if (empty($dispatch)) {
         // 进行URL路由检测
         $dispatch = self::routeCheck($request, \Norma\Config::get());
     }
     // 记录当前调度信息
     $request->dispatch($dispatch);
     // 记录路由信息
     //self::$debug && Log::record('[ ROUTE ] ' . var_export($dispatch, true), 'info');
     // 监听app_begin
     //Hook::listen('app_begin', $dispatch);
     switch ($dispatch['type']) {
         case 'redirect':
             // 执行重定向跳转
             $data = Response::create($dispatch['url'], 'redirect')->code($dispatch['status']);
             break;
         case 'module':
             // 模块/控制器/操作
             $data = self::module($dispatch['module'], \Norma\Config::get(), isset($dispatch['convert']) ? $dispatch['convert'] : null);
             break;
         case 'controller':
             // 执行控制器操作
             $data = Loader::action($dispatch['controller'], $dispatch['params']);
             break;
         case 'method':
             // 执行回调方法
             $data = self::invokeMethod($dispatch['method'], $dispatch['params']);
             break;
         case 'function':
             // 执行闭包
             $data = self::invokeFunction($dispatch['function'], $dispatch['params']);
             break;
         case 'response':
             $data = $dispatch['response'];
             break;
         default:
             throw new \InvalidArgumentException('dispatch type not support');
     }
     // 输出数据到客户端
     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');
         \Norma\Hook::trigger('output', [$data, $type]);
     } else {
         \Norma\Hook::trigger('output');
     }
     //
     //return $response;
 }