ComposerUpdate

This commit is contained in:
邹景立 2021-02-25 10:42:17 +08:00
parent 26fa3b6da0
commit 4e8d63c811
16 changed files with 270 additions and 196 deletions

View File

@ -454,7 +454,7 @@ return array(
'think\\facade\\Db' => $vendorDir . '/topthink/think-orm/src/facade/Db.php',
'think\\facade\\Env' => $vendorDir . '/topthink/framework/src/think/facade/Env.php',
'think\\facade\\Event' => $vendorDir . '/topthink/framework/src/think/facade/Event.php',
'think\\facade\\Facade' => $vendorDir . '/topthink/think-orm/src/facade/Db.php',
'think\\facade\\Facade' => $vendorDir . '/topthink/think-template/src/facade/Template.php',
'think\\facade\\Filesystem' => $vendorDir . '/topthink/framework/src/think/facade/Filesystem.php',
'think\\facade\\Lang' => $vendorDir . '/topthink/framework/src/think/facade/Lang.php',
'think\\facade\\Log' => $vendorDir . '/topthink/framework/src/think/facade/Log.php',

View File

@ -7,5 +7,6 @@ $baseDir = dirname($vendorDir);
return array(
'9b552a3cc426e3287cc811caefa3cf53' => $vendorDir . '/topthink/think-helper/src/helper.php',
'35fab96057f1bf5e7aba31a8a6d5fdde' => $vendorDir . '/topthink/think-orm/stubs/load_stubs.php',
'8dafcc6956460bc297e00381fed53e11' => $vendorDir . '/zoujingli/think-library/src/common.php',
);

View File

@ -8,6 +8,7 @@ class ComposerStaticInit4f89fd0e0503ccf740f2fa5757825d7b
{
public static $files = array (
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
'35fab96057f1bf5e7aba31a8a6d5fdde' => __DIR__ . '/..' . '/topthink/think-orm/stubs/load_stubs.php',
'8dafcc6956460bc297e00381fed53e11' => __DIR__ . '/..' . '/zoujingli/think-library/src/common.php',
);
@ -577,7 +578,7 @@ class ComposerStaticInit4f89fd0e0503ccf740f2fa5757825d7b
'think\\facade\\Db' => __DIR__ . '/..' . '/topthink/think-orm/src/facade/Db.php',
'think\\facade\\Env' => __DIR__ . '/..' . '/topthink/framework/src/think/facade/Env.php',
'think\\facade\\Event' => __DIR__ . '/..' . '/topthink/framework/src/think/facade/Event.php',
'think\\facade\\Facade' => __DIR__ . '/..' . '/topthink/think-orm/src/facade/Db.php',
'think\\facade\\Facade' => __DIR__ . '/..' . '/topthink/think-template/src/facade/Template.php',
'think\\facade\\Filesystem' => __DIR__ . '/..' . '/topthink/framework/src/think/facade/Filesystem.php',
'think\\facade\\Lang' => __DIR__ . '/..' . '/topthink/framework/src/think/facade/Lang.php',
'think\\facade\\Log' => __DIR__ . '/..' . '/topthink/framework/src/think/facade/Log.php',

View File

@ -656,17 +656,17 @@
},
{
"name": "topthink/think-orm",
"version": "v2.0.37",
"version_normalized": "2.0.37.0",
"version": "v2.0.38",
"version_normalized": "2.0.38.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-orm.git",
"reference": "8a2225c3533f5ccae4a77d4988ed4c5523284871"
"reference": "48e01bd25fdd51afee95343a4381fabc5a9cb764"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/8a2225c3533f5ccae4a77d4988ed4c5523284871",
"reference": "8a2225c3533f5ccae4a77d4988ed4c5523284871",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/48e01bd25fdd51afee95343a4381fabc5a9cb764",
"reference": "48e01bd25fdd51afee95343a4381fabc5a9cb764",
"shasum": "",
"mirrors": [
{
@ -677,6 +677,7 @@
},
"require": {
"ext-json": "*",
"ext-pdo": "*",
"php": ">=7.1.0",
"psr/log": "~1.0",
"psr/simple-cache": "^1.0",
@ -685,14 +686,16 @@
"require-dev": {
"phpunit/phpunit": "^7|^8|^9.5"
},
"time": "2021-02-18T02:01:00+00:00",
"time": "2021-02-24T00:54:36+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"think\\": "src"
},
"files": []
"files": [
"stubs/load_stubs.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
@ -860,7 +863,7 @@
"source": {
"type": "git",
"url": "https://gitee.com/zoujingli/ThinkLibrary",
"reference": "1f6500135bacf0b7ef7dcaa1115494e73ab92b90"
"reference": "41fdf9bfc855798bf9bec0384c2c97248ec6e23a"
},
"require": {
"ext-curl": "*",
@ -870,7 +873,7 @@
"ext-mbstring": "*",
"topthink/framework": "^6.0"
},
"time": "2021-02-22T10:20:05+00:00",
"time": "2021-02-23T07:09:05+00:00",
"type": "library",
"extra": {
"think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php
// This file is automatically generated at:2021-02-23 15:11:03
// This file is automatically generated at:2021-02-25 10:41:43
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',

View File

@ -15,6 +15,7 @@
"require": {
"php": ">=7.1.0",
"ext-json": "*",
"ext-pdo": "*",
"psr/simple-cache": "^1.0",
"psr/log": "~1.0",
"topthink/think-helper":"^3.1"
@ -26,7 +27,9 @@
"psr-4": {
"think\\": "src"
},
"files": []
"files": [
"stubs/load_stubs.php"
]
},
"autoload-dev": {
"psr-4": {

View File

@ -456,6 +456,9 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
if ($this->exists) {
$this->data = $this->db()->find($this->getKey())->getData();
$this->origin = $this->data;
$this->get = [];
$this->set = [];
$this->readDataType();
if ($relation) {
$this->relation = [];

View File

@ -18,9 +18,14 @@ use PDOStatement;
use think\db\exception\BindParamException;
use think\db\exception\DbException;
use think\db\exception\PDOException;
use think\Model;
/**
* 数据库连接基础类
* @property PDO[] $links
* @property PDO $linkID
* @property PDO $linkRead
* @property PDO $linkWrite
*/
abstract class PDOConnection extends Connection
{
@ -169,6 +174,26 @@ abstract class PDOConnection extends Connection
'Error writing data to the connection',
'Resource deadlock avoided',
'failed with errno',
'child connection forced to terminate due to client_idle_limit',
'query_wait_timeout',
'reset by peer',
'Physical connection is not usable',
'TCP Provider: Error code 0x68',
'ORA-03114',
'Packets out of order. Expected',
'Adaptive Server connection failed',
'Communication link failure',
'connection is no longer usable',
'Login timeout expired',
'SQLSTATE[HY000] [2002] Connection refused',
'running with the --read-only option so it cannot execute this statement',
'The connection is broken and recovery is not possible. The connection is marked by the client driver as unrecoverable. No attempt was made to restore the connection.',
'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again',
'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known',
'SQLSTATE[HY000]: General error: 7 SSL SYSCALL error: EOF detected',
'SQLSTATE[HY000] [2002] Connection timed out',
'SSL: Connection timed out',
'SQLSTATE[HY000]: General error: 1105 The last transaction was aborted due to Seamless Scaling. Please retry.',
];
/**
@ -580,7 +605,7 @@ abstract class PDOConnection extends Connection
/**
* 获取PDO对象
* @access public
* @return \PDO|false
* @return PDO|false
*/
public function getPdo()
{
@ -594,12 +619,13 @@ abstract class PDOConnection extends Connection
/**
* 执行查询 使用生成器返回数据
* @access public
* @param BaseQuery $query 查询对象
* @param string $sql sql指令
* @param array $bind 参数绑定
* @param \think\Model $model 模型对象实例
* @param array $condition 查询条件
* @param BaseQuery $query 查询对象
* @param string $sql sql指令
* @param array $bind 参数绑定
* @param Model|null $model 模型对象实例
* @param null $condition 查询条件
* @return \Generator
* @throws DbException
*/
public function getCursor(BaseQuery $query, string $sql, array $bind = [], $model = null, $condition = null)
{
@ -618,12 +644,11 @@ abstract class PDOConnection extends Connection
/**
* 执行查询 返回数据集
* @access public
* @param string $sql sql指令
* @param array $bind 参数绑定
* @param string $sql sql指令
* @param array $bind 参数绑定
* @param bool $master 主库读取
* @return array
* @throws BindParamException
* @throws \PDOException
* @throws DbException
*/
public function query(string $sql, array $bind = [], bool $master = false): array
{
@ -636,8 +661,7 @@ abstract class PDOConnection extends Connection
* @param string $sql sql指令
* @param array $bind 参数绑定
* @return int
* @throws BindParamException
* @throws \PDOException
* @throws DbException
*/
public function execute(string $sql, array $bind = []): int
{
@ -647,15 +671,12 @@ abstract class PDOConnection extends Connection
/**
* 执行查询 返回数据集
* @access protected
* @param BaseQuery $query 查询对象
* @param mixed $sql sql指令
* @param array $bind 参数绑定
* @param BaseQuery $query 查询对象
* @param mixed $sql sql指令
* @param array $bind 参数绑定
* @param bool $master 主库读取
* @return array
* @throws BindParamException
* @throws \PDOException
* @throws \Exception
* @throws \Throwable
* @throws DbException
*/
protected function pdoQuery(BaseQuery $query, $sql, array $bind = [], bool $master = null): array
{
@ -703,6 +724,7 @@ abstract class PDOConnection extends Connection
* @access public
* @param BaseQuery $query 查询对象
* @return \PDOStatement
* @throws DbException
*/
public function pdo(BaseQuery $query): PDOStatement
{
@ -721,10 +743,7 @@ abstract class PDOConnection extends Connection
* @param bool $master 是否在主服务器读操作
* @param bool $procedure 是否为存储过程调用
* @return PDOStatement
* @throws BindParamException
* @throws \PDOException
* @throws \Exception
* @throws \Throwable
* @throws DbException
*/
public function getPDOStatement(string $sql, array $bind = [], bool $master = false, bool $procedure = false): PDOStatement
{
@ -759,9 +778,17 @@ abstract class PDOConnection extends Connection
return $this->PDOStatement;
} catch (\Throwable | \Exception $e) {
if ($this->reConnectTimes < 4 && $this->isBreak($e)) {
++$this->reConnectTimes;
return $this->close()->getPDOStatement($sql, $bind, $master, $procedure);
if ($this->transTimes > 0) {
// 事务活动中时不应该进行重试,应直接中断执行,防止造成污染。
if ($this->isBreak($e)) {
// 尝试对事务计数进行重置
$this->transTimes = 0;
}
} else {
if ($this->reConnectTimes < 4 && $this->isBreak($e)) {
++$this->reConnectTimes;
return $this->close()->getPDOStatement($sql, $bind, $master, $procedure);
}
}
if ($e instanceof \PDOException) {
@ -780,10 +807,7 @@ abstract class PDOConnection extends Connection
* @param array $bind 参数绑定
* @param bool $origin 是否原生查询
* @return int
* @throws BindParamException
* @throws \PDOException
* @throws \Exception
* @throws \Throwable
* @throws DbException
*/
protected function pdoExecute(BaseQuery $query, string $sql, array $bind = [], bool $origin = false): int
{
@ -815,6 +839,13 @@ abstract class PDOConnection extends Connection
return $this->numRows;
}
/**
* @param BaseQuery $query
* @param string $sql
* @param array $bind
* @return PDOStatement
* @throws DbException
*/
protected function queryPDOStatement(BaseQuery $query, string $sql, array $bind = []): PDOStatement
{
$options = $query->getOptions();
@ -1416,12 +1447,16 @@ abstract class PDOConnection extends Connection
);
}
$this->reConnectTimes = 0;
} catch (\Exception $e) {
if ($this->reConnectTimes < 4 && $this->isBreak($e)) {
} catch (\Throwable | \Exception $e) {
if ($this->transTimes === 1 && $this->reConnectTimes < 4 && $this->isBreak($e)) {
--$this->transTimes;
++$this->reConnectTimes;
$this->close()->startTrans();
} else {
if ($this->isBreak($e)) {
// 尝试对事务计数进行重置
$this->transTimes = 0;
}
throw $e;
}
}
@ -1431,7 +1466,7 @@ abstract class PDOConnection extends Connection
* 用于非自动提交状态下面的查询提交
* @access public
* @return void
* @throws PDOException
* @throws \PDOException
*/
public function commit(): void
{
@ -1448,7 +1483,7 @@ abstract class PDOConnection extends Connection
* 事务回滚
* @access public
* @return void
* @throws PDOException
* @throws \PDOException
*/
public function rollback(): void
{
@ -1535,6 +1570,7 @@ abstract class PDOConnection extends Connection
$this->linkWrite = null;
$this->linkRead = null;
$this->links = [];
$this->transTimes = 0;
$this->free();

View File

@ -34,6 +34,9 @@ use function is_array;
/**
* Mongo数据库驱动
* @property Manager[] $links
* @property Manager $linkRead
* @property Manager $linkWrite
*/
class Mongo extends Connection
{

View File

@ -12,99 +12,33 @@ declare (strict_types = 1);
namespace think\db\exception;
use Exception;
use think\Exception;
/**
* Database相关异常处理类
*/
if (class_exists('think\Exception')) {
class DbException extends \think\Exception
class DbException extends Exception
{
/**
* DbException constructor.
* @access public
* @param string $message
* @param array $config
* @param string $sql
* @param int $code
*/
public function __construct(string $message, array $config = [], string $sql = '', int $code = 10500)
{
/**
* DbException constructor.
* @access public
* @param string $message
* @param array $config
* @param string $sql
* @param int $code
*/
public function __construct(string $message, array $config = [], string $sql = '', int $code = 10500)
{
$this->message = $message;
$this->code = $code;
$this->message = $message;
$this->code = $code;
$this->setData('Database Status', [
'Error Code' => $code,
'Error Message' => $message,
'Error SQL' => $sql,
]);
$this->setData('Database Status', [
'Error Code' => $code,
'Error Message' => $message,
'Error SQL' => $sql,
]);
unset($config['username'], $config['password']);
$this->setData('Database Config', $config);
}
}
} else {
class DbException extends Exception
{
/**
* DbException constructor.
* @access public
* @param string $message
* @param array $config
* @param string $sql
* @param int $code
*/
public function __construct(string $message, array $config = [], string $sql = '', int $code = 10500)
{
$this->message = $message;
$this->code = $code;
$this->setData('Database Status', [
'Error Code' => $code,
'Error Message' => $message,
'Error SQL' => $sql,
]);
unset($config['username'], $config['password']);
$this->setData('Database Config', $config);
}
/**
* 保存异常页面显示的额外Debug数据
* @var array
*/
protected $data = [];
/**
* 设置异常额外的Debug数据
* 数据将会显示为下面的格式
*
* Exception Data
* --------------------------------------------------
* Label 1
* key1 value1
* key2 value2
* Label 2
* key1 value1
* key2 value2
*
* @param string $label 数据分类,用于异常页面显示
* @param array $data 需要显示的数据,必须为关联数组
*/
final protected function setData($label, array $data)
{
$this->data[$label] = $data;
}
/**
* 获取异常额外Debug数据
* 主要用于输出到异常页面便于调试
* @return array 由setData设置的Debug数据
*/
final public function getData()
{
return $this->data;
}
unset($config['username'], $config['password']);
$this->setData('Database Config', $config);
}
}

View File

@ -11,62 +11,7 @@
namespace think\facade;
if (class_exists('think\Facade')) {
class Facade extends \think\Facade
{}
} else {
class Facade
{
/**
* 始终创建新的对象实例
* @var bool
*/
protected static $alwaysNewInstance;
protected static $instance;
/**
* 获取当前Facade对应类名
* @access protected
* @return string
*/
protected static function getFacadeClass()
{}
/**
* 创建Facade实例
* @static
* @access protected
* @param bool $newInstance 是否每次创建新的实例
* @return object
*/
protected static function createFacade(bool $newInstance = false)
{
$class = static::getFacadeClass() ?: 'think\DbManager';
if (static::$alwaysNewInstance) {
$newInstance = true;
}
if ($newInstance) {
return new $class();
}
if (!self::$instance) {
self::$instance = new $class();
}
return self::$instance;
}
// 调用实际类的方法
public static function __callStatic($method, $params)
{
return call_user_func_array([static::createFacade(), $method], $params);
}
}
}
use think\Facade;
/**
* @see \think\DbManager

View File

@ -94,6 +94,12 @@ trait Attribute
*/
protected $strict = true;
/**
* 获取器数据
* @var array
*/
private $get = [];
/**
* 修改器执行记录
* @var array
@ -266,7 +272,7 @@ trait Attribute
}
/**
* 获取对象原始数据 如果不存在指定字段返回false
* 获取当前对象数据 如果不存在指定字段返回false
* @access public
* @param string $name 字段名 留空获取全部
* @return mixed
@ -479,8 +485,12 @@ trait Attribute
{
// 检测属性获取器
$fieldName = $this->getRealFieldName($name);
$method = 'get' . Str::studly($name) . 'Attr';
if (array_key_exists($fieldName, $this->get)) {
return $this->get[$fieldName];
}
$method = 'get' . Str::studly($name) . 'Attr';
if (isset($this->withAttr[$fieldName])) {
if ($relation) {
$value = $this->getRelationValue($relation);
@ -504,6 +514,8 @@ trait Attribute
$this->relation[$name] = $value;
}
$this->get[$fieldName] = $value;
return $value;
}
@ -516,9 +528,9 @@ trait Attribute
{
foreach ($this->data as $key => $value) {
if (isset($this->type[$key])) {
$this->data[$key] = $this->readTransform($value, $this->type[$key]);
$this->get[$key] = $this->readTransform($value, $this->type[$key]);
} elseif ($this->autoWriteTimestamp && in_array($key, [$this->createTime, $this->updateTime])) {
$this->data[$key] = $this->getTimestampValue($value);
$this->get[$key] = $this->getTimestampValue($value);
}
}
}

View File

@ -0,0 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace think;
/**
* 异常基础类
* @package think
*/
class Exception extends \Exception
{
/**
* 保存异常页面显示的额外Debug数据
* @var array
*/
protected $data = [];
/**
* 设置异常额外的Debug数据
* 数据将会显示为下面的格式
*
* Exception Data
* --------------------------------------------------
* Label 1
* key1 value1
* key2 value2
* Label 2
* key1 value1
* key2 value2
*
* @access protected
* @param string $label 数据分类,用于异常页面显示
* @param array $data 需要显示的数据,必须为关联数组
*/
final protected function setData(string $label, array $data)
{
$this->data[$label] = $data;
}
/**
* 获取异常额外Debug数据
* 主要用于输出到异常页面便于调试
* @access public
* @return array 由setData设置的Debug数据
*/
final public function getData()
{
return $this->data;
}
}

View File

@ -0,0 +1,65 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace think;
class Facade
{
/**
* 始终创建新的对象实例
* @var bool
*/
protected static $alwaysNewInstance;
protected static $instance;
/**
* 获取当前Facade对应类名
* @access protected
* @return string
*/
protected static function getFacadeClass()
{}
/**
* 创建Facade实例
* @static
* @access protected
* @param bool $newInstance 是否每次创建新的实例
* @return object
*/
protected static function createFacade(bool $newInstance = false)
{
$class = static::getFacadeClass() ?: 'think\DbManager';
if (static::$alwaysNewInstance) {
$newInstance = true;
}
if ($newInstance) {
return new $class();
}
if (!self::$instance) {
self::$instance = new $class();
}
return self::$instance;
}
// 调用实际类的方法
public static function __callStatic($method, $params)
{
return call_user_func_array([static::createFacade(), $method], $params);
}
}

View File

@ -0,0 +1,9 @@
<?php
if (!\class_exists('think\Exception')) {
require __DIR__ . '/Exception.php';
}
if (!\class_exists('think\Facade')) {
require __DIR__ . '/Facade.php';
}

View File

@ -100,8 +100,8 @@ class Library extends Service
if (($origin = $request->header('origin', '*')) !== '*') {
$header['Access-Control-Allow-Origin'] = $origin;
$header['Access-Control-Allow-Methods'] = 'GET,PUT,POST,PATCH,DELETE';
$header['Access-Control-Allow-Headers'] = 'Authorization,Content-Type,If-Match,If-Modified-Since,If-None-Match,If-Unmodified-Since,X-Requested-With,Api-Type,Api-Token,User-Form-Token,User-Token,Token';
$header['Access-Control-Expose-Headers'] = 'Api-Type,Api-Token,User-Form-Token,User-Token,Token';
$header['Access-Control-Allow-Headers'] = 'Authorization,Content-Type,If-Match,If-Modified-Since,If-None-Match,If-Unmodified-Since,X-Requested-With,Api-Name,Api-Type,Api-Token,User-Form-Token,User-Token,Token';
$header['Access-Control-Expose-Headers'] = 'Api-Name,Api-Type,Api-Token,User-Form-Token,User-Token,Token';
$header['Access-Control-Allow-Credentials'] = 'true';
}
// 访问模式及访问权限检查