Skip to content

Commit

Permalink
更新版本依赖
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Feb 25, 2023
1 parent edce0ae commit d2a0760
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# think-view

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


## 安装
Expand All @@ -11,7 +11,7 @@ composer require topthink/think-view

## 用法示例

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

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

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}
],
"require": {
"php": ">=7.1.0",
"topthink/think-template": "^2.0"
"php": ">=8.0.0",
"topthink/think-template": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
38 changes: 10 additions & 28 deletions src/Think.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class Think
{
// 模板引擎实例
private $template;
private $app;

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

public function __construct(App $app, array $config = [])
public function __construct(private App $app, array $config = [])
{
$this->app = $app;

$this->config = array_merge($this->config, (array) $config);

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

switch ($type) {
case 'CONST':
$parseStr = strtoupper($param);
break;
case 'CONFIG':
$parseStr = 'config(\'' . $param . '\')';
break;
case 'LANG':
$parseStr = 'lang(\'' . $param . '\')';
break;
case 'NOW':
$parseStr = "date('Y-m-d g:i a',time())";
break;
case 'LDELIM':
$parseStr = '\'' . ltrim($this->getConfig('tpl_begin'), '\\') . '\'';
break;
case 'RDELIM':
$parseStr = '\'' . ltrim($this->getConfig('tpl_end'), '\\') . '\'';
break;
default:
$parseStr = defined($type) ? $type : '\'\'';
}

return $parseStr;
return match ($type) {
'CONST' => strtoupper($param),
'CONFIG' => 'config(\'' . $param . '\')',
'LANG' => 'lang(\'' . $param . '\')',
'NOW' => "date('Y-m-d g:i a',time())",
'LDELIM' => '\'' . ltrim($this->getConfig('tpl_begin'), '\\') . '\'',
'RDELIM' => '\'' . ltrim($this->getConfig('tpl_end'), '\\') . '\'',
default => defined($type) ? $type : '\'\'',
};
});

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

0 comments on commit d2a0760

Please sign in to comment.