Beispiel #1
0
 /**
 +----------------------------------------------------------
 * 应用程序初始化
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @return void
 +----------------------------------------------------------
 */
 public static function init()
 {
     // 设定错误和异常处理
     set_error_handler(array('App', 'appError'));
     set_exception_handler(array('App', 'appException'));
     //[RUNTIME]
     // 检查项目是否编译过
     // 在部署模式下会自动在第一次执行的时候编译项目
     if (defined('RUNTIME_MODEL')) {
         // 运行模式无需载入项目编译缓存
     } elseif (is_file(RUNTIME_PATH . '~app.php') && (!is_file(CONFIG_PATH . 'config.php') || filemtime(RUNTIME_PATH . '~app.php') > filemtime(CONFIG_PATH . 'config.php'))) {
         // 直接读取编译后的项目文件
         C(include RUNTIME_PATH . '~app.php');
     } else {
         // 预编译项目
         App::build();
     }
     //[/RUNTIME]
     // 项目开始标签
     if (C('APP_PLUGIN_ON')) {
         tag('app_begin');
     }
     // 设置系统时区 PHP5支持
     if (function_exists('date_default_timezone_set')) {
         date_default_timezone_set(C('DEFAULT_TIMEZONE'));
     }
     // 允许注册AUTOLOAD方法
     if (C('APP_AUTOLOAD_REG') && function_exists('spl_autoload_register')) {
         spl_autoload_register(array('Think', 'autoload'));
     }
     if (C('SESSION_AUTO_START')) {
         session_start();
     }
     // Session初始化
     // 应用调度过滤器
     // 如果没有加载任何URL调度器
     // 默认只支持 QUERY_STRING 方式
     if (C('URL_DISPATCH_ON')) {
         Dispatcher::dispatch();
     }
     if (!defined('PHP_FILE')) {
         // PHP_FILE 由内置的Dispacher定义
         // 如果不使用该插件,需要重新定义
         define('PHP_FILE', _PHP_FILE_);
     }
     // 取得模块和操作名称
     // 可以在Dispatcher中定义获取规则
     // 加载项目分组公共文件
     if (C('APP_GROUP_LIST')) {
         if (!defined('GROUP_NAME')) {
             define('GROUP_NAME', App::getGroup());
         }
         // Group名称
         // 分组配置文件
         if (is_file(CONFIG_PATH . GROUP_NAME . '/config.php')) {
             C(include CONFIG_PATH . GROUP_NAME . '/config.php');
         }
         // 分组函数文件
         if (is_file(COMMON_PATH . GROUP_NAME . '/function.php')) {
             include COMMON_PATH . GROUP_NAME . '/function.php';
         }
     }
     if (!defined('MODULE_NAME')) {
         define('MODULE_NAME', App::getModule());
     }
     // Module名称
     if (!defined('ACTION_NAME')) {
         define('ACTION_NAME', App::getAction());
     }
     // Action操作
     // 加载模块配置文件
     if (is_file(CONFIG_PATH . strtolower(MODULE_NAME) . '_config.php')) {
         C(include CONFIG_PATH . strtolower(MODULE_NAME) . '_config.php');
     }
     // 系统检查
     App::checkLanguage();
     //语言检查
     App::checkTemplate();
     //模板检查
     if (C('HTML_CACHE_ON')) {
         // 开启静态缓存
         HtmlCache::readHTMLCache();
     }
     // 项目初始化标签
     if (C('APP_PLUGIN_ON')) {
         tag('app_init');
     }
     return;
 }
Beispiel #2
0
 public static function init()
 {
     set_error_handler(array('App', 'appError'));
     set_exception_handler(array('App', 'appException'));
     if (defined('RUNTIME_MODEL')) {
     } elseif (is_file(RUNTIME_PATH . '~app.php') && (!is_file(CONFIG_PATH . 'config.php') || filemtime(RUNTIME_PATH . '~app.php') > filemtime(CONFIG_PATH . 'config.php'))) {
         C(include RUNTIME_PATH . '~app.php');
     } else {
         App::build();
     }
     if (C('APP_PLUGIN_ON')) {
         tag('app_begin');
     }
     if (function_exists('date_default_timezone_set')) {
         date_default_timezone_set(C('DEFAULT_TIMEZONE'));
     }
     if (C('APP_AUTOLOAD_REG') && function_exists('spl_autoload_register')) {
         spl_autoload_register(array('Think', 'autoload'));
     }
     if (C('SESSION_AUTO_START')) {
         session_start();
     }
     if (C('URL_DISPATCH_ON')) {
         Dispatcher::dispatch();
     }
     if (!defined('PHP_FILE')) {
         define('PHP_FILE', _PHP_FILE_);
     }
     if (C('APP_GROUP_LIST')) {
         if (!defined('GROUP_NAME')) {
             define('GROUP_NAME', App::getGroup());
         }
         if (is_file(CONFIG_PATH . GROUP_NAME . '/config.php')) {
             C(include CONFIG_PATH . GROUP_NAME . '/config.php');
         }
         if (is_file(COMMON_PATH . GROUP_NAME . '/function.php')) {
             include COMMON_PATH . GROUP_NAME . '/function.php';
         }
     }
     if (!defined('MODULE_NAME')) {
         define('MODULE_NAME', App::getModule());
     }
     if (!defined('ACTION_NAME')) {
         define('ACTION_NAME', App::getAction());
     }
     if (is_file(CONFIG_PATH . strtolower(MODULE_NAME) . '_config.php')) {
         C(include CONFIG_PATH . strtolower(MODULE_NAME) . '_config.php');
     }
     App::checkLanguage();
     App::checkTemplate();
     if (C('HTML_CACHE_ON')) {
         HtmlCache::readHTMLCache();
     }
     if (C('APP_PLUGIN_ON')) {
         tag('app_init');
     }
     return;
 }