think.class.php的start函数优化

Think.class.php里面40行到99行的代码太乱了。逻辑很简单,debug模式直接装载代码运行,非debug模式有runtime就装载runtime没有则装载代码并生成runtime文件,为何不做简单的抽离,为何要把装载代码和生成runtime弄到一块,看起来很费劲!还有就是你们到底用什么命名方式啊,runtimefile明显是错的!可不可以给出解释。


$runtimeFile = RUNTIME_PATH.APP_MODE.'~runtime.php';
if(!APP_DEBUG) { // 非debug模式
if (Storage::has($runtimeFile)) {
Storage::load($runtimeFile);
} else {
self::loadFiles();
self::generateRuntimeFile($runtimeFile);
}
}


else { // debug模式
if(Storage::has($runtimeFile)){
Storage::unlink($runtimeFile);
}
self::loadFiles();


// 调试模式加载系统默认的配置文件
C(include THINK_PATH . 'Conf/debug.php');
// 读取应用调试配置文件
if (is_file(CONF_PATH . 'debug' . CONF_EXT))
C(include CONF_PATH . 'debug' . CONF_EXT);
}


生成类
private static function generateRuntimeFile($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)) {
$content .= compile($file);
}
}


$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));
return true;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值