📦 更新thinkphp(v5.1.37.1)

This commit is contained in:
Wisp X
2019-08-03 23:59:37 +08:00
parent 0330b3dc88
commit 4ccf046521
59 changed files with 1065 additions and 610 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ use think\route\Dispatch;
*/
class App extends Container
{
const VERSION = '5.1.36 LTS';
const VERSION = '5.1.37 LTS';
/**
* 当前模块路径
+9 -4
View File
@@ -487,12 +487,17 @@ class Console
public function getNamespaces()
{
$namespaces = [];
foreach ($this->commands as $command) {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
foreach ($this->commands as $name => $command) {
if (is_string($command)) {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($name));
} else {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
foreach ($command->getAliases() as $alias) {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
foreach ($command->getAliases() as $alias) {
$namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
}
}
}
return array_values(array_unique(array_filter($namespaces)));
+1 -1
View File
@@ -571,7 +571,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$this->autoRelationUpdate();
}
return false;
return true;
} elseif ($this->autoWriteTimestamp && $this->updateTime && !isset($data[$this->updateTime])) {
// 自动写入更新时间
$data[$this->updateTime] = $this->autoWriteTimestamp($this->updateTime);
+1 -1
View File
@@ -519,7 +519,7 @@ class Validate
if (isset($this->append[$field])) {
// 追加额外的验证规则
$rules = array_unique(array_merge($rules, $this->append[$field]));
$rules = array_unique(array_merge($rules, $this->append[$field]), SORT_REGULAR);
}
$i = 0;
-2
View File
@@ -249,7 +249,6 @@ abstract class Driver
{
if ($this->tag) {
$key = $this->getTagkey($this->tag);
$prev = $this->tag;
$this->tag = null;
if ($this->has($key)) {
@@ -266,7 +265,6 @@ abstract class Driver
}
$this->set($key, $value, 0);
$this->tag = $prev;
}
}
+1 -5
View File
@@ -267,10 +267,6 @@ class Redis extends Driver
protected function getTagItem($tag)
{
$tagName = $this->getTagKey($tag);
$keys = $this->handler->sMembers($tagName);
return array_map(function ($key) {
return $this->getCacheKey($key);
}, $keys);
return $this->handler->sMembers($tagName);
}
}
+7 -6
View File
@@ -1512,6 +1512,7 @@ class Query
{
if ($field instanceof $this) {
$this->options['where'] = $field->getOptions('where');
$this->bind($field->getBind(false));
return $this;
}
@@ -2197,12 +2198,12 @@ class Query
}
/**
* 设置需要追加输出属性
* 设置需要附加的输出属性
* @access public
* @param array $append 需要追加的属性
* @param array $append 属性列表
* @return $this
*/
public function append(array $append)
public function append(array $append = [])
{
$this->options['append'] = $append;
return $this;
@@ -3355,13 +3356,13 @@ class Query
// 输出属性控制
if (!empty($options['visible'])) {
$result->visible($options['visible']);
$result->visible($options['visible'], true);
} elseif (!empty($options['hidden'])) {
$result->hidden($options['hidden']);
$result->hidden($options['hidden'], true);
}
if (!empty($options['append'])) {
$result->append($options['append']);
$result->append($options['append'], true);
}
// 关联查询
+4 -2
View File
@@ -24,8 +24,10 @@ class Collection extends BaseCollection
*/
public function load($relation)
{
$item = current($this->items);
$item->eagerlyResultSet($this->items, $relation);
if (!$this->isEmpty()) {
$item = current($this->items);
$item->eagerlyResultSet($this->items, $relation);
}
return $this;
}
+21
View File
@@ -58,6 +58,16 @@ abstract class Relation
return $this->query->getModel();
}
/**
* 获取当前的关联模型类的实例
* @access public
* @return Query
*/
public function getQuery()
{
return $this->query;
}
/**
* 设置当前关联为自关联
* @access public
@@ -129,6 +139,17 @@ abstract class Relation
}
}
/**
* 更新数据
* @access public
* @param array $data 更新数据
* @return integer|string
*/
public function update(array $data = [])
{
return $this->query->update($data);
}
/**
* 删除记录
* @access public
@@ -327,9 +327,13 @@ trait Attribute
$method = 'set' . Loader::parseName($name, 1) . 'Attr';
if (method_exists($this, $method)) {
$value = $this->$method($value, array_merge($this->data, $data));
$origin = $this->data;
$value = $this->$method($value, array_merge($this->data, $data));
$this->set[$name] = true;
if (is_null($value) && $origin !== $this->data) {
return;
}
} elseif (isset($this->type[$name])) {
// 类型转换
$value = $this->writeTransform($value, $this->type[$name]);
@@ -164,13 +164,15 @@ trait Conversion
foreach ($data as $key => $val) {
if ($val instanceof Model || $val instanceof ModelCollection) {
// 关联模型对象
if (isset($this->visible[$key])) {
if (isset($this->visible[$key]) && is_array($this->visible[$key])) {
$val->visible($this->visible[$key]);
} elseif (isset($this->hidden[$key])) {
} elseif (isset($this->hidden[$key]) && is_array($this->hidden[$key])) {
$val->hidden($this->hidden[$key]);
}
// 关联模型对象
$item[$key] = $val->toArray();
if (!isset($this->hidden[$key]) || true !== $this->hidden[$key]) {
$item[$key] = $val->toArray();
}
} elseif (isset($this->visible[$key])) {
$item[$key] = $this->getAttr($key);
} elseif (!isset($this->hidden[$key]) && !$hasVisible) {
@@ -204,7 +204,7 @@ trait RelationShip
$relationResult = $this->$method();
if (isset($withRelationAttr[$relationName])) {
$relationResult->withAttr($withRelationAttr[$relationName]);
$relationResult->getQuery()->withAttr($withRelationAttr[$relationName]);
}
$this->relation[$relation] = $relationResult->getRelation($subRelation, $closure);
@@ -248,7 +248,7 @@ trait RelationShip
$relationResult = $this->$relation();
if (isset($withRelationAttr[$relationName])) {
$relationResult->withAttr($withRelationAttr[$relationName]);
$relationResult->getQuery()->withAttr($withRelationAttr[$relationName]);
}
$relationResult->eagerlyResultSet($resultSet, $relation, $subRelation, $closure, $join);
@@ -290,7 +290,7 @@ trait RelationShip
$relationResult = $this->$relation();
if (isset($withRelationAttr[$relationName])) {
$relationResult->withAttr($withRelationAttr[$relationName]);
$relationResult->getQuery()->withAttr($withRelationAttr[$relationName]);
}
$relationResult->eagerlyResult($result, $relation, $subRelation, $closure, $join);
+13 -4
View File
@@ -642,17 +642,26 @@ abstract class Rule
protected function checkCrossDomain($request)
{
if (!empty($this->option['cross_domain'])) {
$header = [
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE',
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE',
'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
];
if (!empty($this->option['header'])) {
$header = array_merge($header, $this->option['header']);
}
if (!isset($header['Access-Control-Allow-Origin'])) {
$httpOrigin = $request->header('origin');
if ($httpOrigin && strpos(config('cookie.domain'), $httpOrigin)) {
$header['Access-Control-Allow-Origin'] = $httpOrigin;
} else {
$header['Access-Control-Allow-Origin'] = '*';
}
}
$this->option['header'] = $header;
if ($request->method(true) == 'OPTIONS') {
+1 -1
View File
@@ -118,8 +118,8 @@ class RuleGroup extends Rule
*/
public function check($request, $url, $completeMatch = false)
{
// 跨域OPTIONS请求
if ($dispatch = $this->checkCrossDomain($request)) {
// 跨域OPTIONS请求
return $dispatch;
}
+9 -5
View File
@@ -149,11 +149,6 @@ class RuleItem extends Rule
*/
public function checkRule($request, $url, $match = null, $completeMatch = false)
{
if ($dispatch = $this->checkCrossDomain($request)) {
// 允许跨域
return $dispatch;
}
// 检查参数有效性
if (!$this->checkOption($this->option, $request)) {
return false;
@@ -169,6 +164,15 @@ class RuleItem extends Rule
}
if (false !== $match) {
if (!empty($option['cross_domain'])) {
if ($dispatch = $this->checkCrossDomain($request)) {
// 允许跨域
return $dispatch;
}
$option['header'] = $this->option['header'];
}
// 检查前置行为
if (isset($option['before']) && false === $this->checkBefore($option['before'])) {
return false;