diff --git a/README.md b/README.md index 4e52def..fcd7b0e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # think-view -ThinkPHP6.0 Think-Template模板引擎驱动 +ThinkPHP8.0 Think-Template模板引擎驱动 ## 安装 @@ -11,7 +11,7 @@ composer require topthink/think-view ## 用法示例 -本扩展不能单独使用,依赖ThinkPHP6.0+ +本扩展不能单独使用,依赖ThinkPHP8.0+ 首先配置config目录下的template.php配置文件,然后可以按照下面的用法使用。 diff --git a/composer.json b/composer.json index f4e6431..d9bcca7 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Think.php b/src/Think.php index 562b54a..105b070 100644 --- a/src/Think.php +++ b/src/Think.php @@ -21,7 +21,6 @@ class Think { // 模板引擎实例 private $template; - private $app; // 模板引擎参数 protected $config = [ @@ -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'])) { @@ -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) {