更新核心文件

This commit is contained in:
thinkphp
2015-03-26 16:15:35 +08:00
parent 40db699dc4
commit aa123aa8a2
11 changed files with 221 additions and 178 deletions

View File

@@ -32,7 +32,7 @@ class App {
Cache::connect($config['cache']);
// 加载框架底层语言包
is_file(THINK_PATH.'Lang/'.strtolower(Config::get('default_lang')).EXT) && Lang::set(include THINK_PATH.'Lang/'.strtolower(Config::get('default_lang')).EXT);
is_file(THINK_PATH.'Lang/'.strtolower($config['default_lang']).EXT) AND Lang::set(include THINK_PATH.'Lang/'.strtolower($config['default_lang']).EXT);
// 启动session
if(!IS_CLI) {
@@ -45,27 +45,8 @@ class App {
Hook::listen('app_init');
define('COMMON_PATH', APP_PATH . $config['common_module'].'/');
// 加载全局初始化文件
if(is_file( COMMON_PATH . 'init' . EXT )) {
include COMMON_PATH . 'init' . EXT;
}else{
// 检测全局配置文件
if(is_file(COMMON_PATH . 'config' . EXT)) {
$config = Config::set(include COMMON_PATH . 'config' . EXT);
}
// 加载全局别名文件
if(is_file(COMMON_PATH . 'alias' . EXT)) {
Loader::addMap(include COMMON_PATH . 'alias' . EXT);
}
// 加载全局公共文件
if(is_file( COMMON_PATH . 'common' . EXT)) {
include COMMON_PATH . 'common' . EXT;
}
if(is_file(COMMON_PATH . 'tags' . EXT)) {
// 全局行为扩展文件
Hook::import(include COMMON_PATH . 'tags' . EXT);
}
}
// 初始化公共模块
self::initModule(COMMON_PATH,$config);
// 应用URL调度
self::dispatch($config);
@@ -168,6 +149,39 @@ class App {
return ;
}
/**
* 初始化模块
* @access private
* @return void
*/
static private function initModule($path,&$config){
// 加载初始化文件
if(is_file( $path . 'init' . EXT )) {
include $path . 'init' . EXT;
}else{
// 检测配置文件
if(is_file($path . 'config' . EXT)) {
$config = Config::set(include $path . 'config' . EXT);
}
// 加载应用状态配置文件
if($config['app_status'] && is_file($path . $config['app_status'] . EXT)) {
$config = Config::set(include $path . $config['app_status'] . EXT);
}
// 加载别名文件
if(is_file($path . 'alias' . EXT)) {
Loader::addMap(include $path . 'alias' . EXT);
}
// 加载公共文件
if(is_file( $path . 'common' . EXT)) {
include $path . 'common' . EXT;
}
// 加载行为扩展文件
if(is_file($path . 'tags' . EXT)) {
Hook::import(include $path . 'tags' . EXT);
}
}
}
/**
* URL调度
* @access public
@@ -208,7 +222,8 @@ class App {
define('__INFO__','');
define('__EXT__','');
}else{
define('__INFO__',trim($_SERVER['PATH_INFO'],'/'));
$_SERVER['PATH_INFO'] = trim($_SERVER['PATH_INFO'],'/');
define('__INFO__',$_SERVER['PATH_INFO']);
// URL后缀
define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'],PATHINFO_EXTENSION)));
$_SERVER['PATH_INFO'] = __INFO__;
@@ -222,7 +237,9 @@ class App {
$_GET[$config['var_module']] = array_shift($paths);
$_SERVER['PATH_INFO'] = implode('/', $paths);
}
}
}
// 去除URL后缀
$_SERVER['PATH_INFO'] = preg_replace($config['url_html_suffix']? '/\.('.trim($config['url_html_suffix'],'.').')$/i' : '/\.'.__EXT__.'$/i', '', $_SERVER['PATH_INFO']);
}
// 获取模块名称
@@ -234,32 +251,8 @@ class App {
define('MODULE_PATH', APP_PATH . MODULE_NAME . '/');
define('VIEW_PATH', MODULE_PATH.VIEW_LAYER.'/');
// 加载模块初始化文件
if(is_file( MODULE_PATH . 'init' . EXT )) {
include MODULE_PATH . 'init' . EXT;
$config = Config::get();
}else{
// 检测项目(或模块)配置文件
if(is_file(MODULE_PATH . 'config' . EXT)) {
$config = Config::set(include MODULE_PATH . 'config' . EXT);
}
if($config['app_status'] && is_file(MODULE_PATH . $config['app_status'] . EXT)) {
// 加载对应的项目配置文件
$config = Config::set(include MODULE_PATH . $config['app_status'] . EXT);
}
// 加载别名文件
if(is_file(MODULE_PATH . 'alias' . EXT)) {
Loader::addMap(include MODULE_PATH . 'alias' . EXT);
}
// 加载公共文件
if(is_file( MODULE_PATH . 'common' . EXT)) {
include MODULE_PATH . 'common' . EXT;
}
if(is_file(MODULE_PATH . 'tags' . EXT)) {
// 行为扩展文件
Hook::import(include MODULE_PATH . 'tags' . EXT);
}
}
// 初始化模块
self::initModule(MODULE_PATH,$config);
}else{
throw new Exception('module not exists :' . MODULE_NAME);
}

View File

@@ -13,7 +13,7 @@ namespace think;
class Config {
static private $config = []; // 配置参数
static private $range = '_sys_'; // 参数作用域
static private $range = '_sys_'; // 参数作用域
// 设定配置参数的作用域
static public function range($range){
@@ -57,18 +57,18 @@ class Config {
}
$name = strtolower($name);
if (!strpos($name, '.')) {
// 判断环境变量
if(isset($_ENV[ENV_PREFIX.$name])){
return $_ENV[ENV_PREFIX.$name];
}
// 判断环境变量
if(isset($_ENV[ENV_PREFIX.$name])){
return $_ENV[ENV_PREFIX.$name];
}
return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null;
}else{
// 二维数组设置和获取支持
$name = explode('.', $name);
// 判断环境变量
if(isset($_ENV[ENV_PREFIX.$name[0].'_'.$name[1]])){
return $_ENV[ENV_PREFIX.$name[0].'_'.$name[1]];
}
// 判断环境变量
if(isset($_ENV[ENV_PREFIX.$name[0].'_'.$name[1]])){
return $_ENV[ENV_PREFIX.$name[0].'_'.$name[1]];
}
return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null;
}
}
@@ -97,4 +97,9 @@ class Config {
return null; // 避免非法参数
}
}
// 获取某个作用域的配置列表
static public function getRange($rang){
return isset(self::$config[$range]) ? self::$config[$range] : null;
}
}

View File

@@ -96,7 +96,7 @@ class Error {
static public function halt($error) {
IS_CLI && exit(is_array($error)?$error['message']:$error);
$e = [];
if (Config::get('app_debug')) {
if (APP_DEBUG) {
//调试模式下输出错误信息
if (!is_array($error)) {
$trace = debug_backtrace();

View File

@@ -48,11 +48,13 @@ class Hook {
if(isset(self::$tags[$tag])) {
foreach (self::$tags[$tag] as $name) {
Config::get('app_debug') && Debug::remark('behavior_start','time');
if(APP_DEBUG){
Debug::remark('behavior_start','time');
}
$result = self::exec($name, $tag,$params);
if(Config::get('app_debug')){
if(APP_DEBUG){
Debug::remark('behavior_end','time');
Log::record('Run '.$name.' [ RunTime:'.Debug::getUseTime('behavior_start','behavior_end').'s ]','INFO');
}

View File

@@ -22,16 +22,16 @@ class Template {
'tpl_path' => VIEW_PATH, // 模板路径
'tpl_suffix' => '.html', // 默认模板文件后缀
'cache_suffix' => '.php', // 默认模板缓存后缀
'tpl_deny_func_list' => 'echo,exit', // 模板引擎禁用函数
'tpl_deny_func_list' => 'echo,exit', // 模板引擎禁用函数
'tpl_deny_php' => false, // 默认模板引擎是否禁用PHP原生代码
'tpl_begin' => '{', // 模板引擎普通标签开始标记
'tpl_end' => '}', // 模板引擎普通标签结束标记
'strip_space' => false, // 是否去除模板文件里面的html空格与换行
'tpl_cache' => true, // 是否开启模板编译缓存,设为false则每次都会重新编译
'compile_type' => 'file', // 模板编译类型
'strip_space' => false, // 是否去除模板文件里面的html空格与换行
'tpl_cache' => true, // 是否开启模板编译缓存,设为false则每次都会重新编译
'compile_type' => 'file', // 模板编译类型
'cache_path' => CACHE_PATH, // 模板缓存目录
'cache_prefix' => '', // 模板缓存前缀标识,可以动态改变
'cache_time' => 0, // 模板缓存有效期 0 为永久,(以数字为值,单位:秒)
'cache_time' => 0, // 模板缓存有效期 0 为永久,(以数字为值,单位:秒)
'layout_item' => '{__CONTENT__}', // 布局模板的内容替换标识
'taglib_begin' => '<', // 标签库标签开始标记
'taglib_end' => '>', // 标签库标签结束标记
@@ -39,6 +39,7 @@ class Template {
'taglib_build_in' => 'cx', // 内置标签库名称(标签使用不必指定标签库名称),以逗号分隔 注意解析顺序
'taglib_pre_load' => '', // 需要额外加载的标签库(须指定标签库名称),多个以逗号分隔
'display_cache' => false, // 模板渲染缓存
'tpl_replace_string' => [],
];
private $literal = [];
@@ -210,6 +211,9 @@ class Template {
}
// 优化生成的php代码
$content = str_replace('?><?php','',$content);
// 模板过滤输出
$replace = $this->config['tpl_replace_string'];
$content = str_replace(array_keys($replace),array_values($replace),$content);
// 编译存储
$this->storage->write($cacheFile,$content);
return ;
@@ -453,6 +457,7 @@ class Template {
$end = $this->config['taglib_end'];
$className = '\\think\\template\\taglib\\'.strtolower($tagLib);
$tLib = new $className($this);
//$that = $this;
foreach ($tLib->getTags() as $name=>$val){
$tags = [$name];
if(isset($val['alias'])) {// 别名设置
@@ -470,14 +475,14 @@ class Template {
$n1 = empty($val['attr'])?'(\s*?)':'\s([^'.$end.']*)';
if (!$closeTag){
$patterns = '/'.$begin.$parseTag.$n1.'\/(\s*?)'.$end.'/is';
$content = preg_replace_callback($patterns, function($matches){
return $this->parseXmlTag($tLib, $tagLib, $tag, $matches[0], $matches[1]);
$content = preg_replace_callback($patterns, function($matches) use($tLib,$tagLib,$tag){
return $this->parseXmlTag($tLib, $tagLib, $tag, $matches[1], $matches[2]);
}, $content);
}else{
$patterns = '/'.$begin.$parseTag.$n1.$end.'(.*?)'.$begin.'\/'.$parseTag.'(\s*?)'.$end.'/is';
for($i=0;$i<$level;$i++){
$content = preg_replace_callback($patterns, function($matches){
return $this->parseXmlTag($tLib, $tagLib, $tag, $matches[0], $matches[1]);
$content = preg_replace_callback($patterns, function($matches) use($tLib,$tagLib,$tag){
return $this->parseXmlTag($tLib, $tagLib, $tag, $matches[1], $matches[2]);
}, $content);
}
}
@@ -504,7 +509,6 @@ class Template {
$parse = '_'.$tag;
$content = trim($content);
$tags = $tLib->parseXmlAttr($attr,$tag);
$tLib->tpl = $this;
return $tLib->$parse($tags,$content);
}

View File

@@ -91,10 +91,10 @@ class Url {
$path = explode($depr,$url);
$var = [];
$var[Config::get('var_action')] = !empty($path)?array_pop($path):ACTION_NAME;
if(Config::get('require_controller')) {
if(!defined('BIND_CONTROLLER')){
$var[Config::get('var_controller')] = !empty($path)?array_pop($path):CONTROLLER_NAME;
}
if(Config::get('require_module')) {
if(!defined('BIND_MODULE')){
$var[Config::get('var_module')] = !empty($path)?array_pop($path):MODULE_NAME;
}
}