View类和模板引擎驱动分离调整 模板主题功能取消

This commit is contained in:
thinkphp
2016-04-18 15:32:18 +08:00
parent 455a18e85a
commit c2ef6cc883
6 changed files with 231 additions and 169 deletions

View File

@@ -172,7 +172,7 @@ class Template
if (!empty($this->config['cache_id']) && $this->config['display_cache']) {
// 读取渲染缓存
$cacheContent = Cache::get($this->config['cache_id']);
if ($cacheContent !== false) {
if (false !== $cacheContent) {
echo $cacheContent;
return;
}
@@ -205,13 +205,17 @@ class Template
* @access public
* @param string $content 模板内容
* @param array $vars 模板变量
* @param array $config 模板参数
* @return void
*/
public function fetch($content, $vars = [])
public function fetch($content, $vars = [], $config = [])
{
if ($vars) {
$this->data = $vars;
}
if ($config) {
$this->config($config);
}
$cacheFile = $this->config['cache_path'] . $this->config['cache_prefix'] . md5($content) . $this->config['cache_suffix'];
if (!$this->checkCache($cacheFile)) {
// 缓存无效 模板编译
@@ -736,31 +740,31 @@ class Template
} elseif (')' == substr($name, -1, 1)) {
// $name为对象或是自动识别或者含有函数
switch ($first) {
case '?':
case '?':
$str = '<?php echo ' . $name . ' ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
break;
case '=':
case '=':
$str = '<?php if(' . $name . ') echo ' . substr($str, 1) . '; ?>';
break;
default:
default:
$str = '<?php echo ' . $name . '?' . $str . '; ?>';
}
} else {
// $name为数组
switch ($first) {
case '?':
case '?':
// {$varname??'xxx'} $varname有定义则输出$varname,否则输出xxx
$str = '<?php echo isset(' . $name . ') ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
break;
case '=':
case '=':
// {$varname?='xxx'} $varname为真时才输出xxx
$str = '<?php if(!empty(' . $name . ')) echo ' . substr($str, 1) . '; ?>';
break;
case ':':
case ':':
// {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx
$str = '<?php echo !empty(' . $name . ')?' . $name . $str . '; ?>';
break;
default:
default:
if (strpos($str, ':')) {
// {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b
$str = '<?php echo !empty(' . $name . ')?' . $str . '; ?>';
@@ -838,13 +842,13 @@ class Template
$parseStr = $this->parseThinkVar($vars);
} else {
switch ($this->config['tpl_var_identify']) {
case 'array': // 识别为数组
case 'array': // 识别为数组
$parseStr = $first . '[\'' . implode('\'][\'', $vars) . '\']';
break;
case 'obj': // 识别为对象
case 'obj': // 识别为对象
$parseStr = $first . '->' . implode('->', $vars);
break;
default: // 自动判断数组或对象
default: // 自动判断数组或对象
$parseStr = '(is_array(' . $first . ')?' . $first . '[\'' . implode('\'][\'', $vars) . '\']:' . $first . '->' . implode('->', $vars) . ')';
}
}
@@ -890,14 +894,14 @@ class Template
// 模板函数过滤
$fun = trim($args[0]);
switch ($fun) {
case 'default': // 特殊模板函数
case 'default': // 特殊模板函数
if (false === strpos($name, '(')) {
$name = '(isset(' . $name . ') && (' . $name . ' !== \'\')?' . $name . ':' . $args[1] . ')';
} else {
$name = '(' . $name . ' !== \'\'?' . $name . ':' . $args[1] . ')';
}
break;
default: // 通用模板函数
default: // 通用模板函数
if (!in_array($fun, $template_deny_funs)) {
if (isset($args[1])) {
if (strstr($args[1], '###')) {
@@ -1045,15 +1049,8 @@ class Template
$template = str_replace(['/', ':'], $this->config['view_depr'], $template);
$template = APP_PATH . str_replace('@', '/' . basename($this->config['view_path']) . '/', $template) . $this->config['view_suffix'];
} else {
if (strpos($template, ':')) {
// 指定主题
list($theme, $template) = explode(':', $template, 2);
$path = dirname($this->config['view_path']) . DS . $theme . DS;
} else {
$path = $this->config['view_path'];
}
$template = str_replace(['/', ':'], $this->config['view_depr'], $template);
$template = $path . $template . $this->config['view_suffix'];
$template = $this->config['view_path'] . $template . $this->config['view_suffix'];
}
}
if (is_file($template)) {