Example #1
0
 /**
  * 应用关闭处理
  * @return void
  */
 public static function appShutdown()
 {
     // 记录日志
     Log::save();
     if (SLOG_ON) {
         \org\Slog::sendLog();
     }
     if ($e = error_get_last()) {
         switch ($e['type']) {
             case E_ERROR:
             case E_PARSE:
             case E_CORE_ERROR:
             case E_COMPILE_ERROR:
             case E_USER_ERROR:
                 ob_end_clean();
                 self::halt($e);
                 break;
         }
     }
 }
Example #2
0
 /**
  * 执行应用程序
  * @access public
  * @return void
  */
 public static function run(array $config = [])
 {
     // 初始化公共模块
     self::initModule(COMMON_MODULE, $config);
     // 读取扩展配置文件
     if ($config['extra_config_list']) {
         foreach ($config['extra_config_list'] as $file) {
             Config::load($file, $file);
         }
     }
     // 获取配置参数
     $config = Config::get();
     // 日志初始化
     Log::init($config['log']);
     // 缓存初始化
     Cache::connect($config['cache']);
     // 如果启动SocketLog调试, 进行SocketLog配置
     if (SLOG_ON) {
         \org\Slog::config($config['slog']);
     }
     // 默认语言
     $lang = strtolower($config['default_lang']);
     Lang::range($lang);
     // 加载默认语言包
     Lang::load(THINK_PATH . 'Lang/' . $lang . EXT);
     // 监听app_init
     Hook::listen('app_init');
     // 启动session
     if (!IS_CLI && $config['use_session']) {
         Session::init($config['session']);
     }
     // 应用URL调度
     self::dispatch($config);
     // 监听app_run
     Hook::listen('app_run');
     // 执行操作
     if (!preg_match('/^[A-Za-z](\\/|\\.|\\w)*$/', CONTROLLER_NAME)) {
         // 安全检测
         throw new Exception('class [ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(str_replace('.', '\\', CONTROLLER_NAME), 1) . ' ] not exists');
     }
     if ($config['action_bind_class']) {
         $class = self::bindActionClass($config['empty_controller']);
         $instance = new $class();
         // 操作绑定到类后 固定执行run入口
         $action = 'run';
     } else {
         $instance = Loader::controller(CONTROLLER_NAME, '', $config['empty_controller']);
         // 获取当前操作名
         $action = ACTION_NAME . $config['action_suffix'];
     }
     if (!$instance) {
         throw new Exception('class [ ' . MODULE_NAME . '\\' . CONTROLLER_LAYER . '\\' . Loader::parseName(str_replace('.', '\\', CONTROLLER_NAME), 1) . ' ] not exists');
     }
     try {
         // 操作方法开始监听
         $call = [$instance, $action];
         Hook::listen('action_begin', $call);
         if (!preg_match('/^[A-Za-z](\\w)*$/', $action)) {
             // 非法操作
             throw new \ReflectionException();
         }
         //执行当前操作
         $method = new \ReflectionMethod($instance, $action);
         if ($method->isPublic()) {
             // URL参数绑定检测
             if ($config['url_params_bind'] && $method->getNumberOfParameters() > 0) {
                 // 获取绑定参数
                 $args = self::getBindParams($method, $config['url_parmas_bind_type']);
                 // 全局过滤
                 array_walk_recursive($args, 'Input::filterExp');
                 $data = $method->invokeArgs($instance, $args);
             } else {
                 $data = $method->invoke($instance);
             }
             // 操作方法执行完成监听
             Hook::listen('action_end', $data);
             // 返回数据
             Response::returnData($data, $config['default_return_type'], $config['response_exit']);
         } else {
             // 操作方法不是Public 抛出异常
             throw new \ReflectionException();
         }
     } catch (\ReflectionException $e) {
         // 操作不存在
         if (method_exists($instance, '_empty')) {
             $method = new \ReflectionMethod($instance, '_empty');
             $method->invokeArgs($instance, [$action, '']);
         } else {
             throw new Exception('method [ ' . (new \ReflectionClass($instance))->getName() . '->' . $action . ' ] not exists ');
         }
     }
 }
Example #3
0
 /**
  * 数据库调试 记录当前SQL
  * @access protected
  * @param boolean $start  调试开始标记 true 开始 false 结束
  */
 protected function debug($start)
 {
     if ($this->config['debug']) {
         // 开启数据库调试模式
         if ($start) {
             Debug::remark('queryStartTime', 'time');
         } else {
             $this->modelSql[$this->model] = $this->queryStr;
             //$this->model  =   '_think_';
             // 记录操作结束时间
             Debug::remark('queryEndTime', 'time');
             Log::record($this->queryStr . ' [ RunTime:' . Debug::getUseTime('queryStartTime', 'queryEndTime') . 's ]', 'SQL');
         }
     }
     $slog_config = Config::get('slog');
     if ($slog_config['enable'] && $start) {
         \org\Slog::sql($this->queryStr, $this->_linkID);
     }
 }
Example #4
0
 public function index()
 {
     Slog::log('调试');
     $view = new View();
     return $view->fetch();
 }