更新tp5内核
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -12,6 +12,7 @@
|
||||
namespace think;
|
||||
|
||||
use think\exception\TemplateNotFoundException;
|
||||
use think\template\TagLib;
|
||||
|
||||
/**
|
||||
* ThinkPHP分离出来的模板引擎
|
||||
@@ -59,6 +60,7 @@ class Template
|
||||
/**
|
||||
* 构造函数
|
||||
* @access public
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(array $config = [])
|
||||
{
|
||||
@@ -120,7 +122,7 @@ class Template
|
||||
* 模板引擎配置项
|
||||
* @access public
|
||||
* @param array|string $config
|
||||
* @return void|array
|
||||
* @return string|void|array
|
||||
*/
|
||||
public function config($config)
|
||||
{
|
||||
@@ -183,7 +185,7 @@ class Template
|
||||
}
|
||||
$template = $this->parseTemplateFile($template);
|
||||
if ($template) {
|
||||
$cacheFile = $this->config['cache_path'] . $this->config['cache_prefix'] . md5($template) . '.' . ltrim($this->config['cache_suffix'], '.');
|
||||
$cacheFile = $this->config['cache_path'] . $this->config['cache_prefix'] . md5($this->config['layout_name'] . $template) . '.' . ltrim($this->config['cache_suffix'], '.');
|
||||
if (!$this->checkCache($cacheFile)) {
|
||||
// 缓存无效 重新模板编译
|
||||
$content = file_get_contents($template);
|
||||
@@ -234,7 +236,7 @@ class Template
|
||||
* @access public
|
||||
* @param mixed $name 布局模板名称 false 则关闭布局
|
||||
* @param string $replace 布局模板内容替换标识
|
||||
* @return object
|
||||
* @return Template
|
||||
*/
|
||||
public function layout($name, $replace = '')
|
||||
{
|
||||
@@ -688,6 +690,7 @@ class Template
|
||||
} else {
|
||||
$className = '\\think\\template\\taglib\\' . ucwords($tagLib);
|
||||
}
|
||||
/** @var Taglib $tLib */
|
||||
$tLib = new $className($this);
|
||||
$tLib->parseTag($content, $hide ? '' : $tagLib);
|
||||
return;
|
||||
@@ -763,31 +766,26 @@ class Template
|
||||
} else {
|
||||
if (isset($array[1])) {
|
||||
$this->parseVar($array[2]);
|
||||
$_name = ' && ' . $name . $array[1] . $array[2];
|
||||
$express = $name . $array[1] . $array[2];
|
||||
} else {
|
||||
$_name = '';
|
||||
$express = false;
|
||||
}
|
||||
// $name为数组
|
||||
switch ($first) {
|
||||
case '?':
|
||||
// {$varname??'xxx'} $varname有定义则输出$varname,否则输出xxx
|
||||
$str = '<?php echo isset(' . $name . ')' . $_name . ' ? ' . $name . ' : ' . substr($str, 1) . '; ?>';
|
||||
$str = '<?php echo ' . ($express ?: 'isset(' . $name . ')') . '?' . $name . ':' . substr($str, 1) . '; ?>';
|
||||
break;
|
||||
case '=':
|
||||
// {$varname?='xxx'} $varname为真时才输出xxx
|
||||
$str = '<?php if(!empty(' . $name . ')' . $_name . ') echo ' . substr($str, 1) . '; ?>';
|
||||
$str = '<?php if(' . ($express ?: '!empty(' . $name . ')') . ') echo ' . substr($str, 1) . '; ?>';
|
||||
break;
|
||||
case ':':
|
||||
// {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx
|
||||
$str = '<?php echo !empty(' . $name . ')' . $_name . '?' . $name . $str . '; ?>';
|
||||
$str = '<?php echo ' . ($express ?: '!empty(' . $name . ')') . '?' . $name . $str . '; ?>';
|
||||
break;
|
||||
default:
|
||||
if (strpos($str, ':')) {
|
||||
// {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b
|
||||
$str = '<?php echo !empty(' . $name . ')' . $_name . '?' . $str . '; ?>';
|
||||
} else {
|
||||
$str = '<?php echo ' . $_name . '?' . $str . '; ?>';
|
||||
}
|
||||
$str = '<?php echo ' . ($express ?: '!empty(' . $name . ')') . '?' . $str . '; ?>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -1075,7 +1073,7 @@ class Template
|
||||
} else {
|
||||
$path = isset($module) ? APP_PATH . $module . DS . basename($this->config['view_path']) . DS : $this->config['view_path'];
|
||||
}
|
||||
$template = $path . $template . '.' . ltrim($this->config['view_suffix'], '.');
|
||||
$template = realpath($path . $template . '.' . ltrim($this->config['view_suffix'], '.'));
|
||||
}
|
||||
|
||||
if (is_file($template)) {
|
||||
|
||||
Reference in New Issue
Block a user