From a8233aaf4abbdc0264a833d292b034cb9a2cd457 Mon Sep 17 00:00:00 2001 From: chunice Date: Tue, 15 Mar 2016 14:45:27 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=A1=86=E6=9E=B6?= =?UTF-8?q?=E6=83=AF=E4=BE=8B=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/convention.php b/convention.php index 6c7a5e42..3854ddfe 100644 --- a/convention.php +++ b/convention.php @@ -121,7 +121,9 @@ return [ // +---------------------------------------------------------------------- 'log' => [ - 'type' => 'File', // 支持 file socket trace sae + // 日志记录方式,支持 file socket trace sae + 'type' => 'File', + // 日志保存目录 'path' => LOG_PATH, ], @@ -130,9 +132,13 @@ return [ // +---------------------------------------------------------------------- 'cache' => [ + // 驱动方式 'type' => 'File', + // 缓存保存目录 'path' => CACHE_PATH, + // 缓存前缀 'prefix' => '', + // 缓存有效期 0表示永久缓存 'expire' => 0, ], @@ -142,9 +148,13 @@ return [ 'session' => [ 'id' => '', - 'var_session_id' => '', // SESSION_ID的提交变量,解决flash上传跨域 + // SESSION_ID的提交变量,解决flash上传跨域 + 'var_session_id' => '', + // SESSION 前缀 'prefix' => 'think', + // 驱动方式 支持redis memcache memcached 'type' => '', + // 是否自动开启 SESSION 'auto_start' => true, ], From f043633ff4eabff92791c6caaeb7f02089a67605 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Mar 2016 18:24:51 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E6=94=B9=E8=BF=9BView=E7=B1=BB=E5=92=8CT?= =?UTF-8?q?emplate=E7=B1=BB=20=E7=AE=80=E5=8C=96=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=EF=BC=88=E5=8F=96=E6=B6=88=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BE=A6=E6=B5=8B=EF=BC=89=20=E5=BD=93=E5=89=8D=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E4=BD=9C=E4=B8=BAview=5Fpath=E4=BC=A0=E5=85=A5templat?= =?UTF-8?q?e=20=E6=A8=A1=E6=9D=BF=E6=A0=87=E7=AD=BE=E4=B8=AD=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E4=BD=BF=E7=94=A8=20theme:controller/action=20?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E5=85=B6=E4=BB=96=E4=B8=BB=E9=A2=98=20?= =?UTF-8?q?=E6=88=96=E8=80=85=20module@theme/controller/action=20=E8=B7=A8?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E8=B0=83=E7=94=A8=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 40 +++++++++++++++++++++++--------------- library/think/View.php | 37 +++++++++++++---------------------- 2 files changed, 37 insertions(+), 40 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index 55f2cea0..45021310 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -712,31 +712,31 @@ class Template } elseif (')' == substr($name, -1, 1)) { // $name为对象或是自动识别,或者含有函数 switch ($first) { - case '?': + case '?': $str = ''; break; - case '=': + case '=': $str = ''; break; - default: + default: $str = ''; } } else { // $name为数组 switch ($first) { - case '?': + case '?': // {$varname??'xxx'} $varname有定义则输出$varname,否则输出xxx $str = ''; break; - case '=': + case '=': // {$varname?='xxx'} $varname为真时才输出xxx $str = ''; break; - case ':': + case ':': // {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx $str = ''; break; - default: + default: if (strpos($str, ':')) { // {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b $str = ''; @@ -814,13 +814,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) . ')'; } } @@ -866,14 +866,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], '###')) { @@ -1015,13 +1015,21 @@ class Template */ private function parseTemplateFile($template) { - if (false === strpos($template, '.')) { - $template = str_replace(['/', ':'], $this->config['view_depr'], $template); - // 跨模块支持 + if (false === strpos($template, $this->config['view_suffix'])) { if (strpos($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 { - $template = $this->config['view_path'] . $template . $this->config['view_suffix']; + 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']; } } if (is_file($template)) { diff --git a/library/think/View.php b/library/think/View.php index 0db0d653..1bab915c 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -170,14 +170,6 @@ class View */ public function fetch($template = '', $vars = [], $config = [], $renderContent = false) { - if (is_null($this->engine)) { - // 初始化模板引擎 - if (empty($this->config['view_path']) && defined('VIEW_PATH')) { - $this->config['view_path'] = VIEW_PATH; - } - $this->engine($this->config['view_engine']['type'], $this->config['view_engine']); - } - // 模板变量 $vars = $vars ? $vars : $this->data; if (!$renderContent) { @@ -191,6 +183,10 @@ class View // 记录视图信息 APP_DEBUG && Log::record('[ VIEW ] ' . $template . ' [ ' . var_export($vars, true) . ' ]', 'info'); } + if (is_null($this->engine)) { + // 初始化模板引擎 + $this->engine($this->config['view_engine']['type'], $this->config['view_engine']); + } // 页面缓存 ob_start(); ob_implicit_flush(0); @@ -241,14 +237,20 @@ class View if (is_file($template)) { return realpath($template); } + if (empty($this->config['view_path']) && defined('VIEW_PATH')) { + $this->config['view_path'] = VIEW_PATH; + } + // 获取当前主题 + $theme = $this->getTemplateTheme(); + $this->config['view_path'] .= $theme; $depr = $this->config['view_depr']; $template = str_replace(['/', ':'], $depr, $template); - $theme = $this->getTemplateTheme(); - $path = $this->config['view_path']; if (strpos($template, '@')) { list($module, $template) = explode('@', $template); $path = APP_PATH . (APP_MULTI_MODULE ? $module . DS : '') . $this->config['view_layer'] . DS; + } else { + $path = $this->config['view_path']; } // 分析模板文件规则 @@ -274,24 +276,11 @@ class View if ($this->theme) { // 指定模板主题 $theme = $this->theme; - } elseif ($this->config['auto_detect_theme']) { - // 自动侦测模板主题 - $t = $this->config['var_theme']; - if (isset($_GET[$t])) { - $theme = $_GET[$t]; - } elseif (Cookie::get('think_theme')) { - $theme = Cookie::get('think_theme'); - } - if (!isset($theme) || !is_dir($this->config['view_path'] . DS . $theme)) { - $theme = $this->config['default_theme']; - } - Cookie::set('think_theme', $theme, 864000); } else { $theme = $this->config['default_theme']; } - return $theme . DS; } - return ''; + return isset($theme) ? $theme . DS : ''; } /** From 3cbd5d1b7cf03327f48325bdd26bc9f2f1ca2f04 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Mar 2016 18:34:05 +0800 Subject: [PATCH 03/16] =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=87=87=E7=94=A8template=E4=BA=8C=E7=BA=A7?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/library/think/View.php b/library/think/View.php index 1bab915c..577761b7 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -24,27 +24,23 @@ class View // 视图参数 protected $config = [ // 模板主题 - 'theme_on' => false, - // 是否自动侦测主题 - 'auto_detect_theme' => false, - // 自动侦测主题的URL变量 - 'var_theme' => 't', + 'theme_on' => false, // 默认主题 开启模板主题有效 - 'default_theme' => 'default', + 'default_theme' => 'default', // 视图文件路径 - 'view_path' => '', + 'view_path' => '', // 视图文件后缀 - 'view_suffix' => '.html', + 'view_suffix' => '.html', // 视图文件分隔符 - 'view_depr' => DS, + 'view_depr' => DS, // 视图层目录名 - 'view_layer' => VIEW_LAYER, + 'view_layer' => VIEW_LAYER, // 视图输出字符串替换 - 'parse_str' => [], + 'parse_str' => [], // 视图驱动命名空间 - 'namespace' => '\\think\\view\\driver\\', + 'namespace' => '\\think\\view\\driver\\', // 模板引擎配置参数 - 'view_engine' => [ + 'template' => [ 'type' => 'think', ], ]; @@ -142,14 +138,13 @@ class View public function theme($theme) { if (true === $theme) { - // 自动侦测 - $this->config['theme_on'] = true; - $this->config['auto_detect_theme'] = true; + // 启用主题 + $this->config['theme_on'] = true; } elseif (false === $theme) { // 关闭主题 $this->config['theme_on'] = false; } else { - // 指定模板主题 + // 指定主题 $this->config['theme_on'] = true; $this->theme = $theme; } @@ -185,7 +180,7 @@ class View } if (is_null($this->engine)) { // 初始化模板引擎 - $this->engine($this->config['view_engine']['type'], $this->config['view_engine']); + $this->engine($this->config['template']['type'], $this->config['template']); } // 页面缓存 ob_start(); From f427e4d0778dd1bcb19a25a233822c51cdbeb4d9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Mar 2016 18:42:11 +0800 Subject: [PATCH 04/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/viewTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/thinkphp/library/think/viewTest.php b/tests/thinkphp/library/think/viewTest.php index 891a25eb..741f5457 100644 --- a/tests/thinkphp/library/think/viewTest.php +++ b/tests/thinkphp/library/think/viewTest.php @@ -100,7 +100,6 @@ class viewTest extends \PHPUnit_Framework_TestCase $config_value = $property->getValue($view_instance); $this->assertTrue($config_value['theme_on']); - $this->assertTrue($config_value['auto_detect_theme']); //关闭主题测试 $data = $view_instance->theme(false); From a880485ace787d3a5fc8951f336e2f32e264edf4 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Mar 2016 21:49:33 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E6=94=B9=E8=BF=9BView=20=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E6=89=8B=E5=8A=A8=E5=88=9D=E5=A7=8B=E5=8C=96engine?= =?UTF-8?q?=E7=9A=84=E6=97=B6=E5=80=99=20view=5Fpath=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/think/View.php b/library/think/View.php index 577761b7..f47a7d24 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -118,7 +118,10 @@ class View if ('php' == $engine) { $this->engine = 'php'; } else { - $class = $this->config['namespace'] . ucwords($engine); + $class = $this->config['namespace'] . ucfirst($engine); + if (empty($this->config['view_path']) && defined('VIEW_PATH')) { + $this->config['view_path'] = VIEW_PATH; + } $config = array_merge($config, [ 'view_path' => $this->config['view_path'], 'view_suffix' => $this->config['view_suffix'], From 14d692dfcdc177d138ca4b9741cae244f6e834c3 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Mar 2016 22:02:38 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3View=E7=B1=BB=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/think/View.php b/library/think/View.php index f47a7d24..8e1bcc78 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -260,7 +260,7 @@ class View $template = str_replace('.', DS, CONTROLLER_NAME) . $depr . $template; } } - return realpath($path) . DS . $theme . $template . $this->config['view_suffix']; + return realpath($path) . DS . $template . $this->config['view_suffix']; } /** From a496cf3198b017dae4895fc3f5dfe983ac46d77a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Mar 2016 22:27:16 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 2 +- tests/thinkphp/library/think/viewTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/View.php b/library/think/View.php index 8e1bcc78..cff28228 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -260,7 +260,7 @@ class View $template = str_replace('.', DS, CONTROLLER_NAME) . $depr . $template; } } - return realpath($path) . DS . $template . $this->config['view_suffix']; + return $path . $template . $this->config['view_suffix']; } /** diff --git a/tests/thinkphp/library/think/viewTest.php b/tests/thinkphp/library/think/viewTest.php index 741f5457..590b258b 100644 --- a/tests/thinkphp/library/think/viewTest.php +++ b/tests/thinkphp/library/think/viewTest.php @@ -124,9 +124,9 @@ class viewTest extends \PHPUnit_Framework_TestCase $method = new \ReflectionMethod('\think\View', 'ParseTemplate'); $method->setAccessible(true); if (defined('CONTROLLER_NAME')) { - $expect_data = DS . 'theme_name' . DS . CONTROLLER_NAME . DS . 'template_name.html'; + $expect_data = 'view_path' . 'theme_name' . DS . CONTROLLER_NAME . DS . 'template_name.html'; } else { - $expect_data = DS . 'theme_name' . DS . 'template_name.html'; + $expect_data = 'view_path' . 'theme_name' . DS . 'template_name.html'; } $this->assertEquals($expect_data, $method->invoke($view_instance, 'template_name')); } From 3918ca395291bb73fb5b7d3ab2bda843e6e648dd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 15 Mar 2016 23:10:59 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/View.php | 2 +- tpl/think_exception.tpl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/think/View.php b/library/think/View.php index cff28228..6bc08d20 100644 --- a/library/think/View.php +++ b/library/think/View.php @@ -169,7 +169,7 @@ class View public function fetch($template = '', $vars = [], $config = [], $renderContent = false) { // 模板变量 - $vars = $vars ? $vars : $this->data; + $vars = array_merge($this->data, $vars); if (!$renderContent) { // 获取模板文件名 $template = $this->parseTemplate($template); diff --git a/tpl/think_exception.tpl b/tpl/think_exception.tpl index df1eb395..6c719fd8 100644 --- a/tpl/think_exception.tpl +++ b/tpl/think_exception.tpl @@ -13,7 +13,7 @@ padding: 20px; } h1{ - margin: 0; + margin: 10px 0 0; font-size: 28px; font-weight: 500; line-height: 32px; @@ -22,7 +22,7 @@ color: #4288ce; font-weight: 400; padding: 6px 0; - margin: 10px 6px 0 0; + margin: 6px 0 0; font-size: 18px; border-bottom: 1px solid #eee; } From 4d0310942767b45f73cf8915cce20889fecfc8d5 Mon Sep 17 00:00:00 2001 From: leunggamciu Date: Tue, 15 Mar 2016 23:44:57 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=94=99=E5=88=AB?= =?UTF-8?q?=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/README.md b/tests/README.md index 5bba9a74..0c1d0869 100644 --- a/tests/README.md +++ b/tests/README.md @@ -4,7 +4,7 @@ - conf 测试环境配置文件。 - script 测试环境配置脚本。 -- thinkphp 测试用例和相关文件,与项目文件夹机构一致。 +- thinkphp 测试用例和相关文件,与项目文件夹结构一致。 - mock.php 测试入口文件。 ## 主要测试流程 From 380ae2802174eb5025cf386186b1ab160216fcdd Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 16 Mar 2016 12:40:29 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Build.php | 8 ++++---- library/think/View.php | 2 +- .../library/think/view/default/index/template.html | 14 ++++++++++++++ tests/thinkphp/library/think/viewTest.php | 8 +++++--- 4 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 tests/thinkphp/library/think/view/default/index/template.html diff --git a/library/think/Build.php b/library/think/Build.php index 86dd6887..5b7306cf 100644 --- a/library/think/Build.php +++ b/library/think/Build.php @@ -101,13 +101,13 @@ class Build $namespace = APP_NAMESPACE . '\\' . ($module ? $module . '\\' : '') . $path; $class = $val . (CLASS_APPEND_SUFFIX ? ucfirst($path) : ''); switch ($path) { - case CONTROLLER_LAYER: // 控制器 + case CONTROLLER_LAYER: // 控制器 $content = "config['view_suffix']; + return realpath($path) . DS . $template . $this->config['view_suffix']; } /** diff --git a/tests/thinkphp/library/think/view/default/index/template.html b/tests/thinkphp/library/think/view/default/index/template.html new file mode 100644 index 00000000..5f4548be --- /dev/null +++ b/tests/thinkphp/library/think/view/default/index/template.html @@ -0,0 +1,14 @@ + + + + + + + + + Document + + + + + diff --git a/tests/thinkphp/library/think/viewTest.php b/tests/thinkphp/library/think/viewTest.php index 590b258b..b4b41d59 100644 --- a/tests/thinkphp/library/think/viewTest.php +++ b/tests/thinkphp/library/think/viewTest.php @@ -121,12 +121,14 @@ class viewTest extends \PHPUnit_Framework_TestCase public function testParseTemplate() { $view_instance = \think\View::instance(); - $method = new \ReflectionMethod('\think\View', 'ParseTemplate'); + $view_instance->theme(true); + $view_instance->config(['view_path' => __DIR__ . DS]); + $method = new \ReflectionMethod('\think\View', 'ParseTemplate'); $method->setAccessible(true); if (defined('CONTROLLER_NAME')) { - $expect_data = 'view_path' . 'theme_name' . DS . CONTROLLER_NAME . DS . 'template_name.html'; + $expect_data = __DIR__ . DS . 'default' . DS . CONTROLLER_NAME . DS . 'template.html'; } else { - $expect_data = 'view_path' . 'theme_name' . DS . 'template_name.html'; + $expect_data = __DIR__ . DS . 'default' . DS . 'template.html'; } $this->assertEquals($expect_data, $method->invoke($view_instance, 'template_name')); } From 6ee82ff9ded8734b328891bda558c9bad0b59c25 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 16 Mar 2016 13:13:22 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/viewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/thinkphp/library/think/viewTest.php b/tests/thinkphp/library/think/viewTest.php index b4b41d59..004d281b 100644 --- a/tests/thinkphp/library/think/viewTest.php +++ b/tests/thinkphp/library/think/viewTest.php @@ -130,7 +130,7 @@ class viewTest extends \PHPUnit_Framework_TestCase } else { $expect_data = __DIR__ . DS . 'default' . DS . 'template.html'; } - $this->assertEquals($expect_data, $method->invoke($view_instance, 'template_name')); + $this->assertEquals($expect_data, $method->invoke($view_instance, 'template')); } } From 7921c3c0607faff27b2f6db736ee29bc9a92d497 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 16 Mar 2016 13:23:45 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/viewTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/thinkphp/library/think/viewTest.php b/tests/thinkphp/library/think/viewTest.php index 004d281b..05bfd823 100644 --- a/tests/thinkphp/library/think/viewTest.php +++ b/tests/thinkphp/library/think/viewTest.php @@ -122,13 +122,13 @@ class viewTest extends \PHPUnit_Framework_TestCase { $view_instance = \think\View::instance(); $view_instance->theme(true); - $view_instance->config(['view_path' => __DIR__ . DS]); + $view_instance->config(['view_path' => __DIR__ . DS . 'view' . DS]); $method = new \ReflectionMethod('\think\View', 'ParseTemplate'); $method->setAccessible(true); if (defined('CONTROLLER_NAME')) { - $expect_data = __DIR__ . DS . 'default' . DS . CONTROLLER_NAME . DS . 'template.html'; + $expect_data = __DIR__ . DS . 'view' . DS . 'default' . DS . CONTROLLER_NAME . DS . 'template.html'; } else { - $expect_data = __DIR__ . DS . 'default' . DS . 'template.html'; + $expect_data = __DIR__ . DS . 'view' . DS . 'default' . DS . 'template.html'; } $this->assertEquals($expect_data, $method->invoke($view_instance, 'template')); } From 8a47be77b5692a16ec99ddc69a1f39728e67a230 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 16 Mar 2016 13:34:09 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../think/view/{default => theme}/index/template.html | 0 tests/thinkphp/library/think/viewTest.php | 5 ++--- 2 files changed, 2 insertions(+), 3 deletions(-) rename tests/thinkphp/library/think/view/{default => theme}/index/template.html (100%) diff --git a/tests/thinkphp/library/think/view/default/index/template.html b/tests/thinkphp/library/think/view/theme/index/template.html similarity index 100% rename from tests/thinkphp/library/think/view/default/index/template.html rename to tests/thinkphp/library/think/view/theme/index/template.html diff --git a/tests/thinkphp/library/think/viewTest.php b/tests/thinkphp/library/think/viewTest.php index 05bfd823..44b101a4 100644 --- a/tests/thinkphp/library/think/viewTest.php +++ b/tests/thinkphp/library/think/viewTest.php @@ -121,14 +121,13 @@ class viewTest extends \PHPUnit_Framework_TestCase public function testParseTemplate() { $view_instance = \think\View::instance(); - $view_instance->theme(true); $view_instance->config(['view_path' => __DIR__ . DS . 'view' . DS]); $method = new \ReflectionMethod('\think\View', 'ParseTemplate'); $method->setAccessible(true); if (defined('CONTROLLER_NAME')) { - $expect_data = __DIR__ . DS . 'view' . DS . 'default' . DS . CONTROLLER_NAME . DS . 'template.html'; + $expect_data = __DIR__ . DS . 'view' . DS . 'theme_name' . DS . CONTROLLER_NAME . DS . 'template.html'; } else { - $expect_data = __DIR__ . DS . 'view' . DS . 'default' . DS . 'template.html'; + $expect_data = __DIR__ . DS . 'view' . DS . 'theme_name' . DS . 'template.html'; } $this->assertEquals($expect_data, $method->invoke($view_instance, 'template')); } From 45ca16e8b7bd4cb3f4e4c7bf9e766d9e722f18ff Mon Sep 17 00:00:00 2001 From: huangdijia Date: Wed, 16 Mar 2016 13:35:56 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E4=BC=98=E5=8C=962=E5=A4=84=E5=86=99?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 60 +++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index 45021310..65be4ba9 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -221,15 +221,18 @@ class Template */ public function layout($name) { - if (false !== $name) { - $this->config['layout_on'] = true; - if (is_string($name)) { - $this->config['layout_name'] = $name; - } - } else { + if (false === $name) { // 关闭布局 $this->config['layout_on'] = false; + return $this; } + // 开启布局 + $this->config['layout_on'] = true; + // 名称必须为字符串 + if (is_string($name)) { + $this->config['layout_name'] = $name; + } + return $this; } /** @@ -241,25 +244,36 @@ class Template */ private function checkCache($cacheFile) { - if ($this->config['tpl_cache'] && is_file($cacheFile) && $handle = @fopen($cacheFile, "r")) { - // 读取第一行 - preg_match('/\/\*(.+?)\*\//', fgets($handle), $matches); - if (isset($matches[1])) { - $includeFile = unserialize($matches[1]); - if (is_array($includeFile)) { - // 检查模板文件是否有更新 - foreach ($includeFile as $path => $time) { - if (is_file($path) && filemtime($path) > $time) { - // 模板文件如果有更新则缓存需要更新 - return false; - } - } - } - // 检查编译存储是否有效 - return $this->storage->check($cacheFile, $this->config['cache_time']); + // 未开启缓存功能 + if (!$this->config['tpl_cache']) { + return false; + } + // 缓存文件不存在 + if (!is_file($cacheFile)) { + return false; + } + // 读取缓存文件失败 + if (!$handle = @fopen($cacheFile, "r")) { + return false; + } + // 读取第一行 + preg_match('/\/\*(.+?)\*\//', fgets($handle), $matches); + if (!isset($matches[1])) { + return false; + } + $includeFile = unserialize($matches[1]); + if (!is_array($includeFile)) { + return false; + } + // 检查模板文件是否有更新 + foreach ($includeFile as $path => $time) { + if (is_file($path) && filemtime($path) > $time) { + // 模板文件如果有更新则缓存需要更新 + return false; } } - return false; + // 检查编译存储是否有效 + return $this->storage->check($cacheFile, $this->config['cache_time']); } /** From f90298fe76285a542d2a20426e9dc716cacc2a3d Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 16 Mar 2016 13:37:20 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/thinkphp/library/think/viewTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/thinkphp/library/think/viewTest.php b/tests/thinkphp/library/think/viewTest.php index 44b101a4..4c956566 100644 --- a/tests/thinkphp/library/think/viewTest.php +++ b/tests/thinkphp/library/think/viewTest.php @@ -121,13 +121,14 @@ class viewTest extends \PHPUnit_Framework_TestCase public function testParseTemplate() { $view_instance = \think\View::instance(); + $view_instance->theme('theme'); $view_instance->config(['view_path' => __DIR__ . DS . 'view' . DS]); $method = new \ReflectionMethod('\think\View', 'ParseTemplate'); $method->setAccessible(true); if (defined('CONTROLLER_NAME')) { - $expect_data = __DIR__ . DS . 'view' . DS . 'theme_name' . DS . CONTROLLER_NAME . DS . 'template.html'; + $expect_data = __DIR__ . DS . 'view' . DS . 'theme' . DS . CONTROLLER_NAME . DS . 'template.html'; } else { - $expect_data = __DIR__ . DS . 'view' . DS . 'theme_name' . DS . 'template.html'; + $expect_data = __DIR__ . DS . 'view' . DS . 'theme' . DS . 'template.html'; } $this->assertEquals($expect_data, $method->invoke($view_instance, 'template')); } From 81177066f15bcfb2858cbf1d947a872f7453de0a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 16 Mar 2016 14:15:23 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3template=E7=B1=BB?= =?UTF-8?q?=E7=9A=84=E6=A8=A1=E6=9D=BF=E8=A7=A3=E6=9E=90=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Template.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/library/think/Template.php b/library/think/Template.php index 65be4ba9..f70ae3f8 100644 --- a/library/think/Template.php +++ b/library/think/Template.php @@ -726,31 +726,31 @@ class Template } elseif (')' == substr($name, -1, 1)) { // $name为对象或是自动识别,或者含有函数 switch ($first) { - case '?': + case '?': $str = ''; break; - case '=': + case '=': $str = ''; break; - default: + default: $str = ''; } } else { // $name为数组 switch ($first) { - case '?': + case '?': // {$varname??'xxx'} $varname有定义则输出$varname,否则输出xxx $str = ''; break; - case '=': + case '=': // {$varname?='xxx'} $varname为真时才输出xxx $str = ''; break; - case ':': + case ':': // {$varname?:'xxx'} $varname为真时输出$varname,否则输出xxx $str = ''; break; - default: + default: if (strpos($str, ':')) { // {$varname ? 'a' : 'b'} $varname为真时输出a,否则输出b $str = ''; @@ -828,13 +828,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) . ')'; } } @@ -880,14 +880,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], '###')) { @@ -1029,7 +1029,7 @@ class Template */ private function parseTemplateFile($template) { - if (false === strpos($template, $this->config['view_suffix'])) { + if (false === strpos($template, '.')) { if (strpos($template, '@')) { // 跨模块调用模板 $template = str_replace(['/', ':'], $this->config['view_depr'], $template);