mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]ComposerUpdate
This commit is contained in:
parent
fee0571070
commit
1e8e3798aa
@ -1,6 +1,6 @@
|
||||

|
||||
|
||||
ThinkPHP 5.1 —— 12载初心,你值得信赖的PHP框架
|
||||
ThinkPHP 5.1(LTS) —— 12载初心,你值得信赖的PHP框架
|
||||
===============
|
||||
|
||||
[](https://scrutinizer-ci.com/g/top-think/framework/?branch=5.1)
|
||||
@ -27,6 +27,7 @@ ThinkPHP5.1对底层架构做了进一步的改进,减少依赖,其主要特
|
||||
+ 中间件支持(`V5.1.6+`)
|
||||
+ 支持`Swoole`/`Workerman`运行(`V5.1.18+`)
|
||||
|
||||
官方已经正式宣布`5.1.27`版本为LTS版本。
|
||||
|
||||
### 废除的功能:
|
||||
|
||||
@ -36,6 +37,7 @@ ThinkPHP5.1对底层架构做了进一步的改进,减少依赖,其主要特
|
||||
|
||||
> ThinkPHP5.1的运行环境要求PHP5.6+。
|
||||
|
||||
|
||||
## 安装
|
||||
|
||||
使用composer安装
|
||||
|
@ -20,7 +20,7 @@ use think\route\Dispatch;
|
||||
*/
|
||||
class App extends Container
|
||||
{
|
||||
const VERSION = '5.1.27 LTS';
|
||||
const VERSION = '5.1.28 LTS';
|
||||
|
||||
/**
|
||||
* 当前模块路径
|
||||
|
@ -67,35 +67,6 @@ class Controller
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
|
||||
// 控制器中间件
|
||||
if ($this->middleware) {
|
||||
foreach ($this->middleware as $key => $val) {
|
||||
if (!is_int($key)) {
|
||||
$only = $except = null;
|
||||
|
||||
if (isset($val['only'])) {
|
||||
$only = array_map(function ($item) {
|
||||
return strtolower($item);
|
||||
}, $val['only']);
|
||||
} elseif (isset($val['except'])) {
|
||||
$except = array_map(function ($item) {
|
||||
return strtolower($item);
|
||||
}, $val['except']);
|
||||
}
|
||||
|
||||
if (isset($only) && !in_array($this->request->action(), $only)) {
|
||||
continue;
|
||||
} elseif (isset($except) && in_array($this->request->action(), $except)) {
|
||||
continue;
|
||||
} else {
|
||||
$val = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$this->app['middleware']->controller($val);
|
||||
}
|
||||
}
|
||||
|
||||
// 前置操作方法 即将废弃
|
||||
foreach ((array) $this->beforeActionList as $method => $options) {
|
||||
is_numeric($method) ?
|
||||
@ -108,6 +79,36 @@ class Controller
|
||||
protected function initialize()
|
||||
{}
|
||||
|
||||
// 注册控制器中间件
|
||||
public function registerMiddleware()
|
||||
{
|
||||
foreach ($this->middleware as $key => $val) {
|
||||
if (!is_int($key)) {
|
||||
$only = $except = null;
|
||||
|
||||
if (isset($val['only'])) {
|
||||
$only = array_map(function ($item) {
|
||||
return strtolower($item);
|
||||
}, $val['only']);
|
||||
} elseif (isset($val['except'])) {
|
||||
$except = array_map(function ($item) {
|
||||
return strtolower($item);
|
||||
}, $val['except']);
|
||||
}
|
||||
|
||||
if (isset($only) && !in_array($this->request->action(), $only)) {
|
||||
continue;
|
||||
} elseif (isset($except) && in_array($this->request->action(), $except)) {
|
||||
continue;
|
||||
} else {
|
||||
$val = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$this->app['middleware']->controller($val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 前置操作
|
||||
* @access protected
|
||||
|
@ -161,7 +161,7 @@ class Lang
|
||||
$range = $range ?: $this->range;
|
||||
|
||||
// 空参数返回所有定义
|
||||
if (empty($name)) {
|
||||
if (is_null($name)) {
|
||||
return $this->lang[$range];
|
||||
}
|
||||
|
||||
|
@ -205,26 +205,18 @@ class Log implements LoggerInterface
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($this->config['level'])) {
|
||||
// 获取全部日志
|
||||
$log = $this->log;
|
||||
if (!$this->app->isDebug() && isset($log['debug'])) {
|
||||
unset($log['debug']);
|
||||
$log = [];
|
||||
|
||||
foreach ($this->log as $level => $info) {
|
||||
if (!$this->app->isDebug() && 'debug' == $level) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($log as $level => $info) {
|
||||
if (empty($this->config['level']) || in_array($level, $this->config['level'])) {
|
||||
$log[$level] = $info;
|
||||
|
||||
$this->app['hook']->listen('log_level', [$level, $info]);
|
||||
}
|
||||
} else {
|
||||
// 记录允许级别
|
||||
$log = [];
|
||||
foreach ($this->config['level'] as $level) {
|
||||
if (isset($this->log[$level])) {
|
||||
$log[$level] = $this->log[$level];
|
||||
// 监听log_level
|
||||
$this->app['hook']->listen('log_level', [$level, $log[$level]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->driver->save($log, true);
|
||||
|
@ -348,12 +348,16 @@ class Url
|
||||
public function getRuleUrl($rule, &$vars = [], $allowDomain = '')
|
||||
{
|
||||
foreach ($rule as $item) {
|
||||
list($url, $pattern, $domain, $suffix) = $item;
|
||||
list($url, $pattern, $domain, $suffix, $method) = $item;
|
||||
|
||||
if (is_string($allowDomain) && $domain != $allowDomain) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->app['request']->port() != 80) {
|
||||
$domain .= ':' . $this->app['request']->port();
|
||||
}
|
||||
|
||||
if (empty($pattern)) {
|
||||
return [rtrim($url, '?/-'), $domain, $suffix];
|
||||
}
|
||||
|
@ -87,6 +87,8 @@ class Validate
|
||||
'min' => 'min size of :attribute must be :rule',
|
||||
'after' => ':attribute cannot be less than :rule',
|
||||
'before' => ':attribute cannot exceed :rule',
|
||||
'afterWith' => ':attribute cannot be less than :rule',
|
||||
'beforeWith' => ':attribute cannot exceed :rule',
|
||||
'expire' => ':attribute not within :rule',
|
||||
'allowIp' => 'access IP is not allowed',
|
||||
'denyIp' => 'access IP denied',
|
||||
@ -422,7 +424,7 @@ class Validate
|
||||
|
||||
// 字段验证
|
||||
if ($rule instanceof \Closure) {
|
||||
$result = call_user_func_array($rule, [$value, $data]);
|
||||
$result = call_user_func_array($rule, [$value, $data, $title, $this]);
|
||||
} elseif ($rule instanceof ValidateRule) {
|
||||
// 验证因子
|
||||
$result = $this->checkItem($key, $value, $rule->getRule(), $data, $rule->getTitle() ?: $title, $rule->getMsg());
|
||||
@ -1241,9 +1243,10 @@ class Validate
|
||||
* @access public
|
||||
* @param mixed $value 字段值
|
||||
* @param mixed $rule 验证规则
|
||||
* @param array $data 数据
|
||||
* @return bool
|
||||
*/
|
||||
public function after($value, $rule)
|
||||
public function after($value, $rule, $data)
|
||||
{
|
||||
return strtotime($value) >= strtotime($rule);
|
||||
}
|
||||
@ -1253,13 +1256,42 @@ class Validate
|
||||
* @access public
|
||||
* @param mixed $value 字段值
|
||||
* @param mixed $rule 验证规则
|
||||
* @param array $data 数据
|
||||
* @return bool
|
||||
*/
|
||||
public function before($value, $rule)
|
||||
public function before($value, $rule, $data)
|
||||
{
|
||||
return strtotime($value) <= strtotime($rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证日期字段
|
||||
* @access protected
|
||||
* @param mixed $value 字段值
|
||||
* @param mixed $rule 验证规则
|
||||
* @param array $data 数据
|
||||
* @return bool
|
||||
*/
|
||||
protected function afterWith($value, $rule, $data)
|
||||
{
|
||||
$rule = $this->getDataValue($data, $rule);
|
||||
return !is_null($rule) && strtotime($value) >= strtotime($rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证日期字段
|
||||
* @access protected
|
||||
* @param mixed $value 字段值
|
||||
* @param mixed $rule 验证规则
|
||||
* @param array $data 数据
|
||||
* @return bool
|
||||
*/
|
||||
protected function beforeWith($value, $rule, $data)
|
||||
{
|
||||
$rule = $this->getDataValue($data, $rule);
|
||||
return !is_null($rule) && strtotime($value) <= strtotime($rule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证有效期
|
||||
* @access public
|
||||
|
@ -1314,7 +1314,11 @@ abstract class Connection
|
||||
*/
|
||||
public function aggregate(Query $query, $aggregate, $field)
|
||||
{
|
||||
$field = $aggregate . '(' . $this->builder->parseKey($query, $field, true) . ') AS tp_' . strtolower($aggregate);
|
||||
if (0 === stripos($field, 'DISTINCT ')) {
|
||||
list($distinct, $field) = explode(' ', $field);
|
||||
}
|
||||
|
||||
$field = $aggregate . '(' . (!empty($distinct) ? 'DISTINCT ' : '') . $this->builder->parseKey($query, $field, true) . ') AS tp_' . strtolower($aggregate);
|
||||
|
||||
return $this->value($query, $field, 0);
|
||||
}
|
||||
|
@ -2650,7 +2650,8 @@ class Query
|
||||
}
|
||||
|
||||
foreach ($relations as $key => $relation) {
|
||||
$closure = null;
|
||||
$closure = $aggregateField = null;
|
||||
|
||||
if ($relation instanceof \Closure) {
|
||||
$closure = $relation;
|
||||
$relation = $key;
|
||||
@ -2659,14 +2660,15 @@ class Query
|
||||
$relation = $key;
|
||||
}
|
||||
|
||||
if (!isset($aggregateField)) {
|
||||
$relation = Loader::parseName($relation, 1, false);
|
||||
|
||||
$count = $this->model->$relation()->getRelationCountQuery($closure, $aggregate, $field, $aggregateField);
|
||||
|
||||
if (empty($aggregateField)) {
|
||||
$aggregateField = Loader::parseName($relation) . '_' . $aggregate;
|
||||
}
|
||||
|
||||
$relation = Loader::parseName($relation, 1, false);
|
||||
$count = '(' . $this->model->$relation()->getRelationCountQuery($closure, $aggregate, $field) . ')';
|
||||
|
||||
$this->field([$count => $aggregateField]);
|
||||
$this->field(['(' . $count . ')' => $aggregateField]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ abstract class Relation
|
||||
|
||||
$result = call_user_func_array([$this->query->getModel(), $method], $args);
|
||||
|
||||
return $result === $this->query ? $this : $result;
|
||||
return $result === $this->query && !in_array(strtolower($method), ['fetchsql', 'fetchpdo']) ? $this : $result;
|
||||
} else {
|
||||
throw new Exception('method not exists:' . __CLASS__ . '->' . $method);
|
||||
}
|
||||
|
@ -327,6 +327,8 @@ trait Attribute
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
$value = $this->$method($value, array_merge($this->data, $data));
|
||||
|
||||
$this->set[$name] = true;
|
||||
} elseif (isset($this->type[$name])) {
|
||||
// 类型转换
|
||||
$value = $this->writeTransform($value, $this->type[$name]);
|
||||
@ -335,7 +337,6 @@ trait Attribute
|
||||
|
||||
// 设置数据对象属性
|
||||
$this->data[$name] = $value;
|
||||
$this->set[$name] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -309,7 +309,7 @@ trait RelationShip
|
||||
public function relationCount(&$result, $relations, $aggregate = 'sum', $field = '*')
|
||||
{
|
||||
foreach ($relations as $key => $relation) {
|
||||
$closure = null;
|
||||
$closure = $name = null;
|
||||
|
||||
if ($relation instanceof \Closure) {
|
||||
$closure = $relation;
|
||||
@ -320,9 +320,10 @@ trait RelationShip
|
||||
}
|
||||
|
||||
$relation = Loader::parseName($relation, 1, false);
|
||||
$count = $this->$relation()->relationCount($result, $closure, $aggregate, $field);
|
||||
|
||||
if (!isset($name)) {
|
||||
$count = $this->$relation()->relationCount($result, $closure, $aggregate, $field, $name);
|
||||
|
||||
if (empty($name)) {
|
||||
$name = Loader::parseName($relation) . '_' . $aggregate;
|
||||
}
|
||||
|
||||
|
@ -74,12 +74,17 @@ class BelongsTo extends OneToOne
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $aggregateAlias 聚合字段别名
|
||||
* @return string
|
||||
*/
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*')
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*', &$aggregateAlias = '')
|
||||
{
|
||||
if ($closure) {
|
||||
$closure($this->query);
|
||||
$return = $closure($this->query);
|
||||
|
||||
if ($return && is_string($return)) {
|
||||
$aggregateAlias = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->query
|
||||
@ -88,6 +93,37 @@ class BelongsTo extends OneToOne
|
||||
->$aggregate($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联统计
|
||||
* @access public
|
||||
* @param Model $result 数据对象
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $name 统计字段别名
|
||||
* @return integer
|
||||
*/
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '')
|
||||
{
|
||||
$foreignKey = $this->foreignKey;
|
||||
|
||||
if (!isset($result->$foreignKey)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($closure) {
|
||||
$return = $closure($this->query);
|
||||
|
||||
if ($resturn && is_string($return)) {
|
||||
$name = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->query
|
||||
->where($this->localKey, '=', $result->$foreignKey)
|
||||
->$aggregate($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关联条件查询当前模型
|
||||
* @access public
|
||||
@ -228,10 +264,7 @@ class BelongsTo extends OneToOne
|
||||
*/
|
||||
public function associate($model)
|
||||
{
|
||||
$foreignKey = $this->foreignKey;
|
||||
$pk = $model->getPk();
|
||||
|
||||
$this->parent->setAttr($foreignKey, $model->$pk);
|
||||
$this->parent->setAttr($this->foreignKey, $model->getKey());
|
||||
$this->parent->save();
|
||||
|
||||
return $this->parent->setRelation($this->relation, $model);
|
||||
@ -244,9 +277,7 @@ class BelongsTo extends OneToOne
|
||||
*/
|
||||
public function dissociate()
|
||||
{
|
||||
$foreignKey = $this->foreignKey;
|
||||
|
||||
$this->parent->setAttr($foreignKey, null);
|
||||
$this->parent->setAttr($this->foreignKey, null);
|
||||
$this->parent->save();
|
||||
|
||||
return $this->parent->setRelation($this->relation, null);
|
||||
|
@ -25,6 +25,8 @@ class BelongsToMany extends Relation
|
||||
protected $middle;
|
||||
// 中间表模型名称
|
||||
protected $pivotName;
|
||||
// 中间表数据名称
|
||||
protected $pivotDataName = 'pivot';
|
||||
// 中间表模型对象
|
||||
protected $pivot;
|
||||
|
||||
@ -67,6 +69,18 @@ class BelongsToMany extends Relation
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置中间表数据名称
|
||||
* @access public
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function pivotDataName($name)
|
||||
{
|
||||
$this->pivotDataName = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取中间表更新条件
|
||||
* @param $data
|
||||
@ -121,7 +135,7 @@ class BelongsToMany extends Relation
|
||||
}
|
||||
}
|
||||
|
||||
$model->setRelation('pivot', $this->newPivot($pivot, true));
|
||||
$model->setRelation($this->pivotDataName, $this->newPivot($pivot, true));
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,21 +364,30 @@ class BelongsToMany extends Relation
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $name 统计字段别名
|
||||
* @return integer
|
||||
*/
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*')
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '')
|
||||
{
|
||||
$pk = $result->getPk();
|
||||
$count = 0;
|
||||
$pk = $result->getPk();
|
||||
|
||||
if (isset($result->$pk)) {
|
||||
$pk = $result->$pk;
|
||||
$count = $this->belongsToManyQuery($this->foreignKey, $this->localKey, [
|
||||
['pivot.' . $this->localKey, '=', $pk],
|
||||
])->$aggregate($field);
|
||||
if (!isset($result->$pk)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $count;
|
||||
$pk = $result->$pk;
|
||||
|
||||
if ($closure) {
|
||||
$return = $closure($this->query);
|
||||
|
||||
if ($return && is_string($return)) {
|
||||
$name = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->belongsToManyQuery($this->foreignKey, $this->localKey, [
|
||||
['pivot.' . $this->localKey, '=', $pk],
|
||||
])->$aggregate($field);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -373,10 +396,19 @@ class BelongsToMany extends Relation
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @return string
|
||||
* @param string $aggregateAlias 聚合字段别名
|
||||
* @return array
|
||||
*/
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*')
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*', &$aggregateAlias = '')
|
||||
{
|
||||
if ($closure) {
|
||||
$return = $closure($this->query);
|
||||
|
||||
if ($return && is_string($return)) {
|
||||
$aggregateAlias = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->belongsToManyQuery($this->foreignKey, $this->localKey, [
|
||||
[
|
||||
'pivot.' . $this->localKey, 'exp', $this->query->raw('=' . $this->parent->getTable() . '.' . $this->parent->getPk()),
|
||||
@ -396,7 +428,11 @@ class BelongsToMany extends Relation
|
||||
protected function eagerlyManyToMany($where, $relation, $subRelation = '', $closure = null)
|
||||
{
|
||||
// 预载入关联查询 支持嵌套预载入
|
||||
$list = $this->belongsToManyQuery($this->foreignKey, $this->localKey, $where, $closure)
|
||||
if ($closure) {
|
||||
$closure($this->query);
|
||||
}
|
||||
|
||||
$list = $this->belongsToManyQuery($this->foreignKey, $this->localKey, $where)
|
||||
->with($subRelation)
|
||||
->select();
|
||||
|
||||
@ -414,7 +450,7 @@ class BelongsToMany extends Relation
|
||||
}
|
||||
}
|
||||
|
||||
$set->setRelation('pivot', $this->newPivot($pivot, true));
|
||||
$set->setRelation($this->pivotDataName, $this->newPivot($pivot, true));
|
||||
|
||||
$data[$pivot[$this->localKey]][] = $set;
|
||||
}
|
||||
@ -428,15 +464,10 @@ class BelongsToMany extends Relation
|
||||
* @param string $foreignKey 关联模型关联键
|
||||
* @param string $localKey 当前模型关联键
|
||||
* @param array $condition 关联查询条件
|
||||
* @param \Closure $closure 闭包
|
||||
* @return Query
|
||||
*/
|
||||
protected function belongsToManyQuery($foreignKey, $localKey, $condition = [], $closure = null)
|
||||
protected function belongsToManyQuery($foreignKey, $localKey, $condition = [])
|
||||
{
|
||||
if ($closure) {
|
||||
$closure($this->query);
|
||||
}
|
||||
|
||||
// 关联查询封装
|
||||
$tableName = $this->query->getTable();
|
||||
$table = $this->pivot->getTable();
|
||||
@ -543,6 +574,29 @@ class BelongsToMany extends Relation
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在关联数据
|
||||
* @access public
|
||||
* @param mixed $data 数据 可以使用关联模型对象 或者 关联对象的主键
|
||||
* @return Pivot
|
||||
* @throws Exception
|
||||
*/
|
||||
public function attached($data)
|
||||
{
|
||||
if ($data instanceof Model) {
|
||||
$id = $data->getKey();
|
||||
} else {
|
||||
$id = $data;
|
||||
}
|
||||
|
||||
$pivot = $this->pivot
|
||||
->where($this->localKey, $this->parent->getKey())
|
||||
->where($this->foreignKey, $id)
|
||||
->find();
|
||||
|
||||
return $pivot ?: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解除关联的一个中间表数据
|
||||
* @access public
|
||||
|
@ -152,22 +152,27 @@ class HasMany extends Relation
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $name 统计字段别名
|
||||
* @return integer
|
||||
*/
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*')
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '')
|
||||
{
|
||||
$localKey = $this->localKey;
|
||||
$count = 0;
|
||||
|
||||
if (isset($result->$localKey)) {
|
||||
if ($closure) {
|
||||
$closure($this->query);
|
||||
}
|
||||
|
||||
$count = $this->query->where($this->foreignKey, '=', $result->$localKey)->$aggregate($field);
|
||||
if (!isset($result->$localKey)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $count;
|
||||
if ($closure) {
|
||||
$return = $closure($this->query);
|
||||
if ($resturn && is_string($return)) {
|
||||
$name = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->query
|
||||
->where($this->foreignKey, '=', $result->$localKey)
|
||||
->$aggregate($field);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,12 +181,17 @@ class HasMany extends Relation
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $aggregateAlias 聚合字段别名
|
||||
* @return string
|
||||
*/
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*')
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*', &$aggregateAlias = '')
|
||||
{
|
||||
if ($closure) {
|
||||
$closure($this->query);
|
||||
$return = $closure($this->query);
|
||||
|
||||
if ($return && is_string($return)) {
|
||||
$aggregateAlias = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->query
|
||||
|
@ -120,9 +120,10 @@ class HasManyThrough extends Relation
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $name 统计字段别名
|
||||
* @return integer
|
||||
*/
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*')
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '')
|
||||
{}
|
||||
|
||||
/**
|
||||
|
@ -74,12 +74,17 @@ class HasOne extends OneToOne
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $aggregateAlias 聚合字段别名
|
||||
* @return string
|
||||
*/
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*')
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*', &$aggregateAlias = '')
|
||||
{
|
||||
if ($closure) {
|
||||
$closure($this->query);
|
||||
$return = $closure($this->query);
|
||||
|
||||
if ($return && is_string($return)) {
|
||||
$aggregateAlias = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->query
|
||||
@ -88,6 +93,36 @@ class HasOne extends OneToOne
|
||||
->$aggregate($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联统计
|
||||
* @access public
|
||||
* @param Model $result 数据对象
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $name 统计字段别名
|
||||
* @return integer
|
||||
*/
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '')
|
||||
{
|
||||
$localKey = $this->localKey;
|
||||
|
||||
if (!isset($result->$localKey)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($closure) {
|
||||
$return = $closure($this->query);
|
||||
if ($resturn && is_string($return)) {
|
||||
$name = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->query
|
||||
->where($this->foreignKey, '=', $result->$localKey)
|
||||
->$aggregate($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据关联条件查询当前模型
|
||||
* @access public
|
||||
|
@ -186,27 +186,31 @@ class MorphMany extends Relation
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $name 统计字段别名
|
||||
* @return integer
|
||||
*/
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*')
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '')
|
||||
{
|
||||
$pk = $result->getPk();
|
||||
$count = 0;
|
||||
$pk = $result->getPk();
|
||||
|
||||
if (isset($result->$pk)) {
|
||||
if ($closure) {
|
||||
$closure($this->query);
|
||||
}
|
||||
|
||||
$count = $this->query
|
||||
->where([
|
||||
[$this->morphKey, '=', $result->$pk],
|
||||
[$this->morphType, '=', $this->type],
|
||||
])
|
||||
->$aggregate($field);
|
||||
if (!isset($result->$pk)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $count;
|
||||
if ($closure) {
|
||||
$return = $closure($this->query);
|
||||
|
||||
if ($return && is_string($return)) {
|
||||
$name = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->query
|
||||
->where([
|
||||
[$this->morphKey, '=', $result->$pk],
|
||||
[$this->morphType, '=', $this->type],
|
||||
])
|
||||
->$aggregate($field);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,12 +219,17 @@ class MorphMany extends Relation
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $aggregateAlias 聚合字段别名
|
||||
* @return string
|
||||
*/
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*')
|
||||
public function getRelationCountQuery($closure, $aggregate = 'count', $field = '*', &$aggregateAlias = '')
|
||||
{
|
||||
if ($closure) {
|
||||
$closure($this->query);
|
||||
$return = $closure($this->query);
|
||||
|
||||
if ($return && is_string($return)) {
|
||||
$aggregateAlias = $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->query
|
||||
|
@ -238,9 +238,10 @@ class MorphTo extends Relation
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @param string $name 统计字段别名
|
||||
* @return integer
|
||||
*/
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*')
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '')
|
||||
{}
|
||||
|
||||
/**
|
||||
|
@ -236,20 +236,6 @@ abstract class OneToOne extends Relation
|
||||
return $this->bindAttr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联统计
|
||||
* @access public
|
||||
* @param Model $result 数据对象
|
||||
* @param \Closure $closure 闭包
|
||||
* @param string $aggregate 聚合查询方法
|
||||
* @param string $field 字段
|
||||
* @return integer
|
||||
*/
|
||||
public function relationCount($result, $closure, $aggregate = 'count', $field = '*')
|
||||
{
|
||||
throw new Exception('relation not support: ' . $aggregate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 一对一 关联模型预查询拼装
|
||||
* @access public
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace think\route\dispatch;
|
||||
|
||||
use ReflectionMethod;
|
||||
use think\Controller;
|
||||
use think\exception\ClassNotFoundException;
|
||||
use think\exception\HttpException;
|
||||
use think\Loader;
|
||||
@ -91,6 +92,10 @@ class Module extends Dispatch
|
||||
$this->rule->getConfig('url_controller_layer'),
|
||||
$this->rule->getConfig('controller_suffix'),
|
||||
$this->rule->getConfig('empty_controller'));
|
||||
|
||||
if ($instance instanceof Controller) {
|
||||
$instance->registerMiddleware();
|
||||
}
|
||||
} catch (ClassNotFoundException $e) {
|
||||
throw new HttpException(404, 'controller not exists:' . $e->getClass());
|
||||
}
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInite4f62b825d40d3e077bb16351eabf2a4::getLoader();
|
||||
return ComposerAutoloaderInite9f61c7f17c1efc184e83ad53ffe6a75::getLoader();
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInite4f62b825d40d3e077bb16351eabf2a4
|
||||
class ComposerAutoloaderInite9f61c7f17c1efc184e83ad53ffe6a75
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -19,15 +19,15 @@ class ComposerAutoloaderInite4f62b825d40d3e077bb16351eabf2a4
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInite4f62b825d40d3e077bb16351eabf2a4', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInite9f61c7f17c1efc184e83ad53ffe6a75', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite4f62b825d40d3e077bb16351eabf2a4', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite9f61c7f17c1efc184e83ad53ffe6a75', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require_once __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite4f62b825d40d3e077bb16351eabf2a4::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite9f61c7f17c1efc184e83ad53ffe6a75::getInitializer($loader));
|
||||
} else {
|
||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||
foreach ($map as $namespace => $path) {
|
||||
@ -48,19 +48,19 @@ class ComposerAutoloaderInite4f62b825d40d3e077bb16351eabf2a4
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInite4f62b825d40d3e077bb16351eabf2a4::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInite9f61c7f17c1efc184e83ad53ffe6a75::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequiree4f62b825d40d3e077bb16351eabf2a4($fileIdentifier, $file);
|
||||
composerRequiree9f61c7f17c1efc184e83ad53ffe6a75($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequiree4f62b825d40d3e077bb16351eabf2a4($fileIdentifier, $file)
|
||||
function composerRequiree9f61c7f17c1efc184e83ad53ffe6a75($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInite4f62b825d40d3e077bb16351eabf2a4
|
||||
class ComposerStaticInite9f61c7f17c1efc184e83ad53ffe6a75
|
||||
{
|
||||
public static $files = array (
|
||||
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
|
||||
@ -303,9 +303,9 @@ class ComposerStaticInite4f62b825d40d3e077bb16351eabf2a4
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite4f62b825d40d3e077bb16351eabf2a4::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite4f62b825d40d3e077bb16351eabf2a4::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite4f62b825d40d3e077bb16351eabf2a4::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite9f61c7f17c1efc184e83ad53ffe6a75::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite9f61c7f17c1efc184e83ad53ffe6a75::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite9f61c7f17c1efc184e83ad53ffe6a75::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
12
vendor/composer/installed.json
vendored
12
vendor/composer/installed.json
vendored
@ -50,17 +50,17 @@
|
||||
},
|
||||
{
|
||||
"name": "topthink/framework",
|
||||
"version": "v5.1.27",
|
||||
"version_normalized": "5.1.27.0",
|
||||
"version": "v5.1.28",
|
||||
"version_normalized": "5.1.28.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/top-think/framework.git",
|
||||
"reference": "f607b8fd51cc25e4da7e2f4ef0d5e64f390d36bd"
|
||||
"reference": "8102ec96136a66f926bae89faea540b91687de37"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/f607b8fd51cc25e4da7e2f4ef0d5e64f390d36bd",
|
||||
"reference": "f607b8fd51cc25e4da7e2f4ef0d5e64f390d36bd",
|
||||
"url": "https://api.github.com/repos/top-think/framework/zipball/8102ec96136a66f926bae89faea540b91687de37",
|
||||
"reference": "8102ec96136a66f926bae89faea540b91687de37",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@ -82,7 +82,7 @@
|
||||
"sebastian/phpcpd": "2.*",
|
||||
"squizlabs/php_codesniffer": "2.*"
|
||||
},
|
||||
"time": "2018-10-22T02:10:08+00:00",
|
||||
"time": "2018-10-28T12:24:29+00:00",
|
||||
"type": "think-framework",
|
||||
"installation-source": "dist",
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
|
Loading…
x
Reference in New Issue
Block a user