提交 a83f52d8 编写于 作者: D Devil

框架更新

上级 17438dbd
...@@ -449,16 +449,16 @@ ...@@ -449,16 +449,16 @@
}, },
{ {
"name": "topthink/framework", "name": "topthink/framework",
"version": "v6.0.8", "version": "v6.0.9",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/framework.git", "url": "https://github.com/top-think/framework.git",
"reference": "4789343672aef06d571d556da369c0e156609bce" "reference": "0b5fb453f0e533de3af3a1ab6a202510b61be617"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/framework/zipball/4789343672aef06d571d556da369c0e156609bce", "url": "https://api.github.com/repos/top-think/framework/zipball/0b5fb453f0e533de3af3a1ab6a202510b61be617",
"reference": "4789343672aef06d571d556da369c0e156609bce", "reference": "0b5fb453f0e533de3af3a1ab6a202510b61be617",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
...@@ -470,9 +470,9 @@ ...@@ -470,9 +470,9 @@
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
"league/flysystem": "^1.0", "league/flysystem": "^1.1.4",
"league/flysystem-cached-adapter": "^1.0", "league/flysystem-cached-adapter": "^1.0",
"php": ">=7.1.0", "php": ">=7.2.5",
"psr/container": "~1.0", "psr/container": "~1.0",
"psr/log": "~1.0", "psr/log": "~1.0",
"psr/simple-cache": "^1.0", "psr/simple-cache": "^1.0",
...@@ -514,9 +514,9 @@ ...@@ -514,9 +514,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/top-think/framework/issues", "issues": "https://github.com/top-think/framework/issues",
"source": "https://github.com/top-think/framework/tree/v6.0.8" "source": "https://github.com/top-think/framework/tree/v6.0.9"
}, },
"time": "2021-04-27T00:41:08+00:00" "time": "2021-07-22T03:24:49+00:00"
}, },
{ {
"name": "topthink/think-helper", "name": "topthink/think-helper",
...@@ -623,16 +623,16 @@ ...@@ -623,16 +623,16 @@
}, },
{ {
"name": "topthink/think-orm", "name": "topthink/think-orm",
"version": "v2.0.41", "version": "v2.0.44",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/think-orm.git", "url": "https://github.com/top-think/think-orm.git",
"reference": "64bbfdde01f4fd6939c2f695fceb08e6d764ac6b" "reference": "5d3d5c1ebf8bfccf34bacd90edb42989b16ea409"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/64bbfdde01f4fd6939c2f695fceb08e6d764ac6b", "url": "https://api.github.com/repos/top-think/think-orm/zipball/5d3d5c1ebf8bfccf34bacd90edb42989b16ea409",
"reference": "64bbfdde01f4fd6939c2f695fceb08e6d764ac6b", "reference": "5d3d5c1ebf8bfccf34bacd90edb42989b16ea409",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
...@@ -678,9 +678,9 @@ ...@@ -678,9 +678,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/top-think/think-orm/issues", "issues": "https://github.com/top-think/think-orm/issues",
"source": "https://github.com/top-think/think-orm/tree/v2.0.41" "source": "https://github.com/top-think/think-orm/tree/v2.0.44"
}, },
"time": "2021-07-14T07:51:15+00:00" "time": "2021-07-21T02:22:31+00:00"
}, },
{ {
"name": "topthink/think-template", "name": "topthink/think-template",
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// 检测PHP环境 // 检测PHP环境
if(version_compare(PHP_VERSION,'7.1.0','<')) die('PHP版本最低 7.1.0'); if(version_compare(PHP_VERSION,'7.2.0','<')) die('PHP版本最低 7.2.0');
// 系统版本 // 系统版本
define('APPLICATION_VERSION', 'v2.2.0'); define('APPLICATION_VERSION', 'v2.2.0');
......
...@@ -9,7 +9,7 @@ return array( ...@@ -9,7 +9,7 @@ return array(
'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'), 'think\\view\\driver\\' => array($vendorDir . '/topthink/think-view/src'),
'think\\trace\\' => array($vendorDir . '/topthink/think-trace/src'), 'think\\trace\\' => array($vendorDir . '/topthink/think-trace/src'),
'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'), 'think\\app\\' => array($vendorDir . '/topthink/think-multi-app/src'),
'think\\' => array($vendorDir . '/topthink/framework/src/think', $vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/think-template/src'), 'think\\' => array($vendorDir . '/topthink/think-helper/src', $vendorDir . '/topthink/think-template/src', $vendorDir . '/topthink/think-orm/src', $vendorDir . '/topthink/framework/src/think'),
'app\\' => array($baseDir . '/app'), 'app\\' => array($baseDir . '/app'),
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'), 'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'), 'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'),
......
...@@ -64,10 +64,10 @@ class ComposerStaticInit1ed187777399b73a018d9a6af63a57d1 ...@@ -64,10 +64,10 @@ class ComposerStaticInit1ed187777399b73a018d9a6af63a57d1
), ),
'think\\' => 'think\\' =>
array ( array (
0 => __DIR__ . '/..' . '/topthink/framework/src/think', 0 => __DIR__ . '/..' . '/topthink/think-helper/src',
1 => __DIR__ . '/..' . '/topthink/think-helper/src', 1 => __DIR__ . '/..' . '/topthink/think-template/src',
2 => __DIR__ . '/..' . '/topthink/think-orm/src', 2 => __DIR__ . '/..' . '/topthink/think-orm/src',
3 => __DIR__ . '/..' . '/topthink/think-template/src', 3 => __DIR__ . '/..' . '/topthink/framework/src/think',
), ),
'app\\' => 'app\\' =>
array ( array (
......
...@@ -762,25 +762,31 @@ ...@@ -762,25 +762,31 @@
}, },
{ {
"name": "topthink/framework", "name": "topthink/framework",
"version": "v6.0.8", "version": "v6.0.9",
"version_normalized": "6.0.8.0", "version_normalized": "6.0.9.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/framework.git", "url": "https://github.com/top-think/framework.git",
"reference": "4789343672aef06d571d556da369c0e156609bce" "reference": "0b5fb453f0e533de3af3a1ab6a202510b61be617"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/framework/zipball/4789343672aef06d571d556da369c0e156609bce", "url": "https://api.github.com/repos/top-think/framework/zipball/0b5fb453f0e533de3af3a1ab6a202510b61be617",
"reference": "4789343672aef06d571d556da369c0e156609bce", "reference": "0b5fb453f0e533de3af3a1ab6a202510b61be617",
"shasum": "" "shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
}, },
"require": { "require": {
"ext-json": "*", "ext-json": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
"league/flysystem": "^1.0", "league/flysystem": "^1.1.4",
"league/flysystem-cached-adapter": "^1.0", "league/flysystem-cached-adapter": "^1.0",
"php": ">=7.1.0", "php": ">=7.2.5",
"psr/container": "~1.0", "psr/container": "~1.0",
"psr/log": "~1.0", "psr/log": "~1.0",
"psr/simple-cache": "^1.0", "psr/simple-cache": "^1.0",
...@@ -792,7 +798,7 @@ ...@@ -792,7 +798,7 @@
"mockery/mockery": "^1.2", "mockery/mockery": "^1.2",
"phpunit/phpunit": "^7.0" "phpunit/phpunit": "^7.0"
}, },
"time": "2021-04-27T00:41:08+00:00", "time": "2021-07-22T03:24:49+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
...@@ -824,7 +830,7 @@ ...@@ -824,7 +830,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/top-think/framework/issues", "issues": "https://github.com/top-think/framework/issues",
"source": "https://github.com/top-think/framework/tree/v6.0.8" "source": "https://github.com/top-think/framework/tree/v6.0.9"
}, },
"install-path": "../topthink/framework" "install-path": "../topthink/framework"
}, },
...@@ -927,17 +933,17 @@ ...@@ -927,17 +933,17 @@
}, },
{ {
"name": "topthink/think-orm", "name": "topthink/think-orm",
"version": "v2.0.41", "version": "v2.0.44",
"version_normalized": "2.0.41.0", "version_normalized": "2.0.44.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/think-orm.git", "url": "https://github.com/top-think/think-orm.git",
"reference": "64bbfdde01f4fd6939c2f695fceb08e6d764ac6b" "reference": "5d3d5c1ebf8bfccf34bacd90edb42989b16ea409"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/64bbfdde01f4fd6939c2f695fceb08e6d764ac6b", "url": "https://api.github.com/repos/top-think/think-orm/zipball/5d3d5c1ebf8bfccf34bacd90edb42989b16ea409",
"reference": "64bbfdde01f4fd6939c2f695fceb08e6d764ac6b", "reference": "5d3d5c1ebf8bfccf34bacd90edb42989b16ea409",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
...@@ -957,7 +963,7 @@ ...@@ -957,7 +963,7 @@
"require-dev": { "require-dev": {
"phpunit/phpunit": "^7|^8|^9.5" "phpunit/phpunit": "^7|^8|^9.5"
}, },
"time": "2021-07-14T07:51:15+00:00", "time": "2021-07-21T02:22:31+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
...@@ -985,7 +991,7 @@ ...@@ -985,7 +991,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/top-think/think-orm/issues", "issues": "https://github.com/top-think/think-orm/issues",
"source": "https://github.com/top-think/think-orm/tree/v2.0.41" "source": "https://github.com/top-think/think-orm/tree/v2.0.44"
}, },
"install-path": "../topthink/think-orm" "install-path": "../topthink/think-orm"
}, },
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '6c215fcba72e60dc4017bd65b0bc08b8b67c94d2', 'reference' => '17438dbd90d9945b175a1e428da20474e46aff80',
'name' => 'shopxo/shopxo', 'name' => 'shopxo/shopxo',
'dev' => true, 'dev' => true,
), ),
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
'type' => 'project', 'type' => 'project',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
'reference' => '6c215fcba72e60dc4017bd65b0bc08b8b67c94d2', 'reference' => '17438dbd90d9945b175a1e428da20474e46aff80',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'symfony/polyfill-mbstring' => array( 'symfony/polyfill-mbstring' => array(
...@@ -119,12 +119,12 @@ ...@@ -119,12 +119,12 @@
'dev_requirement' => true, 'dev_requirement' => true,
), ),
'topthink/framework' => array( 'topthink/framework' => array(
'pretty_version' => 'v6.0.8', 'pretty_version' => 'v6.0.9',
'version' => '6.0.8.0', 'version' => '6.0.9.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../topthink/framework', 'install_path' => __DIR__ . '/../topthink/framework',
'aliases' => array(), 'aliases' => array(),
'reference' => '4789343672aef06d571d556da369c0e156609bce', 'reference' => '0b5fb453f0e533de3af3a1ab6a202510b61be617',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'topthink/think-helper' => array( 'topthink/think-helper' => array(
...@@ -146,12 +146,12 @@ ...@@ -146,12 +146,12 @@
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'topthink/think-orm' => array( 'topthink/think-orm' => array(
'pretty_version' => 'v2.0.41', 'pretty_version' => 'v2.0.44',
'version' => '2.0.41.0', 'version' => '2.0.44.0',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../topthink/think-orm', 'install_path' => __DIR__ . '/../topthink/think-orm',
'aliases' => array(), 'aliases' => array(),
'reference' => '64bbfdde01f4fd6939c2f695fceb08e6d764ac6b', 'reference' => '5d3d5c1ebf8bfccf34bacd90edb42989b16ea409',
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'topthink/think-template' => array( 'topthink/think-template' => array(
......
<?php <?php
// This file is automatically generated at:2021-07-19 11:36:48 // This file is automatically generated at:2021-07-22 11:43:19
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\app\\Service', 0 => 'think\\app\\Service',
......
...@@ -4,9 +4,9 @@ language: php ...@@ -4,9 +4,9 @@ language: php
matrix: matrix:
fast_finish: true fast_finish: true
include: include:
- php: 7.1
- php: 7.2 - php: 7.2
- php: 7.3 - php: 7.3
- php: 8.0
cache: cache:
directories: directories:
......
...@@ -19,10 +19,10 @@ ...@@ -19,10 +19,10 @@
} }
], ],
"require": { "require": {
"php": ">=7.1.0", "php": ">=7.2.5",
"ext-json": "*", "ext-json": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
"league/flysystem": "^1.0", "league/flysystem": "^1.1.4",
"league/flysystem-cached-adapter": "^1.0", "league/flysystem-cached-adapter": "^1.0",
"psr/log": "~1.0", "psr/log": "~1.0",
"psr/container": "~1.0", "psr/container": "~1.0",
......
...@@ -39,7 +39,7 @@ use think\initializer\RegisterService; ...@@ -39,7 +39,7 @@ use think\initializer\RegisterService;
*/ */
class App extends Container class App extends Container
{ {
const VERSION = '6.0.8'; const VERSION = '6.0.9';
/** /**
* 应用调试模式 * 应用调试模式
......
...@@ -37,6 +37,7 @@ class Event ...@@ -37,6 +37,7 @@ class Event
'HttpEnd' => event\HttpEnd::class, 'HttpEnd' => event\HttpEnd::class,
'RouteLoaded' => event\RouteLoaded::class, 'RouteLoaded' => event\RouteLoaded::class,
'LogWrite' => event\LogWrite::class, 'LogWrite' => event\LogWrite::class,
'LogRecord' => event\LogRecord::class,
]; ];
/** /**
...@@ -215,6 +216,14 @@ class Event ...@@ -215,6 +216,14 @@ class Event
$result = []; $result = [];
$listeners = $this->listener[$event] ?? []; $listeners = $this->listener[$event] ?? [];
if (strpos($event, '.')) {
[$prefix, $event] = explode('.', $event, 2);
if (isset($this->listener[$prefix . '.*'])) {
$listeners = array_merge($listeners, $this->listener[$prefix . '.*']);
}
}
$listeners = array_unique($listeners, SORT_REGULAR); $listeners = array_unique($listeners, SORT_REGULAR);
foreach ($listeners as $key => $listener) { foreach ($listeners as $key => $listener) {
......
...@@ -408,7 +408,8 @@ class Request implements ArrayAccess ...@@ -408,7 +408,8 @@ class Request implements ArrayAccess
$rootDomain = $this->rootDomain(); $rootDomain = $this->rootDomain();
if ($rootDomain) { if ($rootDomain) {
$this->subDomain = rtrim(stristr($this->host(), $rootDomain, true), '.'); $sub = stristr($this->host(), $rootDomain, true);
$this->subDomain = $sub ? rtrim($sub, '.') : '';
} else { } else {
$this->subDomain = ''; $this->subDomain = '';
} }
...@@ -878,10 +879,12 @@ class Request implements ArrayAccess ...@@ -878,10 +879,12 @@ class Request implements ArrayAccess
*/ */
public function all($name = '', $filter = '') public function all($name = '', $filter = '')
{ {
$data = array_merge($this->param(), $this->file()); $data = array_merge($this->param(), $this->file() ?: []);
if (is_array($name)) { if (is_array($name)) {
$data = $this->only($name, $data, $filter); $data = $this->only($name, $data, $filter);
} elseif ($name) {
$data = $data[$name] ?? null;
} }
return $data; return $data;
...@@ -1147,7 +1150,6 @@ class Request implements ArrayAccess ...@@ -1147,7 +1150,6 @@ class Request implements ArrayAccess
{ {
$files = $this->file; $files = $this->file;
if (!empty($files)) { if (!empty($files)) {
if (strpos($name, '.')) { if (strpos($name, '.')) {
[$name, $sub] = explode('.', $name); [$name, $sub] = explode('.', $name);
} }
...@@ -1307,12 +1309,12 @@ class Request implements ArrayAccess ...@@ -1307,12 +1309,12 @@ class Request implements ArrayAccess
/** /**
* 强制类型转换 * 强制类型转换
* @access public * @access protected
* @param mixed $data * @param mixed $data
* @param string $type * @param string $type
* @return mixed * @return mixed
*/ */
private function typeCast(&$data, string $type) protected function typeCast(&$data, string $type)
{ {
switch (strtolower($type)) { switch (strtolower($type)) {
// 数组 // 数组
...@@ -1344,7 +1346,7 @@ class Request implements ArrayAccess ...@@ -1344,7 +1346,7 @@ class Request implements ArrayAccess
/** /**
* 获取数据 * 获取数据
* @access public * @access protected
* @param array $data 数据源 * @param array $data 数据源
* @param string $name 字段名 * @param string $name 字段名
* @param mixed $default 默认值 * @param mixed $default 默认值
......
...@@ -63,7 +63,7 @@ class RunServer extends Command ...@@ -63,7 +63,7 @@ class RunServer extends Command
escapeshellarg($root . DIRECTORY_SEPARATOR . 'router.php') escapeshellarg($root . DIRECTORY_SEPARATOR . 'router.php')
); );
$output->writeln(sprintf('ThinkPHP Development server is started On <http://%s:%s/>', '0.0.0.0' == $host ? '127.0.0.1' : $host, $port)); $output->writeln(sprintf('ThinkPHP Development server is started On <http://%s:%s/>', $host, $port));
$output->writeln(sprintf('You can exit with <info>`CTRL-C`</info>')); $output->writeln(sprintf('You can exit with <info>`CTRL-C`</info>'));
$output->writeln(sprintf('Document root is: %s', $root)); $output->writeln(sprintf('Document root is: %s', $root));
passthru($command); passthru($command);
......
...@@ -62,7 +62,7 @@ use think\route\Url as UrlBuild; ...@@ -62,7 +62,7 @@ use think\route\Url as UrlBuild;
* @method static RuleItem redirect(string $rule, string $route = '', int $status = 301) 注册重定向路由 * @method static RuleItem redirect(string $rule, string $route = '', int $status = 301) 注册重定向路由
* @method static \think\Route rest(string|array $name, array|bool $resource = []) rest方法定义和修改 * @method static \think\Route rest(string|array $name, array|bool $resource = []) rest方法定义和修改
* @method static array|null getRest(string $name = null) 获取rest方法定义的参数 * @method static array|null getRest(string $name = null) 获取rest方法定义的参数
* @method static RuleItem miss(string|Closure $route, string $method = '*') 注册未匹配路由规则后的处理 * @method static RuleItem miss(string|\Closure $route, string $method = '*') 注册未匹配路由规则后的处理
* @method static Response dispatch(\think\Request $request, Closure|bool $withRoute = true) 路由调度 * @method static Response dispatch(\think\Request $request, Closure|bool $withRoute = true) 路由调度
* @method static Dispatch|false check() 检测URL路由 * @method static Dispatch|false check() 检测URL路由
* @method static Dispatch url(string $url) 默认URL解析 * @method static Dispatch url(string $url) 默认URL解析
......
...@@ -42,6 +42,12 @@ class ModelService extends Service ...@@ -42,6 +42,12 @@ class ModelService extends Service
$model->setDateFormat($config->get('database.datetime_format', 'Y-m-d H:i:s')); $model->setDateFormat($config->get('database.datetime_format', 'Y-m-d H:i:s'));
} }
$timeField = $config->get('database.datetime_field');
if (!empty($timeField)) {
[$createTime, $updateTime] = explode(',', $timeField);
$model->setTimeField($createTime, $updateTime);
}
}); });
} }
} }
...@@ -364,7 +364,7 @@ class DbManager ...@@ -364,7 +364,7 @@ class DbManager
{ {
if (isset($this->event[$event])) { if (isset($this->event[$event])) {
foreach ($this->event[$event] as $callback) { foreach ($this->event[$event] as $callback) {
call_user_func_array($callback, [$this]); call_user_func_array($callback, [$params]);
} }
} }
} }
......
...@@ -621,7 +621,7 @@ abstract class BaseQuery ...@@ -621,7 +621,7 @@ abstract class BaseQuery
$bind = $this->bind; $bind = $this->bind;
$total = $this->count(); $total = $this->count();
$results = $this->options($options)->bind($bind)->page($page, $listRows)->select(); $results = $total > 0 ? $this->options($options)->bind($bind)->page($page, $listRows)->select() : [];
} elseif ($simple) { } elseif ($simple) {
$results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select(); $results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select();
$total = null; $total = null;
......
...@@ -969,8 +969,8 @@ abstract class Builder ...@@ -969,8 +969,8 @@ abstract class Builder
$sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : ''; $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : '';
$bind = $query->getFieldsBindType(); $bind = $query->getFieldsBindType();
foreach ($val as $item) { foreach ($val as $k => $item) {
$val[] = $this->parseDataBind($query, $key, $item, $bind); $val[$k] = $this->parseDataBind($query, $key, $item, $bind);
} }
return 'field(' . $this->parseKey($query, $key, true) . ',' . implode(',', $val) . ')' . $sort; return 'field(' . $this->parseKey($query, $key, true) . ',' . implode(',', $val) . ')' . $sort;
......
...@@ -16,6 +16,7 @@ use Closure; ...@@ -16,6 +16,7 @@ use Closure;
use PDO; use PDO;
use PDOStatement; use PDOStatement;
use think\db\exception\BindParamException; use think\db\exception\BindParamException;
use think\db\exception\DbEventException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\db\exception\PDOException; use think\db\exception\PDOException;
use think\Model; use think\Model;
...@@ -865,18 +866,18 @@ abstract class PDOConnection extends Connection ...@@ -865,18 +866,18 @@ abstract class PDOConnection extends Connection
public function find(BaseQuery $query): array public function find(BaseQuery $query): array
{ {
// 事件回调 // 事件回调
$result = $this->db->trigger('before_find', $query); try {
$this->db->trigger('before_find', $query);
if (!$result) { } catch (DbEventException $e) {
// 执行查询 return [];
$resultSet = $this->pdoQuery($query, function ($query) {
return $this->builder->select($query, true);
});
$result = $resultSet[0] ?? [];
} }
return $result; // 执行查询
$resultSet = $this->pdoQuery($query, function ($query) {
return $this->builder->select($query, true);
});
return $resultSet[0] ?? [];
} }
/** /**
...@@ -908,16 +909,16 @@ abstract class PDOConnection extends Connection ...@@ -908,16 +909,16 @@ abstract class PDOConnection extends Connection
*/ */
public function select(BaseQuery $query): array public function select(BaseQuery $query): array
{ {
$resultSet = $this->db->trigger('before_select', $query); try {
$this->db->trigger('before_select', $query);
if (!$resultSet) { } catch (DbEventException $e) {
// 执行查询操作 return [];
$resultSet = $this->pdoQuery($query, function ($query) {
return $this->builder->select($query);
});
} }
return $resultSet; // 执行查询操作
return $this->pdoQuery($query, function ($query) {
return $this->builder->select($query);
});
} }
/** /**
...@@ -1158,7 +1159,7 @@ abstract class PDOConnection extends Connection ...@@ -1158,7 +1159,7 @@ abstract class PDOConnection extends Connection
$field = $aggregate . '(' . (!empty($distinct) ? 'DISTINCT ' : '') . $this->builder->parseKey($query, $field, true) . ') AS think_' . strtolower($aggregate); $field = $aggregate . '(' . (!empty($distinct) ? 'DISTINCT ' : '') . $this->builder->parseKey($query, $field, true) . ') AS think_' . strtolower($aggregate);
$result = $this->value($query, $field, 0, false); $result = $this->value($query, $field, 0);
return $force ? (float) $result : $result; return $force ? (float) $result : $result;
} }
...@@ -1448,7 +1449,7 @@ abstract class PDOConnection extends Connection ...@@ -1448,7 +1449,7 @@ abstract class PDOConnection extends Connection
} }
$this->reConnectTimes = 0; $this->reConnectTimes = 0;
} catch (\Throwable | \Exception $e) { } catch (\Throwable | \Exception $e) {
if ($this->transTimes === 1 && $this->reConnectTimes < 4 && $this->isBreak($e)) { if (1 === $this->transTimes && $this->reConnectTimes < 4 && $this->isBreak($e)) {
--$this->transTimes; --$this->transTimes;
++$this->reConnectTimes; ++$this->reConnectTimes;
$this->close()->startTrans(); $this->close()->startTrans();
...@@ -1566,10 +1567,10 @@ abstract class PDOConnection extends Connection ...@@ -1566,10 +1567,10 @@ abstract class PDOConnection extends Connection
*/ */
public function close() public function close()
{ {
$this->linkID = null; $this->linkID = null;
$this->linkWrite = null; $this->linkWrite = null;
$this->linkRead = null; $this->linkRead = null;
$this->links = []; $this->links = [];
$this->transTimes = 0; $this->transTimes = 0;
$this->free(); $this->free();
......
...@@ -227,6 +227,8 @@ trait ResultOperation ...@@ -227,6 +227,8 @@ trait ResultOperation
* @access public * @access public
* @param array|string|Query|Closure $data 数据 * @param array|string|Query|Closure $data 数据
* @return array|Collection|static[] * @return array|Collection|static[]
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/ */
public function selectOrFail($data = null) public function selectOrFail($data = null)
{ {
...@@ -238,6 +240,8 @@ trait ResultOperation ...@@ -238,6 +240,8 @@ trait ResultOperation
* @access public * @access public
* @param array|string|Query|Closure $data 数据 * @param array|string|Query|Closure $data 数据
* @return array|Model|static * @return array|Model|static
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/ */
public function findOrFail($data = null) public function findOrFail($data = null)
{ {
......
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\db\exception;
/**
* Db事件异常
*/
class DbEventException extends DbException
{
}
...@@ -245,11 +245,15 @@ abstract class Relation ...@@ -245,11 +245,15 @@ abstract class Relation
/** /**
* 排除关联数据的字段 * 排除关联数据的字段
* @access public * @access public
* @param array $field 关联字段限制 * @param array|string $field 关联字段限制
* @return $this * @return $this
*/ */
public function withoutField(array $field) public function withoutField($field)
{ {
if (is_string($field)) {
$field = array_map('trim', explode(',', $field));
}
$this->withoutField = $field; $this->withoutField = $field;
return $this; return $this;
} }
......
...@@ -77,6 +77,21 @@ trait TimeStamp ...@@ -77,6 +77,21 @@ trait TimeStamp
return $type; return $type;
} }
/**
* 设置时间字段名称
* @access public
* @param string $createTime
* @param string $updateTime
* @return $this
*/
public function setTimeField(string $createTime, string $updateTime)
{
$this->createTime = $createTime;
$this->updateTime = $updateTime;
return $this;
}
/** /**
* 获取自动写入时间字段 * 获取自动写入时间字段
* @access public * @access public
......
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 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\model\concern;
use think\db\BaseQuery as Query;
use think\db\exception\DbException as Exception;
/**
* 虚拟模型
*/
trait Virtual
{
/**
* 获取当前模型的数据库查询对象
* @access public
* @param array $scope 设置不使用的全局查询范围
* @return Query
*/
public function db($scope = []): Query
{
throw new Exception('virtual model not support db query');
}
/**
* 获取字段类型信息
* @access public
* @param string $field 字段名
* @return string|null
*/
public function getFieldType(string $field)
{}
/**
* 保存当前数据对象
* @access public
* @param array $data 数据
* @param string $sequence 自增序列名
* @return bool
*/
public function save(array $data = [], string $sequence = null): bool
{
// 数据对象赋值
$this->setAttrs($data);
if ($this->isEmpty() || false === $this->trigger('BeforeWrite')) {
return false;
}
// 写入回调
$this->trigger('AfterWrite');
$this->exists(true);
return true;
}
/**
* 删除当前的记录
* @access public
* @return bool
*/
public function delete(): bool
{
if (!$this->isExists() || $this->isEmpty() || false === $this->trigger('BeforeDelete')) {
return false;
}
// 关联删除
if (!empty($this->relationWrite)) {
$this->autoRelationDelete();
}
$this->trigger('AfterDelete');
$this->exists(false);
return true;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册