ComposerUpdate

This commit is contained in:
邹景立 2021-04-28 14:00:09 +08:00
parent 21235ae70b
commit c5e5648781
23 changed files with 253 additions and 103 deletions

View File

@ -449,6 +449,7 @@ return array(
'think\\event\\AppInit' => $vendorDir . '/topthink/framework/src/think/event/AppInit.php',
'think\\event\\HttpEnd' => $vendorDir . '/topthink/framework/src/think/event/HttpEnd.php',
'think\\event\\HttpRun' => $vendorDir . '/topthink/framework/src/think/event/HttpRun.php',
'think\\event\\LogRecord' => $vendorDir . '/topthink/framework/src/think/event/LogRecord.php',
'think\\event\\LogWrite' => $vendorDir . '/topthink/framework/src/think/event/LogWrite.php',
'think\\event\\RouteLoaded' => $vendorDir . '/topthink/framework/src/think/event/RouteLoaded.php',
'think\\exception\\ClassNotFoundException' => $vendorDir . '/topthink/framework/src/think/exception/ClassNotFoundException.php',

View File

@ -578,6 +578,7 @@ class ComposerStaticInit3e3e984682c06e656fe76c5d84347fb3
'think\\event\\AppInit' => __DIR__ . '/..' . '/topthink/framework/src/think/event/AppInit.php',
'think\\event\\HttpEnd' => __DIR__ . '/..' . '/topthink/framework/src/think/event/HttpEnd.php',
'think\\event\\HttpRun' => __DIR__ . '/..' . '/topthink/framework/src/think/event/HttpRun.php',
'think\\event\\LogRecord' => __DIR__ . '/..' . '/topthink/framework/src/think/event/LogRecord.php',
'think\\event\\LogWrite' => __DIR__ . '/..' . '/topthink/framework/src/think/event/LogWrite.php',
'think\\event\\RouteLoaded' => __DIR__ . '/..' . '/topthink/framework/src/think/event/RouteLoaded.php',
'think\\exception\\ClassNotFoundException' => __DIR__ . '/..' . '/topthink/framework/src/think/exception/ClassNotFoundException.php',

View File

@ -515,17 +515,17 @@
},
{
"name": "topthink/framework",
"version": "v6.0.7",
"version_normalized": "6.0.7.0",
"version": "v6.0.8",
"version_normalized": "6.0.8.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/framework.git",
"reference": "db8fe22520a9660dd5e4c87e304034ac49e39270"
"reference": "4789343672aef06d571d556da369c0e156609bce"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/framework/zipball/db8fe22520a9660dd5e4c87e304034ac49e39270",
"reference": "db8fe22520a9660dd5e4c87e304034ac49e39270",
"url": "https://api.github.com/repos/top-think/framework/zipball/4789343672aef06d571d556da369c0e156609bce",
"reference": "4789343672aef06d571d556da369c0e156609bce",
"shasum": "",
"mirrors": [
{
@ -551,7 +551,7 @@
"mockery/mockery": "^1.2",
"phpunit/phpunit": "^7.0"
},
"time": "2021-01-25T14:48:29+00:00",
"time": "2021-04-27T00:41:08+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -631,17 +631,17 @@
},
{
"name": "topthink/think-orm",
"version": "v2.0.39",
"version_normalized": "2.0.39.0",
"version": "v2.0.40",
"version_normalized": "2.0.40.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/think-orm.git",
"reference": "39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7"
"reference": "1119d979b850849f3725856460cf108eec1c3eb8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7",
"reference": "39a9d0a0e52d9b8bad9d98484d8484cdf5b683a7",
"url": "https://api.github.com/repos/top-think/think-orm/zipball/1119d979b850849f3725856460cf108eec1c3eb8",
"reference": "1119d979b850849f3725856460cf108eec1c3eb8",
"shasum": "",
"mirrors": [
{
@ -661,7 +661,7 @@
"require-dev": {
"phpunit/phpunit": "^7|^8|^9.5"
},
"time": "2021-02-26T10:20:00+00:00",
"time": "2021-04-19T13:29:37+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
@ -834,12 +834,12 @@
"source": {
"type": "git",
"url": "https://github.com/zoujingli/ThinkLibrary.git",
"reference": "c4bfb714326a86598fe14a085be4b5439f656c77"
"reference": "361caa1f19e990422b0ca089b44961666861e28d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/c4bfb714326a86598fe14a085be4b5439f656c77",
"reference": "c4bfb714326a86598fe14a085be4b5439f656c77",
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/361caa1f19e990422b0ca089b44961666861e28d",
"reference": "361caa1f19e990422b0ca089b44961666861e28d",
"shasum": "",
"mirrors": [
{
@ -856,7 +856,7 @@
"ext-mbstring": "*",
"topthink/framework": "^6.0"
},
"time": "2021-04-08T06:20:57+00:00",
"time": "2021-04-26T09:07:36+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-04-22 09:44:32
// This file is automatically generated at:2021-04-28 13:59:52
declare (strict_types = 1);
return array (
0 => 'think\\admin\\Library',

View File

@ -39,7 +39,7 @@ use think\initializer\RegisterService;
*/
class App extends Container
{
const VERSION = '6.0.7';
const VERSION = '6.0.8';
/**
* 应用调试模式
@ -47,6 +47,12 @@ class App extends Container
*/
protected $appDebug = false;
/**
* 环境变量标识
* @var string
*/
protected $envName = '';
/**
* 应用开始时间
* @var float
@ -277,6 +283,18 @@ class App extends Container
return $this->namespace;
}
/**
* 设置环境变量标识
* @access public
* @param string $name 环境标识
* @return $this
*/
public function setEnvName(string $name)
{
$this->envName = $name;
return $this;
}
/**
* 获取框架版本
* @access public
@ -395,6 +413,22 @@ class App extends Container
return $this->beginMem;
}
/**
* 加载环境变量定义
* @access public
* @param string $envName 环境标识
* @return void
*/
public function loadEnv(string $envName = ''): void
{
// 加载环境变量
$envFile = $envName ? $this->rootPath . '.env.' . $envName : $this->rootPath . '.env';
if (is_file($envFile)) {
$this->env->load($envFile);
}
}
/**
* 初始化应用
* @access public
@ -407,10 +441,7 @@ class App extends Container
$this->beginTime = microtime(true);
$this->beginMem = memory_get_usage();
// 加载环境变量
if (is_file($this->rootPath . '.env')) {
$this->env->load($this->rootPath . '.env');
}
$this->loadEnv($this->envName);
$this->configExt = $this->env->get('config_ext', '.php');
@ -590,7 +621,7 @@ class App extends Container
* 是否运行在命令行下
* @return bool
*/
public function runningInConsole()
public function runningInConsole(): bool
{
return php_sapi_name() === 'cli' || php_sapi_name() === 'phpdbg';
}

View File

@ -869,6 +869,24 @@ class Request implements ArrayAccess
return $this->input($this->param, $name, $default, $filter);
}
/**
* 获取包含文件在内的请求参数
* @access public
* @param string|array $name 变量名
* @param string|array $filter 过滤方法
* @return mixed
*/
public function all($name = '', $filter = '')
{
$data = array_merge($this->param(), $this->file());
if (is_array($name)) {
$data = $this->only($name, $data, $filter);
}
return $data;
}
/**
* 设置路由变量
* @access public

View File

@ -214,7 +214,7 @@ abstract class Response
/**
* 是否允许请求缓存
* @access public
* @return $this
* @return bool
*/
public function isAllowCache()
{

View File

@ -1591,7 +1591,7 @@ class Validate
* @param string $msg 错误信息
* @param mixed $rule 验证规则数据
* @param string $title 字段描述名
* @return string
* @return string|array
*/
protected function parseErrorMsg(string $msg, $rule, string $title)
{

View File

@ -13,14 +13,37 @@ namespace think\console\input;
class Argument
{
// 必传参数
const REQUIRED = 1;
// 可选参数
const OPTIONAL = 2;
// 数组参数
const IS_ARRAY = 4;
/**
* 参数名
* @var string
*/
private $name;
/**
* 参数类型
* @var int
*/
private $mode;
/**
* 参数默认值
* @var mixed
*/
private $default;
/**
* 参数描述
* @var string
*/
private $description;
/**

View File

@ -0,0 +1,29 @@
<?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: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
namespace think\event;
/**
* LogRecord事件类
*/
class LogRecord
{
/** @var string */
public $type;
/** @var string */
public $message;
public function __construct($type, $message)
{
$this->type = $type;
$this->message = $message;
}
}

View File

@ -15,6 +15,7 @@ namespace think\log;
use Psr\Log\LoggerInterface;
use think\contract\LogHandlerInterface;
use think\Event;
use think\event\LogRecord;
use think\event\LogWrite;
class Channel implements LoggerInterface
@ -94,6 +95,9 @@ class Channel implements LoggerInterface
if (!empty($msg) || 0 === $msg) {
$this->log[$type][] = $msg;
if ($this->event) {
$this->event->trigger(new LogRecord($type, $msg));
}
}
if (!$this->lazy || !$lazy) {

View File

@ -171,7 +171,9 @@ class RuleGroup extends Rule
}
}
if ($this->miss && in_array($this->miss->getMethod(), ['*', $method])) {
if (!empty($option['dispatcher'])) {
$result = $this->parseRule($request, '', $option['dispatcher'], $url, $option);
} elseif ($this->miss && in_array($this->miss->getMethod(), ['*', $method])) {
// 未匹配所有路由的路由规则处理
$result = $this->parseRule($request, '', $this->miss->getRoute(), $url, $this->miss->getOption());
} else {
@ -244,6 +246,11 @@ class RuleGroup extends Rule
*/
public function parseGroupRule($rule): void
{
if (is_string($rule) && is_subclass_of($rule, Dispatch::class)) {
$this->dispatcher($rule);
return;
}
$origin = $this->router->getGroup();
$this->router->setGroup($this);
@ -466,6 +473,17 @@ class RuleGroup extends Rule
return $this->setOption('merge_rule_regex', $merge);
}
/**
* 设置分组的Dispatch调度
* @access public
* @param string $dispatch 调度类
* @return $this
*/
public function dispatcher(string $dispatch)
{
return $this->setOption('dispatcher', $dispatch);
}
/**
* 获取完整分组Name
* @access public

View File

@ -98,7 +98,7 @@ class File implements SessionHandlerInterface
/** @var SplFileInfo $item */
foreach ($items as $item) {
if ($item->isDir() && !$item->isLink()) {
yield from$this->findFiles($item->getPathname(), $filter);
yield from $this->findFiles($item->getPathname(), $filter);
} else {
if ($filter($item)) {
yield $item;

View File

@ -267,7 +267,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
public function newInstance(array $data = [], $where = null): Model
{
$model = new static($data);
$model->readDataType();
if ($this->connection) {
$model->setConnection($this->connection);
@ -457,8 +456,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
$this->data = $this->db()->find($this->getKey())->getData();
$this->origin = $this->data;
$this->get = [];
$this->set = [];
$this->readDataType();
if ($relation) {
$this->relation = [];
@ -546,7 +543,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
// 重新记录原始数据
$this->origin = $this->data;
$this->set = [];
$this->get = [];
$this->lazySave = false;
return true;
@ -613,8 +610,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
return true;
}
$data = $this->writeDataType($data);
if ($this->autoWriteTimestamp && $this->updateTime) {
// 自动写入更新时间
$data[$this->updateTime] = $this->autoWriteTimestamp();
@ -677,7 +672,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
}
$this->checkData();
$data = $this->writeDataType($this->data);
$data = $this->data;
// 时间戳自动写入
if ($this->autoWriteTimestamp) {
@ -709,6 +704,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
$pk = $this->getPk();
if (is_string($pk) && (!isset($this->data[$pk]) || '' == $this->data[$pk])) {
unset($this->get[$pk]);
$this->data[$pk] = $result;
}
}
@ -721,6 +717,7 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
// 标记数据已经存在
$this->exists = true;
$this->origin = $this->data;
// 新增回调
$this->trigger('AfterInsert');
@ -969,7 +966,6 @@ abstract class Model implements JsonSerializable, ArrayAccess, Arrayable, Jsonab
{
unset($this->data[$name],
$this->get[$name],
$this->set[$name],
$this->relation[$name]);
}

View File

@ -1163,10 +1163,6 @@ abstract class BaseQuery
$this->parseView($options);
}
if (!isset($options['field'])) {
$options['field'] = '*';
}
foreach (['data', 'order', 'join', 'union'] as $name) {
if (!isset($options[$name])) {
$options[$name] = [];

View File

@ -136,7 +136,7 @@ abstract class Builder
}
if (empty($fields)) {
if ('*' == $options['field']) {
if (empty($options['field']) || '*' == $options['field']) {
$fields = array_keys($bind);
} else {
$fields = $options['field'];
@ -1125,7 +1125,7 @@ abstract class Builder
$this->parseTable($query, $options['table']),
$this->parseDistinct($query, $options['distinct']),
$this->parseExtra($query, $options['extra']),
$this->parseField($query, $options['field']),
$this->parseField($query, $options['field'] ?? '*'),
$this->parseJoin($query, $options['join']),
$this->parseWhere($query, $options['where']),
$this->parseGroup($query, $options['group']),
@ -1187,7 +1187,7 @@ abstract class Builder
$bind = $query->getFieldsBindType();
// 获取合法的字段
if ('*' == $options['field']) {
if (empty($options['field']) || '*' == $options['field']) {
$allowFields = array_keys($bind);
} else {
$allowFields = $options['field'];

View File

@ -290,7 +290,7 @@ abstract class Connection implements ConnectionInterface
protected function getCacheKey(BaseQuery $query, string $method = ''): string
{
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 {
$key = $query->getQueryGuid();
}

View File

@ -89,7 +89,7 @@ class Mysql extends Builder
$this->parsePartition($query, $options['partition']),
$this->parseDistinct($query, $options['distinct']),
$this->parseExtra($query, $options['extra']),
$this->parseField($query, $options['field']),
$this->parseField($query, $options['field'] ?? '*'),
$this->parseJoin($query, $options['join']),
$this->parseWhere($query, $options['where']),
$this->parseGroup($query, $options['group']),
@ -155,7 +155,7 @@ class Mysql extends Builder
$bind = $query->getFieldsBindType();
// 获取合法的字段
if ('*' == $options['field']) {
if (empty($options['field']) || '*' == $options['field']) {
$allowFields = array_keys($bind);
} else {
$allowFields = $options['field'];

View File

@ -100,12 +100,6 @@ trait Attribute
*/
private $get = [];
/**
* 修改器执行记录
* @var array
*/
private $set = [];
/**
* 动态获取器
* @var array
@ -363,10 +357,6 @@ trait Attribute
{
$name = $this->getRealFieldName($name);
if (isset($this->set[$name])) {
return;
}
// 检测修改器
$method = 'set' . Str::studly($name) . 'Attr';
@ -375,10 +365,12 @@ trait Attribute
$value = $this->$method($value, array_merge($this->data, $data));
$this->set[$name] = true;
if (is_null($value) && $array !== $this->data) {
return;
}
} elseif (isset($this->type[$name])) {
// 类型转换
$value = $this->writeTransform($value, $this->type[$name]);
}
// 设置数据对象属性
@ -512,6 +504,11 @@ trait Attribute
}
$value = $this->$method($value, $this->data);
} elseif (isset($this->type[$fieldName])) {
// 类型转换
$value = $this->readTransform($value, $this->type[$fieldName]);
} elseif ($this->autoWriteTimestamp && in_array($fieldName, [$this->createTime, $this->updateTime])) {
$value = $this->getTimestampValue($value);
} elseif ($relation) {
$value = $this->getRelationValue($relation);
// 保存关联对象值
@ -523,40 +520,6 @@ trait Attribute
return $value;
}
/**
* 读取数据类型处理
* @access protected
* @return void
*/
protected function readDataType(): void
{
foreach ($this->data as $key => $value) {
if (isset($this->type[$key])) {
$this->get[$key] = $this->readTransform($value, $this->type[$key]);
} elseif ($this->autoWriteTimestamp && in_array($key, [$this->createTime, $this->updateTime])) {
$this->get[$key] = $this->getTimestampValue($value);
}
}
}
/**
* 写入数据类型处理
* @access protected
* @param array $data 数据
* @return array
*/
protected function writeDataType(array $data): array
{
foreach ($data as $name => &$value) {
if (isset($this->type[$name])) {
// 类型转换
$value = $this->writeTransform($value, $this->type[$name]);
}
}
return $data;
}
/**
* 获取JSON字段属性值
* @access protected

View File

@ -136,7 +136,7 @@ trait RelationShip
public function relationQuery(array $relations, array $withRelationAttr = []): void
{
foreach ($relations as $key => $relation) {
$subRelation = '';
$subRelation = [];
$closure = null;
if ($relation instanceof Closure) {
@ -161,7 +161,7 @@ trait RelationShip
$relationResult->withAttr($withRelationAttr[$relationName]);
}
$this->relation[$relation] = $relationResult->getRelation($subRelation, $closure);
$this->relation[$relation] = $relationResult->getRelation((array) $subRelation, $closure);
}
}
@ -810,19 +810,20 @@ trait RelationShip
/**
* 自动关联数据删除(支持一对一及一对多关联)
* @access protected
* @param bool $force 强制删除
* @return void
*/
protected function autoRelationDelete(): void
protected function autoRelationDelete($force = false): void
{
foreach ($this->relationWrite as $key => $name) {
$name = is_numeric($key) ? $name : $key;
$result = $this->getRelation($name, true);
if ($result instanceof Model) {
$result->delete();
$result->force($force)->delete();
} elseif ($result instanceof Collection) {
foreach ($result as $model) {
$model->delete();
$model->force($force)->delete();
}
}
}

View File

@ -107,9 +107,10 @@ trait SoftDelete
return false;
}
$name = $this->getDeleteTimeField();
$name = $this->getDeleteTimeField();
$force = $this->isForce();
if ($name && !$this->isForce()) {
if ($name && !$force) {
// 软删除
$this->set($name, $this->autoWriteTimestamp($name));
@ -131,7 +132,7 @@ trait SoftDelete
// 关联删除
if (!empty($this->relationWrite)) {
$this->autoRelationDelete();
$this->autoRelationDelete($force);
}
$this->trigger('AfterDelete');

View File

@ -41,6 +41,12 @@ class MorphOne extends Relation
*/
protected $type;
/**
* 绑定的关联属性
* @var array
*/
protected $bindAttr = [];
/**
* 构造函数
* @access public
@ -78,6 +84,11 @@ class MorphOne extends Relation
$relationModel = $this->query->relation($subRelation)->find();
if ($relationModel) {
if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($this->parent, $relationModel);
}
$relationModel->setParent(clone $this->parent);
}
@ -154,7 +165,13 @@ class MorphOne extends Relation
$relationModel->exists(true);
}
$result->setRelation($relation, $relationModel);
if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($result, $relationModel);
} else {
// 设置关联属性
$result->setRelation($relation, $relationModel);
}
}
}
}
@ -188,7 +205,13 @@ class MorphOne extends Relation
$relationModel = null;
}
$result->setRelation($relation, $relationModel);
if (!empty($this->bindAttr)) {
// 绑定关联属性
$this->bindAttr($result, $relationModel);
} else {
// 设置关联属性
$result->setRelation($relation, $relationModel);
}
}
}
@ -277,4 +300,48 @@ class MorphOne extends Relation
}
}
/**
* 绑定关联表的属性到父模型属性
* @access public
* @param array $attr 要绑定的属性列表
* @return $this
*/
public function bind(array $attr)
{
$this->bindAttr = $attr;
return $this;
}
/**
* 获取绑定属性
* @access public
* @return array
*/
public function getBindAttr(): array
{
return $this->bindAttr;
}
/**
* 绑定关联属性到父模型
* @access protected
* @param Model $result 父模型对象
* @param Model $model 关联模型对象
* @return void
* @throws Exception
*/
protected function bindAttr(Model $result, Model $model = null): void
{
foreach ($this->bindAttr as $key => $attr) {
$key = is_numeric($key) ? $attr : $key;
$value = $result->getOrigin($key);
if (!is_null($value)) {
throw new Exception('bind attr has exists:' . $key);
}
$result->setAttr($key, $model ? $model->$attr : null);
}
}
}

View File

@ -104,13 +104,14 @@ class ProcessService extends Service
/**
* 查询相关进程列表
* @param string $command 任务指令
* @param string $name 执行名称
* @return array
*/
public function query(string $command): array
public function query(string $command, $name = 'php.exe'): array
{
$list = [];
if ($this->iswin()) {
$lines = $this->exec('wmic process where name="php.exe" get processid,CommandLine', true);
$lines = $this->exec('wmic process where name="' . $name . '" get processid,CommandLine', true);
foreach ($lines as $line) if ($this->_issub($line, $command) !== false) {
$attr = explode(' ', $this->_space($line));
$list[] = ['pid' => array_pop($attr), 'cmd' => join(' ', $attr)];