class Think {
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);
// ...
// /home/www/www.domain.com/core/Mode/common.php
$mode = include is_file(CONF_PATH.'core.php')?CONF_PATH.'core.php':MODE_PATH.APP_MODE.'.php';
//---------------- core ----------------
// 加载核心文件 /home/www/www.domain.com/core/Mode/common.php
foreach ($mode['core'] as $file){
if(is_file($file)) {
include $file;
if(!APP_DEBUG) $content .= compile($file);
}
}
// {
// /home/www/www.domain.com/core/Common/functions.php
// /home/www/www.domain.com/myapp/Common/functions.php
// /home/www/www.domain.com/core/Library/Think/Hook.class.php,
// /home/www/www.domain.com/core/Library/Think/App.class.php,
// /home/www/www.domain.com/core/Library/Think/Dispatcher.class.php,
// /home/www/www.domain.com/core/Library/Think/Route.class.php,
// /home/www/www.domain.com/core/Library/Think/Controller.class.php,
// /home/www/www.domain.com/core/Library/Think/View.class.php,
// /home/www/www.domain.com/core/Library/Behavior/BuildLiteBehavior.class.php,
// /home/www/www.domain.com/core/Library/Behavior/ParseTemplateBehavior.class.php,
// /home/www/www.domain.com/core/Library/Behavior/ContentReplaceBehavior.class.php,
// }
//---------------- config ----------------
// 加载应用模式配置文件 /home/www/www.domain.com/core/Mode/common.php
foreach ($mode['config'] as $key=>$file){
is_numeric($key)?C(load_config($file)):C($key,load_config($file));
}
// $mode['config'] = {
// /home/www/www.domain.com/core/Conf/convention.php, // 系统惯例配置
// /home/www/www.domain.com/myapp/Common/Conf/config.php, // 应用公共配置
// }
//---------------- alias ----------------
// 加载模式别名定义 /home/www/www.domain.com/core/Mode/common.php
if(isset($mode['alias'])){
self::addMap(is_array($mode['alias'])?$mode['alias']:include $mode['alias']);
}
// $mode['alias'] = {
// 'Think\Log' => '/home/www/www.domain.com/core/Library/Think/Log.class.php',
// 'Think\Log\Driver\File' => '/home/www/www.domain.com/core/Library/Think/Log/Driver/File',
// 'Think\Exception' => '/home/www/www.domain.com/core/Library/Think/Exception',
// 'Think\Model' => '/home/www/www.domain.com/core/Library/Think/Model',
// 'Think\Db' => '/home/www/www.domain.com/core/Library/Think/Db',
// 'Think\Template' => '/home/www/www.domain.com/core/Library/Think/Template',
// 'Think\Cache' => '/home/www/www.domain.com/core/Library/Think/Cache',
// 'Think\Cache\Driver\File' => '/home/www/www.domain.com/core/Library/Think/Cache/Driver/File',
// 'Think\Storage' => '/home/www/www.domain.com/core/Library/Think/Storage',
// }
// 加载应用别名定义文件 /home/www/www.domain.com/<myapp>/Common/alias.php
if(is_file(CONF_PATH.'alias.php'))
self::addMap(include CONF_PATH.'alias.php');
//---------------- tags ----------------
// 加载模式行为定义 /home/www/www.domain.com/core/Mode/common.php
if(isset($mode['tags'])) {
// 如: self::$tags['app_init'][] = 'Behavior\BuildLiteBehavior';
Hook::import(is_array($mode['tags'])?$mode['tags']:include $mode['tags']);
}
// $mode['tags'] = {
// 'app_init' => array(
// 'Behavior\BuildLiteBehavior', // 生成运行Lite文件
// ),
// 'app_begin' => array(
// 'Behavior\ReadHtmlCacheBehavior', // 读取静态缓存
// ),
// 'app_end' => array(
// 'Behavior\ShowPageTraceBehavior', // 页面Trace显示
// ),
// 'view_parse' => array(
// 'Behavior\ParseTemplateBehavior', // 模板解析 支持PHP、内置模板引擎和第三方模板引擎
// ),
// 'template_filter'=> array(
// 'Behavior\ContentReplaceBehavior', // 模板输出替换
// ),
// 'view_filter' => array(
// 'Behavior\WriteHtmlCacheBehavior', // 写入静态缓存
// ),
// }
// 加载应用行为定义 /home/www/www.domain.com/<myapp>/Common/Conf/tags.php
if(is_file(CONF_PATH.'tags.php'))
// 如:
// 定义: self::$tags['method1'][] = 'UnStandardBehavior\CheckClientIp';
// 执行: Hook::listen('method1');
// 允许应用增加开发模式配置定义
Hook::import(include CONF_PATH.'tags.php');
// 加载框架底层语言包 /home/www/www.domain.com/core/Lang/zh-cn.php
L(include THINK_PATH.'Lang/'.strtolower(C('DEFAULT_LANG')).'.php');
if(!APP_DEBUG){
// 生成合并后的执行文件
// /home/www/www.domain.com/<myapp>/Runtime/common~runtime.php
}else{
// 调试模式加载系统默认的配置文件 /home/www/www.domain.com/core/Conf/debug.php
C(include THINK_PATH.'Conf/debug.php');
// 读取应用调试配置文件 /home/www/www.domain.com/<myapp>/Common/Conf/debug.php
if(is_file(CONF_PATH.'debug'.CONF_EXT))
C(include CONF_PATH.'debug'.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);
}
}
// ...
// 运行应用
App::run();
}
}