ComposerUpdate

This commit is contained in:
Anyon 2020-05-01 21:13:23 +08:00
parent 21a79bb794
commit 0efb9180c1
21 changed files with 3247 additions and 3185 deletions

21
composer.lock generated
View File

@ -721,16 +721,16 @@
}, },
{ {
"name": "topthink/think-orm", "name": "topthink/think-orm",
"version": "v2.0.31", "version": "v2.0.32",
"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": "d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4" "reference": "03aaaa4d8c4475115b3acaa5aa2498bf5792e017"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4", "url": "https://api.github.com/repos/top-think/think-orm/zipball/03aaaa4d8c4475115b3acaa5aa2498bf5792e017",
"reference": "d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4", "reference": "03aaaa4d8c4475115b3acaa5aa2498bf5792e017",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -768,7 +768,7 @@
"database", "database",
"orm" "orm"
], ],
"time": "2020-01-07T10:05:10+00:00" "time": "2020-04-26T13:54:48+00:00"
}, },
{ {
"name": "topthink/think-template", "name": "topthink/think-template",
@ -909,12 +909,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "373e7587a6ade11254892b63e431cb57498f8fa3" "reference": "646ddaf7017822aabbc9aa7c3e8e4e0aa095c515"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/373e7587a6ade11254892b63e431cb57498f8fa3", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/646ddaf7017822aabbc9aa7c3e8e4e0aa095c515",
"reference": "373e7587a6ade11254892b63e431cb57498f8fa3", "reference": "646ddaf7017822aabbc9aa7c3e8e4e0aa095c515",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -958,7 +958,7 @@
], ],
"description": "ThinkPHP v6.0 Development Library", "description": "ThinkPHP v6.0 Development Library",
"homepage": "http://framework.thinkadmin.top", "homepage": "http://framework.thinkadmin.top",
"time": "2020-04-26T09:48:50+00:00" "time": "2020-05-01T12:57:12+00:00"
}, },
{ {
"name": "zoujingli/wechat-developer", "name": "zoujingli/wechat-developer",
@ -1047,5 +1047,6 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-simplexml": "*" "ext-simplexml": "*"
}, },
"platform-dev": [] "platform-dev": [],
"plugin-api-version": "1.1.0"
} }

View File

@ -44,7 +44,7 @@ return [
// 数据库表前缀 // 数据库表前缀
'prefix' => '', 'prefix' => '',
// 数据库调试模式 // 数据库调试模式
'debug' => true, 'debug' => app()->isDebug(),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0, 'deploy' => 0,
// 数据库读写是否分离 主从式有效 // 数据库读写是否分离 主从式有效

View File

@ -13,6 +13,9 @@ class ComposerAutoloaderInitf41e9df38a61a147f539b835fbd021f0
} }
} }
/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader() public static function getLoader()
{ {
if (null !== self::$loader) { if (null !== self::$loader) {

View File

@ -738,17 +738,17 @@
}, },
{ {
"name": "topthink/think-orm", "name": "topthink/think-orm",
"version": "v2.0.31", "version": "v2.0.32",
"version_normalized": "2.0.31.0", "version_normalized": "2.0.32.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": "d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4" "reference": "03aaaa4d8c4475115b3acaa5aa2498bf5792e017"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4", "url": "https://api.github.com/repos/top-think/think-orm/zipball/03aaaa4d8c4475115b3acaa5aa2498bf5792e017",
"reference": "d6965dfae21f150e29cc899ab6f9b1bd2c0f2ee4", "reference": "03aaaa4d8c4475115b3acaa5aa2498bf5792e017",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -764,7 +764,7 @@
"psr/simple-cache": "^1.0", "psr/simple-cache": "^1.0",
"topthink/think-helper": "^3.1" "topthink/think-helper": "^3.1"
}, },
"time": "2020-01-07T10:05:10+00:00", "time": "2020-04-26T13:54:48+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
@ -935,12 +935,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git", "url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "373e7587a6ade11254892b63e431cb57498f8fa3" "reference": "646ddaf7017822aabbc9aa7c3e8e4e0aa095c515"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/373e7587a6ade11254892b63e431cb57498f8fa3", "url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/646ddaf7017822aabbc9aa7c3e8e4e0aa095c515",
"reference": "373e7587a6ade11254892b63e431cb57498f8fa3", "reference": "646ddaf7017822aabbc9aa7c3e8e4e0aa095c515",
"shasum": "", "shasum": "",
"mirrors": [ "mirrors": [
{ {
@ -956,7 +956,7 @@
"ext-json": "*", "ext-json": "*",
"topthink/framework": "^6.0" "topthink/framework": "^6.0"
}, },
"time": "2020-04-26T09:48:50+00:00", "time": "2020-05-01T12:57:12+00:00",
"type": "library", "type": "library",
"extra": { "extra": {
"think": { "think": {

2
vendor/services.php vendored
View File

@ -1,5 +1,5 @@
<?php <?php
// This file is automatically generated at:2020-04-30 14:37:31 // This file is automatically generated at:2020-05-01 21:06:44
declare (strict_types = 1); declare (strict_types = 1);
return array ( return array (
0 => 'think\\app\\Service', 0 => 'think\\app\\Service',

View File

@ -139,6 +139,12 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
*/ */
protected static $maker = []; protected static $maker = [];
/**
* 方法注入
* @var Closure[][]
*/
protected static $macro = [];
/** /**
* 设置服务注入 * 设置服务注入
* @access public * @access public
@ -150,6 +156,21 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
static::$maker[] = $maker; static::$maker[] = $maker;
} }
/**
* 设置方法注入
* @access public
* @param string $method
* @param Closure $closure
* @return void
*/
public static function macro(string $method, Closure $closure)
{
if (!isset(static::$macro[static::class])) {
static::$macro[static::class] = [];
}
static::$macro[static::class][$method] = $closure;
}
/** /**
* 设置Db对象 * 设置Db对象
* @access public * @access public
@ -759,11 +780,13 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
$result = []; $result = [];
$suffix = $this->getSuffix();
foreach ($dataSet as $key => $data) { foreach ($dataSet as $key => $data) {
if ($this->exists || (!empty($auto) && isset($data[$pk]))) { if ($this->exists || (!empty($auto) && isset($data[$pk]))) {
$result[$key] = self::update($data); $result[$key] = static::update($data, [], [], $suffix);
} else { } else {
$result[$key] = self::create($data, $this->field, $this->replace); $result[$key] = static::create($data, $this->field, $this->replace, $suffix);
} }
} }
@ -822,9 +845,10 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
* @param array $data 数据数组 * @param array $data 数据数组
* @param array $allowField 允许字段 * @param array $allowField 允许字段
* @param bool $replace 使用Replace * @param bool $replace 使用Replace
* @param string $suffix 数据表后缀
* @return static * @return static
*/ */
public static function create(array $data, array $allowField = [], bool $replace = false): Model public static function create(array $data, array $allowField = [], bool $replace = false, string $suffix = ''): Model
{ {
$model = new static(); $model = new static();
@ -832,6 +856,10 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
$model->allowField($allowField); $model->allowField($allowField);
} }
if (!empty($suffix)) {
$model->setSuffix($suffix);
}
$model->replace($replace)->save($data); $model->replace($replace)->save($data);
return $model; return $model;
@ -843,9 +871,10 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
* @param array $data 数据数组 * @param array $data 数据数组
* @param mixed $where 更新条件 * @param mixed $where 更新条件
* @param array $allowField 允许字段 * @param array $allowField 允许字段
* @param string $suffix 数据表后缀
* @return static * @return static
*/ */
public static function update(array $data, $where = [], array $allowField = []) public static function update(array $data, $where = [], array $allowField = [], string $suffix = '')
{ {
$model = new static(); $model = new static();
@ -857,6 +886,10 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
$model->setUpdateWhere($where); $model->setUpdateWhere($where);
} }
if (!empty($suffix)) {
$model->setSuffix($suffix);
}
$model->exists(true)->save($data); $model->exists(true)->save($data);
return $model; return $model;
@ -1013,6 +1046,10 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
public function __call($method, $args) public function __call($method, $args)
{ {
if (isset(static::$macro[static::class][$method])) {
return call_user_func_array(static::$macro[static::class][$method]->bindTo($this, static::class), $args);
}
if ('withattr' == strtolower($method)) { if ('withattr' == strtolower($method)) {
return call_user_func_array([$this, 'withAttribute'], $args); return call_user_func_array([$this, 'withAttribute'], $args);
} }
@ -1022,6 +1059,10 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
public static function __callStatic($method, $args) public static function __callStatic($method, $args)
{ {
if (isset(static::$macro[static::class][$method])) {
return call_user_func_array(static::$macro[static::class][$method]->bindTo(null, static::class), $args);
}
$model = new static(); $model = new static();
return call_user_func_array([$model->db(), $method], $args); return call_user_func_array([$model->db(), $method], $args);

View File

@ -368,7 +368,10 @@ abstract class Builder
if ($value instanceof Closure) { if ($value instanceof Closure) {
// 使用闭包查询 // 使用闭包查询
$where[] = $this->parseClosureWhere($query, $value, $logic); $whereClosureStr = $this->parseClosureWhere($query, $value, $logic);
if ($whereClosureStr) {
$where[] = $whereClosureStr;
}
} elseif (is_array($field)) { } elseif (is_array($field)) {
$where[] = $this->parseMultiWhereField($query, $value, $field, $logic, $binds); $where[] = $this->parseMultiWhereField($query, $value, $field, $logic, $binds);
} elseif ($field instanceof Raw) { } elseif ($field instanceof Raw) {

View File

@ -214,11 +214,12 @@ abstract class Connection
* 分析缓存Key * 分析缓存Key
* @access protected * @access protected
* @param BaseQuery $query 查询对象 * @param BaseQuery $query 查询对象
* @param string $method查询方法
* @return string * @return string
*/ */
protected function getCacheKey(BaseQuery $query): string protected function getCacheKey(BaseQuery $query, string $method = ''): string
{ {
if (!empty($query->getOptions('key'))) { if (!empty($query->getOptions('key')) && empty($method)) {
$key = 'think:' . $this->getConfig('database') . '.' . $query->getTable() . '|' . $query->getOptions('key'); $key = 'think:' . $this->getConfig('database') . '.' . $query->getTable() . '|' . $query->getOptions('key');
} else { } else {
$key = $query->getQueryGuid(); $key = $query->getQueryGuid();
@ -232,9 +233,10 @@ abstract class Connection
* @access protected * @access protected
* @param BaseQuery $query 查询对象 * @param BaseQuery $query 查询对象
* @param array $cache 缓存信息 * @param array $cache 缓存信息
* @param string $method查询方法
* @return CacheItem * @return CacheItem
*/ */
protected function parseCache(BaseQuery $query, array $cache): CacheItem protected function parseCache(BaseQuery $query, array $cache, string $method = ''): CacheItem
{ {
[$key, $expire, $tag] = $cache; [$key, $expire, $tag] = $cache;
@ -242,7 +244,7 @@ abstract class Connection
$cacheItem = $key; $cacheItem = $key;
} else { } else {
if (true === $key) { if (true === $key) {
$key = $this->getCacheKey($query); $key = $this->getCacheKey($query, $method);
} }
$cacheItem = new CacheItem($key); $cacheItem = new CacheItem($key);

View File

@ -1033,7 +1033,7 @@ abstract class PDOConnection extends Connection implements ConnectionInterface
$query->setOption('field', (array) $field); $query->setOption('field', (array) $field);
if (!empty($options['cache'])) { if (!empty($options['cache'])) {
$cacheItem = $this->parseCache($query, $options['cache']); $cacheItem = $this->parseCache($query, $options['cache'], 'value');
$key = $cacheItem->getKey(); $key = $cacheItem->getKey();
if ($this->cache->has($key)) { if ($this->cache->has($key)) {
@ -1118,7 +1118,7 @@ abstract class PDOConnection extends Connection implements ConnectionInterface
if (!empty($options['cache'])) { if (!empty($options['cache'])) {
// 判断查询缓存 // 判断查询缓存
$cacheItem = $this->parseCache($query, $options['cache']); $cacheItem = $this->parseCache($query, $options['cache'], 'column');
$name = $cacheItem->getKey(); $name = $cacheItem->getKey();
if ($this->cache->has($name)) { if ($this->cache->has($name)) {
@ -1151,6 +1151,8 @@ abstract class PDOConnection extends Connection implements ConnectionInterface
if (strpos($column, ',')) { if (strpos($column, ',')) {
$column = null; $column = null;
} elseif (strpos($column, ' ')) {
$column = substr(strrchr(trim($column), ' '), 1);
} elseif (strpos($column, '.')) { } elseif (strpos($column, '.')) {
[$alias, $column] = explode('.', $column); [$alias, $column] = explode('.', $column);
} }

View File

@ -140,13 +140,19 @@ trait ModelRelationQuery
/** /**
* 使用搜索器条件搜索字段 * 使用搜索器条件搜索字段
* @access public * @access public
* @param array $fields 搜索字段 * @param string|array $fields 搜索字段
* @param array $data 搜索数据 * @param mixed $data 搜索数据
* @param string $prefix 字段前缀标识 * @param string $prefix 字段前缀标识
* @return $this * @return $this
*/ */
public function withSearch(array $fields, array $data = [], string $prefix = '') public function withSearch($fields, $data = [], string $prefix = '')
{ {
if (is_string($fields)) {
$fields = explode(',', $fields);
}
$likeFields = $this->getConfig('match_like_fields') ?: [];
foreach ($fields as $key => $field) { foreach ($fields as $key => $field) {
if ($field instanceof Closure) { if ($field instanceof Closure) {
$field($this, $data[$key] ?? null, $data, $prefix); $field($this, $data[$key] ?? null, $data, $prefix);
@ -157,6 +163,8 @@ trait ModelRelationQuery
if (method_exists($this->model, $method)) { if (method_exists($this->model, $method)) {
$this->model->$method($this, $data[$field] ?? null, $data, $prefix); $this->model->$method($this, $data[$field] ?? null, $data, $prefix);
} elseif (isset($data[$field])) {
$this->where($fieldName, in_array($fieldName, $likeFields) ? 'like' : '=', in_array($fieldName, $likeFields) ? '%' . $data[$field] . '%' : $data[$field]);
} }
} }
} }

View File

@ -12,10 +12,14 @@ declare (strict_types = 1);
namespace think\db\concern; namespace think\db\concern;
use Closure;
use think\Collection; use think\Collection;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\db\Query;
use think\helper\Str; use think\helper\Str;
use think\Model;
/** /**
* 查询数据处理 * 查询数据处理
@ -103,6 +107,7 @@ trait ResultOperation
*/ */
protected function filterResult(&$result): void protected function filterResult(&$result): void
{ {
$array = [];
if (!empty($this->options['visible'])) { if (!empty($this->options['visible'])) {
foreach ($this->options['visible'] as $key) { foreach ($this->options['visible'] as $key) {
$array[] = $key; $array[] = $key;
@ -222,9 +227,6 @@ trait ResultOperation
* @access public * @access public
* @param array|string|Query|Closure $data 数据 * @param array|string|Query|Closure $data 数据
* @return array|Model * @return array|Model
* @throws DbException
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/ */
public function selectOrFail($data = null) public function selectOrFail($data = null)
{ {
@ -236,9 +238,6 @@ trait ResultOperation
* @access public * @access public
* @param array|string|Query|Closure $data 数据 * @param array|string|Query|Closure $data 数据
* @return array|Model * @return array|Model
* @throws DbException
* @throws ModelNotFoundException
* @throws DataNotFoundException
*/ */
public function findOrFail($data = null) public function findOrFail($data = null)
{ {

View File

@ -228,7 +228,7 @@ abstract class Relation
if (!empty($params)) { if (!empty($params)) {
$type = $params[0]->getType(); $type = $params[0]->getType();
return Relation::class == $type || is_null($type) ? $this : $this->query; return is_null($type) || Relation::class == $type->getName() ? $this : $this->query;
} }
return $this; return $this;

View File

@ -720,7 +720,7 @@ trait RelationShip
{ {
$relation = Str::camel($attr); $relation = Str::camel($attr);
if (method_exists($this, $relation) && !method_exists('think\Model', $relation)) { if ((method_exists($this, $relation) && !method_exists('think\Model', $relation)) || isset(static::$macro[static::class][$relation])) {
return $relation; return $relation;
} }

View File

@ -13,9 +13,11 @@ declare (strict_types = 1);
namespace think\model\concern; namespace think\model\concern;
use think\db\BaseQuery as Query; use think\db\BaseQuery as Query;
use think\Model;
/** /**
* 数据软删除 * 数据软删除
* @mixin Model
*/ */
trait SoftDelete trait SoftDelete
{ {
@ -149,7 +151,7 @@ trait SoftDelete
public static function destroy($data, bool $force = false): bool public static function destroy($data, bool $force = false): bool
{ {
// 包含软删除数据 // 包含软删除数据
$query = (new static())->db(false); $query = (new static())->withTrashedData(true)->db(false);
if (is_array($data) && key($data) !== 0) { if (is_array($data) && key($data) !== 0) {
$query->where($data); $query->where($data);

View File

@ -222,7 +222,7 @@ class BelongsToMany extends Relation
*/ */
public function find($data = null) public function find($data = null)
{ {
$result = $this->buildQuery()->find($data); $result = $this->buildQuery()->findOrEmpty($data);
if (!$result->isEmpty()) { if (!$result->isEmpty()) {
$this->hydratePivot([$result]); $this->hydratePivot([$result]);

View File

@ -340,7 +340,7 @@ class HasMany extends Relation
return $query->group($model . '.' . $this->localKey) return $query->group($model . '.' . $this->localKey)
->field($fields) ->field($fields)
->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey) ->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $joinType)
->when($softDelete, function ($query) use ($softDelete, $relation) { ->when($softDelete, function ($query) use ($softDelete, $relation) {
$query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null);
}) })

View File

@ -154,7 +154,7 @@ class HasManyThrough extends Relation
$query = $query ?: $this->parent->db()->alias($model); $query = $query ?: $this->parent->db()->alias($model);
return $query->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) return $query->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey)
->join($modelTable, $modelTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) ->join($modelTable, $modelTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk, $joinType)
->when($softDelete, function ($query) use ($softDelete, $modelTable) { ->when($softDelete, function ($query) use ($softDelete, $modelTable) {
$query->where($modelTable . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); $query->where($modelTable . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null);
}) })

View File

@ -223,7 +223,6 @@ class MorphTo extends Relation
// 关联模型 // 关联模型
if (!isset($data[$result->$morphKey])) { if (!isset($data[$result->$morphKey])) {
$relationModel = null; $relationModel = null;
throw new Exception('relation data not exists :' . $this->model);
} else { } else {
$relationModel = $data[$result->$morphKey]; $relationModel = $data[$result->$morphKey];
$relationModel->setParent(clone $result); $relationModel->setParent(clone $result);

View File

@ -15,6 +15,7 @@
namespace think\admin\command; namespace think\admin\command;
use Psr\Log\NullLogger;
use think\admin\Command; use think\admin\Command;
use think\admin\service\ProcessService; use think\admin\service\ProcessService;
use think\console\Input; use think\console\Input;
@ -44,8 +45,9 @@ abstract class Queue extends Command
* @param Input $input * @param Input $input
* @param Output $output * @param Output $output
*/ */
public function initialize(Input $input, Output $output) protected function initialize(Input $input, Output $output)
{ {
$this->app->db->setLog(new NullLogger());
$this->process = ProcessService::instance(); $this->process = ProcessService::instance();
} }
} }