From e505c13843bb5fa77e05251f9e0ca0f948dc303a Mon Sep 17 00:00:00 2001 From: topnuomi <1130395124@qq.com> Date: Thu, 18 Jul 2024 17:09:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF=E5=BC=95?= =?UTF-8?q?=E6=93=8E=E9=85=8D=E7=BD=AE=E5=90=8D=E7=A7=B0=E3=80=81README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 31 +++++++++++++------------------ framework/config/config.php | 2 +- framework/library/View.php | 20 ++++++++++++++++---- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4309358..f559999 100644 --- a/README.md +++ b/README.md @@ -452,7 +452,7 @@ return [ ``` 'view' => [ - 'engine' => 'Top', + 'driver' => 'Top', ], ``` @@ -872,34 +872,29 @@ $cache->remove('lists'); $cache->exists('lists'); ``` -### File -1. 使用判断设置缓存 +### 使用缓存 ``` -use top\library\cache\driver\File; +use top\library\Cache; -$cache = File::instance(); +$cache = Cache::instance(); if (!$cache->exists('text')) { $text = '测试'; $cache->set('text', $text); } $data = $cache->get('text'); ``` -2. get方法 + +### 缓存配置 +可在config.php配置文件中使用的配置 ``` -use top\library\cache\driver\File; - -$cache = File::instance(); -$data = $cache->get('text', function ($cache) { - $cache->set('text', $text = '测试'); - return $text; -}); +'cache' => [ + 'driver' => 'file', // 缓存驱动,默认为file,可选 file|redis + 'path' => './runtime/cache/', // 缓存文件存放路径,file驱动有效 +], ``` -### Redis -使用方式同File缓存 - -### 自定义缓存实现 -文件存放位置 'framework/library/cache/driver' 。必须实现CacheIfs接口,具体方法看缓存介绍。 +### 缓存实现 +缓存文件存放位置 'framework/library/cache' 。必须实现CacheIfs接口,具体方法看缓存介绍。 ## 路由 可在config.php配置文件中使用的配置 diff --git a/framework/config/config.php b/framework/config/config.php index dd3dd7e..581cb0f 100644 --- a/framework/config/config.php +++ b/framework/config/config.php @@ -37,7 +37,7 @@ return [ 'auth' => '', ], 'view' => [ - 'engine' => 'Top', + 'driver' => 'Top', 'tagLib' => [], 'ext' => 'html', 'path' => APP_PATH . CURRENT_MODULE . '/view/', diff --git a/framework/library/View.php b/framework/library/View.php index 1f0ea62..3823ec4 100644 --- a/framework/library/View.php +++ b/framework/library/View.php @@ -2,6 +2,9 @@ namespace top\library; +use top\library\template\driver\Smarty; +use top\library\template\driver\Top; +use top\library\template\driver\Twig; use top\traits\Instance; /** @@ -26,11 +29,20 @@ class View private function __construct() { $this->config = config('view'); - $className = '\\top\\library\\template\\driver\\' . $this->config['engine']; - if (!class_exists($className)) { - throw new \Exception('不存在的模板引擎:' . $className); + $driver = strtolower($this->config['driver']); + switch ($driver) { + case 'top': + $this->template = Template::instance(Top::instance()); + break; + case 'smarty': + $this->template = Template::instance(Smarty::instance()); + break; + case 'twig': + $this->template = Template::instance(Twig::instance()); + break; + default: + throw new \Exception('不存在的模板引擎:' . $driver); } - $this->template = Template::instance($className::instance()); } /**