public static function start() { //注册自动加载类函数 spl_autoload_register('self::autoload'); //导入公用的函数 include THINK_PATH . 'Common/functions.php'; //导入通用的function函数 if (is_file(COMMON_PATH . 'Common/function.php')) { include COMMON_PATH . 'Common/function.php'; } //导入通用的配置文件 C(include THINK_PATH . 'Conf/convention.php'); // 设置系统时区 date_default_timezone_set(C('DEFAULT_TIMEZONE')); // 检查应用目录结构 如果不存在则自动创建 if (C('CHECK_APP_DIR')) { if (!is_dir(LOG_PATH)) { // 检测应用目录结构 Build::checkDir(); } } // 定义当前请求的系统常量 define('NOW_TIME', $_SERVER['REQUEST_TIME']); define('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']); define('IS_GET', REQUEST_METHOD == 'GET' ? true : false); define('IS_POST', REQUEST_METHOD == 'POST' ? true : false); //路由解析 self::dispatch(); define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' || !empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')]) ? true : false); //初始化session session(C('SESSION_OPTIONS')); //执行应用程序 self::exec(); }
public static function start() { //注册AUTOLOAD方法 spl_autoload_register('\\Core\\HF::autoload'); //自动生成目录 Build::checkDir(); //加载项目下配置文件 if (is_file(CONF_PATH . 'config.php')) { C(include CONF_PATH . 'config.php'); } //运行应用 App::run(); }
// 实例化对象 private static $_instance = array(); /** * 应用程序初始化 * @access public * @return void */ public static function start() { // 注册AUTOLOAD方法 spl_autoload_register('Think\\Think::autoload'); // 设定错误和异常处理 register_shutdown_function('Think\\Think::fatalError'); set_error_handler('Think\\Think::appError'); set_exception_handler('Think\\Think::appException'); // 初始化文件存储方式 Storage::connect(STORAGE_TYPE); $runtimefile = RUNTIME_PATH . APP_MODE . '~runtime.php'; if (!APP_DEBUG && Storage::has($runtimefile)) { Storage::load($runtimefile); } else { if (Storage::has($runtimefile)) { Storage::unlink($runtimefile); } $content = ''; // 读取应用模式 $mode = (include is_file(CONF_PATH . 'core.php') ? CONF_PATH . 'core.php' : MODE_PATH . APP_MODE . '.php'); // 加载核心文件 foreach ($mode['core'] as $file) { if (is_file($file)) { include $file; if (!APP_DEBUG) { $content .= compile($file); } } } // 加载应用模式配置文件 foreach ($mode['config'] as $key => $file) { is_numeric($key) ? C(load_config($file)) : C($key, load_config($file)); } // 读取当前应用模式对应的配置文件 if ('common' != APP_MODE && is_file(CONF_PATH . 'config_' . APP_MODE . CONF_EXT)) { C(load_config(CONF_PATH . 'config_' . APP_MODE . CONF_EXT)); } // 加载模式别名定义 if (isset($mode['alias'])) { self::addMap(is_array($mode['alias']) ? $mode['alias'] : (include $mode['alias'])); } // 加载应用别名定义文件 if (is_file(CONF_PATH . 'alias.php')) { self::addMap(include CONF_PATH . 'alias.php'); } // 加载模式行为定义 if (isset($mode['tags'])) { Hook::import(is_array($mode['tags']) ? $mode['tags'] : (include $mode['tags'])); } // 加载应用行为定义 if (is_file(CONF_PATH . 'tags.php')) { // 允许应用增加开发模式配置定义 Hook::import(include CONF_PATH . 'tags.php'); } // 加载框架底层语言包 L(include THINK_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php'); if (!APP_DEBUG) { $content .= "\nnamespace { Think\\Think::addMap(" . var_export(self::$_map, true) . ");"; $content .= "\nL(" . var_export(L(), true) . ");\nC(" . var_export(C(), true) . ');Think\\Hook::import(' . var_export(Hook::get(), true) . ');}'; Storage::put($runtimefile, strip_whitespace('<?php ' . $content)); } else { // 调试模式加载系统默认的配置文件 C(include THINK_PATH . 'Conf/debug.php'); // 读取应用调试配置文件 if (is_file(CONF_PATH . 'debug' . CONF_EXT)) { C(include CONF_PATH . 'debug' . CONF_EXT); } } } // 读取当前应用状态对应的配置文件 if (APP_STATUS && is_file(CONF_PATH . APP_STATUS . CONF_EXT)) { C(include CONF_PATH . APP_STATUS . CONF_EXT); } // 设置系统时区 date_default_timezone_set(C('DEFAULT_TIMEZONE')); // 检查应用目录结构 如果不存在则自动创建 if (C('CHECK_APP_DIR')) { $module = defined('BIND_MODULE') ? BIND_MODULE : C('DEFAULT_MODULE'); if (!is_dir(APP_PATH . $module) || !is_dir(LOG_PATH)) { // 检测应用目录结构 Build::checkDir($module); }