Skip to content

Commit d2a0760

Browse files
committed
更新版本依赖
1 parent edce0ae commit d2a0760

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# think-view
22

3-
ThinkPHP6.0 Think-Template模板引擎驱动
3+
ThinkPHP8.0 Think-Template模板引擎驱动
44

55

66
## 安装
@@ -11,7 +11,7 @@ composer require topthink/think-view
1111

1212
## 用法示例
1313

14-
本扩展不能单独使用,依赖ThinkPHP6.0+
14+
本扩展不能单独使用,依赖ThinkPHP8.0+
1515

1616
首先配置config目录下的template.php配置文件,然后可以按照下面的用法使用。
1717

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
}
1010
],
1111
"require": {
12-
"php": ">=7.1.0",
13-
"topthink/think-template": "^2.0"
12+
"php": ">=8.0.0",
13+
"topthink/think-template": "^3.0"
1414
},
1515
"autoload": {
1616
"psr-4": {

src/Think.php

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class Think
2121
{
2222
// 模板引擎实例
2323
private $template;
24-
private $app;
2524

2625
// 模板引擎参数
2726
protected $config = [
@@ -39,10 +38,8 @@ class Think
3938
'tpl_cache' => true,
4039
];
4140

42-
public function __construct(App $app, array $config = [])
41+
public function __construct(private App $app, array $config = [])
4342
{
44-
$this->app = $app;
45-
4643
$this->config = array_merge($this->config, (array) $config);
4744

4845
if (empty($this->config['cache_path'])) {
@@ -55,30 +52,15 @@ public function __construct(App $app, array $config = [])
5552
$type = strtoupper(trim(array_shift($vars)));
5653
$param = implode('.', $vars);
5754

58-
switch ($type) {
59-
case 'CONST':
60-
$parseStr = strtoupper($param);
61-
break;
62-
case 'CONFIG':
63-
$parseStr = 'config(\'' . $param . '\')';
64-
break;
65-
case 'LANG':
66-
$parseStr = 'lang(\'' . $param . '\')';
67-
break;
68-
case 'NOW':
69-
$parseStr = "date('Y-m-d g:i a',time())";
70-
break;
71-
case 'LDELIM':
72-
$parseStr = '\'' . ltrim($this->getConfig('tpl_begin'), '\\') . '\'';
73-
break;
74-
case 'RDELIM':
75-
$parseStr = '\'' . ltrim($this->getConfig('tpl_end'), '\\') . '\'';
76-
break;
77-
default:
78-
$parseStr = defined($type) ? $type : '\'\'';
79-
}
80-
81-
return $parseStr;
55+
return match ($type) {
56+
'CONST' => strtoupper($param),
57+
'CONFIG' => 'config(\'' . $param . '\')',
58+
'LANG' => 'lang(\'' . $param . '\')',
59+
'NOW' => "date('Y-m-d g:i a',time())",
60+
'LDELIM' => '\'' . ltrim($this->getConfig('tpl_begin'), '\\') . '\'',
61+
'RDELIM' => '\'' . ltrim($this->getConfig('tpl_end'), '\\') . '\'',
62+
default => defined($type) ? $type : '\'\'',
63+
};
8264
});
8365

8466
$this->template->extend('$Request', function (array $vars) {

0 commit comments

Comments
 (0)