示例#1
0
 /**
  * 开始运行应用.
  * 
  * @access public
  * @return void
  */
 public static function run()
 {
     ini_set('session.auto_start', 0);
     // 关闭 php.ini 中的自动开启 session.
     $configs = Config::get();
     // 设置时区.
     date_default_timezone_set($configs['default_timezone']);
     if ($configs['gzip_output'] && function_exists('ob_gzhandler')) {
         ob_start('ob_gzhandler');
     } else {
         ob_start();
     }
     header('Content-type: text/html; charset=' . $configs['default_charset']);
     unset($configs);
     if (NULL !== self::$onBeforeParseRequest) {
         call_user_func(self::$onBeforeParseRequest);
     }
     Url::parseRequest();
     // 解析请求.
     if (NULL !== self::$onBeforeDispatch) {
         call_user_func(self::$onBeforeDispatch);
     }
     Url::dispatch();
     // 请求分发.
     ob_end_flush();
     flush();
 }
示例#2
0
 /**
  * 获取模板文件路径.
  * $tplName 格式参见 display 方法说明.
  *
  * @access public
  * @param string $tplName 模板名称, 默认 NULL.
  * @return array ['tpl' => 模板文件路径, 'compile' => 模板编译文件路径]
  */
 protected function fetchViewPath($tplName = NULL)
 {
     $isGroup = Url::isGroup();
     $groupName = Url::groupName();
     $controllerName = Url::controllerName();
     $actionName = Url::actionName();
     $style = '';
     // 主题名称.
     // 临时主题目录名, 只能用一次 theme 方法, 但 theme 方法设置主题名的优先级低于冒号格式的设置.
     if (FALSE !== $this->_theme) {
         $style = $this->_theme;
         $this->_theme = FALSE;
     }
     // 判断 $tplName 已指定 主题名 的情况.
     $pos = NULL === $tplName ? FALSE : strpos($tplName, ':');
     if (FALSE !== $pos) {
         list($style, $tplName) = explode(':', $tplName);
     }
     $style = empty($style) ? $this->style : $style;
     $style = empty($style) ? '' : $style . '/';
     $result['tpl'] = $this->tplDir . $style;
     $result['compile'] = $this->compileDir . $style;
     $fullTpl = '';
     // 解析模板名称.
     if (NULL === $tplName || empty($tplName)) {
         $fullTpl = ($isGroup ? $groupName . '/' : '') . $controllerName . '/' . $actionName;
     } else {
         $arrTpl = explode('/', $tplName);
         $tplLen = count($arrTpl);
         $fullTpl = $tplName;
         if ($isGroup && 1 === $tplLen) {
             $fullTpl = $groupName . '/' . $controllerName . '/' . $fullTpl;
         } elseif ($isGroup && 2 === $tplLen) {
             $fullTpl = $groupName . '/' . $fullTpl;
         } elseif (1 === $tplLen) {
             $fullTpl = $controllerName . '/' . $fullTpl;
         } elseif ($tplLen > ($isGroup ? 3 : 2)) {
             $arrTpl = array_slice($arrTpl, 0, $isGroup ? 3 : 2);
             $fullTpl = implode('/', $arrTpl);
         }
     }
     $pos = strrpos($fullTpl, '/');
     $oriTplName = substr($fullTpl, $pos + 1);
     // 模板文件名.
     $oriTplPath = substr($fullTpl, 0, $pos);
     // 相对路径.
     $result['tpl'] .= $fullTpl . $this->tplSuffix;
     $result['compile'] .= $oriTplPath . '/' . md5($oriTplName) . '_' . $oriTplName . '.php';
     return $result;
 }