Example #1
0
 /**
  * 运行调度器
  *
  */
 public function run()
 {
     // APP运行的开始时间
     $this->_setDebugInfo('beginTime', microtime(true));
     // 运行应用的 Bootstrap
     require APPLICATION_PATH . '/Bootstrap.php';
     $bootStrap = new Bootstrap();
     $bootStrap->init();
     // 解析当前的URI(包括解析路由)
     $this->_parseUri();
     // 得到控制器
     $controller = $this->_getController();
     $action = $this->_action . 'Action';
     // 判断动作是否存在
     if (!method_exists($controller, $action)) {
         throw new QP_Exception('控制器:' . get_class($controller) . ' 中未定义动作:' . $action, QP_Exception::EXCEPTION_NO_ACTION);
     }
     // 选择的动作
     $this->_setDebugInfo('action', $action);
     // 把执行的输出先保存起来放到 Layout 中显示
     ob_start();
     // 执行 init 方法
     $controller->init();
     // 执行动作
     $controller->{$action}();
     // 得到所有输出内容
     $viewContent = ob_get_clean();
     // 是否自动输出视图
     if ($controller->viewIsAutoRender()) {
         $controller->view->setPath($this->_controllerPath);
         $viewContent .= $controller->view->render($this->_action . '.html');
         // 使用的视图
         $this->_setDebugInfo('view', $this->_action . '.html');
     }
     // 是否启用了 Layout
     if (QP_Layout::isEnabled()) {
         // 将 Layout 当作当前视图的一部分
         $view = QP_View::getInstance();
         $view->setPath(APPLICATION_PATH . '/Views/Layouts', true);
         // 将布局的变量与重新赋值给视图
         $view->assign(QP_Layout::get());
         // 'LayoutContent' 为框架的布局内容引用
         $view->LayoutContent = $viewContent;
         $layoutName = QP_Layout::name();
         $viewContent = $view->render($layoutName);
         // 使用的 Layout
         $this->_setDebugInfo('layout', $layoutName);
     }
     // 如果是 SAPI 运行模式就要设置字符集,防止乱码
     if (PHP_SAPI != 'cli') {
         header("Content-Type:text/html; charset=" . $this->_appConfig['charset']);
     }
     // 有视图内容则输出
     if ($viewContent != '') {
         echo $viewContent;
     }
     // APP运行的结束时间
     $this->_setDebugInfo('endTime', microtime(true));
     // 如果显示调试信息 并且 当前不是 AJAX 的请求 并且框架不是以 CLI方式运行
     if ($this->_appConfig['debug'] && !$this->_request->isAjax() && PHP_SAPI != 'cli') {
         $debugInfo = $this->_debugInfo;
         include QUICKPHP_PATH . '/Debug/Debuginfo.php';
     }
 }