fix:修复BUG/升级1.1.6版本
This commit is contained in:
135
vendor/topthink/think-orm/src/DbManager.php
vendored
135
vendor/topthink/think-orm/src/DbManager.php
vendored
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// | Copyright (c) 2006~2023 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace think;
|
||||
|
||||
@@ -21,64 +22,71 @@ use think\db\Query;
|
||||
use think\db\Raw;
|
||||
|
||||
/**
|
||||
* Class DbManager
|
||||
* @package think
|
||||
* Class DbManager.
|
||||
*
|
||||
* @mixin BaseQuery
|
||||
* @mixin Query
|
||||
*/
|
||||
class DbManager
|
||||
{
|
||||
/**
|
||||
* 数据库连接实例
|
||||
* 数据库连接实例.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $instance = [];
|
||||
|
||||
/**
|
||||
* 数据库配置
|
||||
* 数据库配置.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $config = [];
|
||||
|
||||
/**
|
||||
* Event对象或者数组
|
||||
* Event对象或者数组.
|
||||
*
|
||||
* @var array|object
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
/**
|
||||
* SQL监听
|
||||
* SQL监听.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [];
|
||||
|
||||
/**
|
||||
* SQL日志
|
||||
* SQL日志.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dbLog = [];
|
||||
|
||||
/**
|
||||
* 查询次数
|
||||
* 查询次数.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $queryTimes = 0;
|
||||
|
||||
/**
|
||||
* 查询缓存对象
|
||||
*
|
||||
* @var CacheInterface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* 查询日志对象
|
||||
*
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
protected $log;
|
||||
|
||||
/**
|
||||
* 架构函数
|
||||
* @access public
|
||||
* 架构函数.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -87,7 +95,7 @@ class DbManager
|
||||
|
||||
/**
|
||||
* 注入模型对象
|
||||
* @access public
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function modelMaker()
|
||||
@@ -116,17 +124,19 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听SQL
|
||||
* @access protected
|
||||
* 监听SQL.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function triggerSql(): void
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化配置参数
|
||||
* @access public
|
||||
* 初始化配置参数.
|
||||
*
|
||||
* @param array $config 连接配置
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setConfig($config): void
|
||||
@@ -136,8 +146,9 @@ class DbManager
|
||||
|
||||
/**
|
||||
* 设置缓存对象
|
||||
* @access public
|
||||
*
|
||||
* @param CacheInterface $cache 缓存对象
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setCache(CacheInterface $cache): void
|
||||
@@ -147,8 +158,9 @@ class DbManager
|
||||
|
||||
/**
|
||||
* 设置日志对象
|
||||
* @access public
|
||||
*
|
||||
* @param LoggerInterface $log 日志对象
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setLog(LoggerInterface $log): void
|
||||
@@ -157,10 +169,11 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录SQL日志
|
||||
* @access protected
|
||||
* 记录SQL日志.
|
||||
*
|
||||
* @param string $log SQL日志信息
|
||||
* @param string $type 日志类型
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function log(string $log, string $type = 'sql')
|
||||
@@ -173,9 +186,10 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得查询日志(没有设置日志对象使用)
|
||||
* @access public
|
||||
* 获得查询日志(没有设置日志对象使用).
|
||||
*
|
||||
* @param bool $clear 是否清空
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDbLog(bool $clear = false): array
|
||||
@@ -189,10 +203,11 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取配置参数
|
||||
* @access public
|
||||
* 获取配置参数.
|
||||
*
|
||||
* @param string $name 配置参数
|
||||
* @param mixed $default 默认值
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getConfig(string $name = '', $default = null)
|
||||
@@ -205,10 +220,11 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建/切换数据库连接查询
|
||||
* @access public
|
||||
* 创建/切换数据库连接查询.
|
||||
*
|
||||
* @param string|null $name 连接配置标识
|
||||
* @param bool $force 强制重新连接
|
||||
*
|
||||
* @return ConnectionInterface
|
||||
*/
|
||||
public function connect(string $name = null, bool $force = false)
|
||||
@@ -217,10 +233,11 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建数据库连接实例
|
||||
* @access protected
|
||||
* 创建数据库连接实例.
|
||||
*
|
||||
* @param string|null $name 连接标识
|
||||
* @param bool $force 强制重新连接
|
||||
*
|
||||
* @return ConnectionInterface
|
||||
*/
|
||||
protected function instance(string $name = null, bool $force = false): ConnectionInterface
|
||||
@@ -237,8 +254,10 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取连接配置
|
||||
* 获取连接配置.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getConnectionConfig(string $name): array
|
||||
@@ -252,8 +271,10 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建连接
|
||||
* 创建连接.
|
||||
*
|
||||
* @param $name
|
||||
*
|
||||
* @return ConnectionInterface
|
||||
*/
|
||||
protected function createConnection(string $name): ConnectionInterface
|
||||
@@ -262,7 +283,7 @@ class DbManager
|
||||
|
||||
$type = !empty($config['type']) ? $config['type'] : 'mysql';
|
||||
|
||||
if (false !== strpos($type, '\\')) {
|
||||
if (str_contains($type, '\\')) {
|
||||
$class = $type;
|
||||
} else {
|
||||
$class = '\\think\\db\\connector\\' . ucfirst($type);
|
||||
@@ -280,9 +301,10 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用表达式设置数据
|
||||
* @access public
|
||||
* 使用表达式设置数据.
|
||||
*
|
||||
* @param string $value 表达式
|
||||
*
|
||||
* @return Raw
|
||||
*/
|
||||
public function raw(string $value): Raw
|
||||
@@ -291,8 +313,8 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新查询次数
|
||||
* @access public
|
||||
* 更新查询次数.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateQueryTimes(): void
|
||||
@@ -301,8 +323,8 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置查询次数
|
||||
* @access public
|
||||
* 重置查询次数.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearQueryTimes(): void
|
||||
@@ -311,9 +333,9 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得查询次数
|
||||
* @access public
|
||||
* @return integer
|
||||
* 获得查询次数.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getQueryTimes(): int
|
||||
{
|
||||
@@ -321,9 +343,10 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 监听SQL执行
|
||||
* @access public
|
||||
* 监听SQL执行.
|
||||
*
|
||||
* @param callable $callback 回调方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function listen(callable $callback): void
|
||||
@@ -332,8 +355,8 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监听SQL执行
|
||||
* @access public
|
||||
* 获取监听SQL执行.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getListen(): array
|
||||
@@ -342,10 +365,21 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册回调方法
|
||||
* @access public
|
||||
* 获取所有连接实列.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInstance(): array
|
||||
{
|
||||
return $this->instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册回调方法.
|
||||
*
|
||||
* @param string $event 事件名
|
||||
* @param callable $callback 回调方法
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function event(string $event, callable $callback): void
|
||||
@@ -354,10 +388,11 @@ class DbManager
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发事件
|
||||
* @access public
|
||||
* 触发事件.
|
||||
*
|
||||
* @param string $event 事件名
|
||||
* @param mixed $params 传入参数
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function trigger(string $event, $params = null)
|
||||
|
||||
Reference in New Issue
Block a user