From 2d488afbb9167189eaa65e3d196347f35b232d42 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 16 Sep 2023 22:33:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=95=E7=8B=AC=E4=BD=BF?= =?UTF-8?q?=E7=94=A8orm=E7=9A=84=E6=97=B6=E5=80=99=20=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E7=9A=84=E5=86=85=E5=AD=98=E6=BA=A2=E5=87=BA=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20setLog=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81=E4=BC=A0=E5=85=A5?= =?UTF-8?q?=E9=97=AD=E5=8C=85=E5=AF=B9=E6=97=A5=E5=BF=97=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=A4=84=E7=90=86=20=E5=BA=9F=E5=BC=83getDbLog=E3=80=81updateQ?= =?UTF-8?q?ueryTime=E3=80=81clearQueryTime=E5=8F=8AgetQueryTimes=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DbManager.php | 38 ++++++++++++++------------------------ src/Model.php | 2 +- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/DbManager.php b/src/DbManager.php index 416e1c8e..9e08e69f 100644 --- a/src/DbManager.php +++ b/src/DbManager.php @@ -9,10 +9,11 @@ // +---------------------------------------------------------------------- // | Author: liu21st // +---------------------------------------------------------------------- -declare(strict_types=1); +declare (strict_types = 1); namespace think; +use Closure; use InvalidArgumentException; use Psr\Log\LoggerInterface; use Psr\SimpleCache\CacheInterface; @@ -57,13 +58,6 @@ class DbManager */ protected $listen = []; - /** - * SQL日志. - * - * @var array - */ - protected $dbLog = []; - /** * 查询次数. * @@ -159,11 +153,11 @@ public function setCache(CacheInterface $cache): void /** * 设置日志对象 * - * @param LoggerInterface $log 日志对象 + * @param LoggerInterface|Closure $log 日志对象 * * @return void */ - public function setLog(LoggerInterface $log): void + public function setLog(LoggerInterface | Closure $log): void { $this->log = $log; } @@ -179,27 +173,24 @@ public function setLog(LoggerInterface $log): void public function log(string $log, string $type = 'sql') { if ($this->log) { - $this->log->log($type, $log); - } else { - $this->dbLog[$type][] = $log; + if ($this->log instanceof Closure) { + call_user_func_array($this->log, [$type, $log]); + } else { + $this->log->log($type, $log); + } } } /** * 获得查询日志(没有设置日志对象使用). * + * @deprecated * @param bool $clear 是否清空 - * * @return array */ public function getDbLog(bool $clear = false): array { - $logs = $this->dbLog; - if ($clear) { - $this->dbLog = []; - } - - return $logs; + return []; } /** @@ -314,17 +305,16 @@ public function raw(string $value): Raw /** * 更新查询次数. - * + * @deprecated * @return void */ public function updateQueryTimes(): void { - $this->queryTimes++; } /** * 重置查询次数. - * + * @deprecated * @return void */ public function clearQueryTimes(): void @@ -334,7 +324,7 @@ public function clearQueryTimes(): void /** * 获得查询次数. - * + * @deprecated * @return int */ public function getQueryTimes(): int diff --git a/src/Model.php b/src/Model.php index 714b341b..bee01840 100644 --- a/src/Model.php +++ b/src/Model.php @@ -331,7 +331,7 @@ protected function setUpdateWhere($where): void * 设置当前模型的数据库连接. * * @param string $connection 数据表连接标识 - * + * * @return $this */ public function setConnection(string $connection)