升级基础框架,Tp到5.0.7

This commit is contained in:
邹景立 2017-03-06 12:02:57 +08:00
parent 9a775341b3
commit d31f5def04
77 changed files with 670 additions and 269 deletions

42
composer.lock generated
View File

@ -17,7 +17,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/ivanlanin/pclzip/19dd1de9d3f5fc4d7d70175b4c344dee329f45fd.zip", "url": "https://files.phpcomposer.com/files/ivanlanin/pclzip/19dd1de9d3f5fc4d7d70175b4c344dee329f45fd.zip",
"reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd", "reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd",
"shasum": "" "shasum": ""
}, },
@ -54,7 +54,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/qiniu/php-sdk/b91653485e36b4797d7a302cc86c49695e47a642.zip", "url": "https://files.phpcomposer.com/files/qiniu/php-sdk/b91653485e36b4797d7a302cc86c49695e47a642.zip",
"reference": "b91653485e36b4797d7a302cc86c49695e47a642", "reference": "b91653485e36b4797d7a302cc86c49695e47a642",
"shasum": "" "shasum": ""
}, },
@ -97,16 +97,16 @@
}, },
{ {
"name": "topthink/framework", "name": "topthink/framework",
"version": "v5.0.6", "version": "v5.0.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/framework.git", "url": "https://github.com/top-think/framework.git",
"reference": "a3a37e6cfad132d5b02ffff8f23a4abc565f7928" "reference": "bcf64f19f4fadbff6c8503891689ff7e6f2fe9a3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/framework/a3a37e6cfad132d5b02ffff8f23a4abc565f7928.zip", "url": "https://files.phpcomposer.com/files/top-think/framework/bcf64f19f4fadbff6c8503891689ff7e6f2fe9a3.zip",
"reference": "a3a37e6cfad132d5b02ffff8f23a4abc565f7928", "reference": "bcf64f19f4fadbff6c8503891689ff7e6f2fe9a3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -144,7 +144,7 @@
"orm", "orm",
"thinkphp" "thinkphp"
], ],
"time": "2017-02-07 09:39:59" "time": "2017-02-25 02:51:57"
}, },
{ {
"name": "topthink/think-captcha", "name": "topthink/think-captcha",
@ -156,7 +156,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-captcha/0c55455df26a1626a60d0dc35d2d89002b741d44.zip", "url": "https://files.phpcomposer.com/files/top-think/think-captcha/0c55455df26a1626a60d0dc35d2d89002b741d44.zip",
"reference": "0c55455df26a1626a60d0dc35d2d89002b741d44", "reference": "0c55455df26a1626a60d0dc35d2d89002b741d44",
"shasum": "" "shasum": ""
}, },
@ -192,7 +192,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-helper/ed64408cdc4cdbd390365ba0906d208b987af520.zip", "url": "https://files.phpcomposer.com/files/top-think/think-helper/ed64408cdc4cdbd390365ba0906d208b987af520.zip",
"reference": "ed64408cdc4cdbd390365ba0906d208b987af520", "reference": "ed64408cdc4cdbd390365ba0906d208b987af520",
"shasum": "" "shasum": ""
}, },
@ -228,7 +228,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-installer/4c6e1ebecd1afce3f4ccc47e147d61bbe1bf641d.zip", "url": "https://files.phpcomposer.com/files/top-think/think-installer/4c6e1ebecd1afce3f4ccc47e147d61bbe1bf641d.zip",
"reference": "4c6e1ebecd1afce3f4ccc47e147d61bbe1bf641d", "reference": "4c6e1ebecd1afce3f4ccc47e147d61bbe1bf641d",
"shasum": "" "shasum": ""
}, },
@ -261,16 +261,16 @@
}, },
{ {
"name": "topthink/think-mongo", "name": "topthink/think-mongo",
"version": "v1.5", "version": "v1.6",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/think-mongo.git", "url": "https://github.com/top-think/think-mongo.git",
"reference": "2dd7ecae965cd3a6e5cc99f3db7c63353dae4cf3" "reference": "1c6d29f58bd7caa8da088c167b4e65ddac621588"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-mongo/2dd7ecae965cd3a6e5cc99f3db7c63353dae4cf3.zip", "url": "https://files.phpcomposer.com/files/top-think/think-mongo/1c6d29f58bd7caa8da088c167b4e65ddac621588.zip",
"reference": "2dd7ecae965cd3a6e5cc99f3db7c63353dae4cf3", "reference": "1c6d29f58bd7caa8da088c167b4e65ddac621588",
"shasum": "" "shasum": ""
}, },
"type": "library", "type": "library",
@ -291,20 +291,20 @@
} }
], ],
"description": "mongodb driver for thinkphp5", "description": "mongodb driver for thinkphp5",
"time": "2017-02-06 06:05:55" "time": "2017-02-13 07:17:51"
}, },
{ {
"name": "topthink/think-queue", "name": "topthink/think-queue",
"version": "v1.1.2", "version": "v1.1.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/think-queue.git", "url": "https://github.com/top-think/think-queue.git",
"reference": "503c5b809585ca60cba9485a233aa8be4b22c990" "reference": "07480c36381344bef9db9c9bbe3de28005a839d3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-queue/503c5b809585ca60cba9485a233aa8be4b22c990.zip", "url": "https://files.phpcomposer.com/files/top-think/think-queue/07480c36381344bef9db9c9bbe3de28005a839d3.zip",
"reference": "503c5b809585ca60cba9485a233aa8be4b22c990", "reference": "07480c36381344bef9db9c9bbe3de28005a839d3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -336,7 +336,7 @@
} }
], ],
"description": "The ThinkPHP5 Queue Package", "description": "The ThinkPHP5 Queue Package",
"time": "2016-12-01 04:29:39" "time": "2017-02-28 08:07:37"
}, },
{ {
"name": "zoujingli/wechat-php-sdk", "name": "zoujingli/wechat-php-sdk",
@ -348,7 +348,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/zoujingli/wechat-php-sdk/12759d48867aab14e6b66be81a5b5afe223a0476.zip", "url": "https://files.phpcomposer.com/files/zoujingli/wechat-php-sdk/12759d48867aab14e6b66be81a5b5afe223a0476.zip",
"reference": "12759d48867aab14e6b66be81a5b5afe223a0476", "reference": "12759d48867aab14e6b66be81a5b5afe223a0476",
"shasum": "" "shasum": ""
}, },

View File

@ -32,7 +32,7 @@ ThinkPHP5在保持快速开发和大道至简的核心理念不变的同时PH
> ThinkPHP5的运行环境要求PHP5.4以上。 > ThinkPHP5的运行环境要求PHP5.4以上。
详细开发文档参考 [ThinkPHP5完全开发手册](http://www.kancloud.cn/manual/thinkphp5) 详细开发文档参考 [ThinkPHP5完全开发手册](http://www.kancloud.cn/manual/thinkphp5) 以及[ThinkPHP5入门系列教程](http://www.kancloud.cn/special/thinkphp5_quickstart)
## 目录结构 ## 目录结构

View File

@ -9,7 +9,7 @@
// | Author: liu21st <liu21st@gmail.com> // | Author: liu21st <liu21st@gmail.com>
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
define('THINK_VERSION', '5.0.6'); define('THINK_VERSION', '5.0.7');
define('THINK_START_TIME', microtime(true)); define('THINK_START_TIME', microtime(true));
define('THINK_START_MEM', memory_get_usage()); define('THINK_START_MEM', memory_get_usage());
define('EXT', '.php'); define('EXT', '.php');

View File

@ -2,7 +2,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ] // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved. // | Copyright (c) 2006-2017 http://thinkphp.cn All rights reserved.
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------

View File

@ -206,7 +206,7 @@ return [
// 是否自动开启 SESSION // 是否自动开启 SESSION
'auto_start' => true, 'auto_start' => true,
'httponly' => true, 'httponly' => true,
'secure' => true, 'secure' => false,
], ],
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------

View File

@ -64,4 +64,5 @@ return [
'invalid request' => '非法请求', 'invalid request' => '非法请求',
'bind attr has exists' => '模型的属性已经存在', 'bind attr has exists' => '模型的属性已经存在',
'relation data not exists' => '关联数据不存在', 'relation data not exists' => '关联数据不存在',
'relation not support' => '关联不支持',
]; ];

View File

@ -87,7 +87,7 @@ class Config
return isset(self::$config[$range][strtolower($name)]); return isset(self::$config[$range][strtolower($name)]);
} else { } else {
// 二维数组设置和获取支持 // 二维数组设置和获取支持
$name = explode('.', $name); $name = explode('.', $name, 2);
return isset(self::$config[$range][strtolower($name[0])][$name[1]]); return isset(self::$config[$range][strtolower($name[0])][$name[1]]);
} }
} }
@ -111,7 +111,7 @@ class Config
return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null; return isset(self::$config[$range][$name]) ? self::$config[$range][$name] : null;
} else { } else {
// 二维数组设置和获取支持 // 二维数组设置和获取支持
$name = explode('.', $name); $name = explode('.', $name, 2);
$name[0] = strtolower($name[0]); $name[0] = strtolower($name[0]);
return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null; return isset(self::$config[$range][$name[0]][$name[1]]) ? self::$config[$range][$name[0]][$name[1]] : null;
} }
@ -135,7 +135,7 @@ class Config
self::$config[$range][strtolower($name)] = $value; self::$config[$range][strtolower($name)] = $value;
} else { } else {
// 二维数组设置和获取支持 // 二维数组设置和获取支持
$name = explode('.', $name); $name = explode('.', $name, 2);
self::$config[$range][strtolower($name[0])][$name[1]] = $value; self::$config[$range][strtolower($name[0])][$name[1]] = $value;
} }
return; return;

View File

@ -40,7 +40,7 @@ class Controller
protected $beforeActionList = []; protected $beforeActionList = [];
/** /**
* 架构函数 * 构造方法
* @param Request $request Request对象 * @param Request $request Request对象
* @access public * @access public
*/ */

View File

@ -369,8 +369,9 @@ class Loader
if (isset(self::$instance[$guid])) { if (isset(self::$instance[$guid])) {
return self::$instance[$guid]; return self::$instance[$guid];
} }
if (strpos($name, '\\')) { if (false !== strpos($name, '\\')) {
$class = $name; $class = $name;
$module = Request::instance()->module();
} else { } else {
if (strpos($name, '/')) { if (strpos($name, '/')) {
list($module, $name) = explode('/', $name, 2); list($module, $name) = explode('/', $name, 2);
@ -404,8 +405,9 @@ class Loader
*/ */
public static function controller($name, $layer = 'controller', $appendSuffix = false, $empty = '') public static function controller($name, $layer = 'controller', $appendSuffix = false, $empty = '')
{ {
if (strpos($name, '\\')) { if (false !== strpos($name, '\\')) {
$class = $name; $class = $name;
$module = Request::instance()->module();
} else { } else {
if (strpos($name, '/')) { if (strpos($name, '/')) {
list($module, $name) = explode('/', $name); list($module, $name) = explode('/', $name);
@ -440,8 +442,9 @@ class Loader
if (isset(self::$instance[$guid])) { if (isset(self::$instance[$guid])) {
return self::$instance[$guid]; return self::$instance[$guid];
} }
if (strpos($name, '\\')) { if (false !== strpos($name, '\\')) {
$class = $name; $class = $name;
$module = Request::instance()->module();
} else { } else {
if (strpos($name, '/')) { if (strpos($name, '/')) {
list($module, $name) = explode('/', $name); list($module, $name) = explode('/', $name);

View File

@ -14,7 +14,7 @@ namespace think;
use InvalidArgumentException; use InvalidArgumentException;
use think\db\Query; use think\db\Query;
use think\Exception\ValidateException; use think\Exception\ValidateException;
use think\model\Collection; use think\model\Collection as ModelCollection;
use think\model\Relation; use think\model\Relation;
use think\model\relation\BelongsTo; use think\model\relation\BelongsTo;
use think\model\relation\BelongsToMany; use think\model\relation\BelongsToMany;
@ -109,7 +109,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
protected static $initialized = []; protected static $initialized = [];
/** /**
* 架构函数 * 构造方法
* @access public * @access public
* @param array|object $data 数据 * @param array|object $data 数据
*/ */
@ -290,9 +290,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
} }
// 标记字段更改 // 标记字段更改
if (isset($this->data[$name]) && is_scalar($this->data[$name]) && is_scalar($value) && 0 !== strcmp($this->data[$name], $value)) { if (!isset($this->data[$name])) {
$this->change[] = $name; $this->change[] = $name;
} elseif (!isset($this->data[$name]) || $value != $this->data[$name]) { } elseif (is_scalar($value) && is_scalar($this->data[$name]) && 0 !== strcmp($this->data[$name], $value)) {
$this->change[] = $name;
} elseif (!is_object($value) && $value != $this->data[$name]) {
$this->change[] = $name; $this->change[] = $name;
} }
// 设置数据对象属性 // 设置数据对象属性
@ -508,7 +510,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$value = json_decode($value, true); $value = json_decode($value, true);
break; break;
case 'array': case 'array':
$value = is_null($value) ? [] : json_decode($value, true); $value = empty($value) ? [] : json_decode($value, true);
break; break;
case 'object': case 'object':
$value = empty($value) ? new \stdClass() : json_decode($value); $value = empty($value) ? new \stdClass() : json_decode($value);
@ -624,7 +626,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
/** /**
* 转换子模型对象 * 转换子模型对象
* @access protected * @access protected
* @param Model|Collection $model * @param Model|ModelCollection $model
* @param $visible * @param $visible
* @param $hidden * @param $hidden
* @param $key * @param $key
@ -663,7 +665,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
} }
foreach ($data as $key => $val) { foreach ($data as $key => $val) {
if ($val instanceof Model || $val instanceof Collection) { if ($val instanceof Model || $val instanceof ModelCollection) {
// 关联模型对象 // 关联模型对象
$item[$key] = $this->subToArray($val, $visible, $hidden, $key); $item[$key] = $this->subToArray($val, $visible, $hidden, $key);
} elseif (is_array($val) && reset($val) instanceof Model) { } elseif (is_array($val) && reset($val) instanceof Model) {
@ -712,14 +714,14 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
/** /**
* 转换当前模型数据集为数据集对象 * 转换当前模型数据集为数据集对象
* @access public * @access public
* @param array|Collection $collection 数据集 * @param array|\think\Collection $collection 数据集
* @return Collection * @return \think\Collection
*/ */
public function toCollection($collection) public function toCollection($collection)
{ {
if ($this->resultSetType) { if ($this->resultSetType) {
if ('collection' == $this->resultSetType) { if ('collection' == $this->resultSetType) {
$collection = new Collection($collection); $collection = new ModelCollection($collection);
} elseif (false !== strpos($this->resultSetType, '\\')) { } elseif (false !== strpos($this->resultSetType, '\\')) {
$class = $this->resultSetType; $class = $this->resultSetType;
$collection = new $class($collection); $collection = new $class($collection);
@ -1081,7 +1083,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
// 删除条件 // 删除条件
$pk = $this->getPk(); $pk = $this->getPk();
if (isset($this->data[$pk])) { if (is_string($pk) && isset($this->data[$pk])) {
$where = [$pk => $this->data[$pk]]; $where = [$pk => $this->data[$pk]];
} elseif (!empty($this->updateWhere)) { } elseif (!empty($this->updateWhere)) {
$where = $this->updateWhere; $where = $this->updateWhere;
@ -1426,16 +1428,11 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/ */
public static function has($relation, $operator = '>=', $count = 1, $id = '*') public static function has($relation, $operator = '>=', $count = 1, $id = '*')
{ {
$model = new static(); $relation = (new static())->$relation();
$relation = $model->$relation(); if (is_array($operator) || $operator instanceof \Closure) {
if ($relation instanceof HasMany) { return $relation->hasWhere($operator);
if (is_array($operator) || $operator instanceof \Closure) {
return $relation->hasWhere($operator);
}
return $relation->has($operator, $count, $id);
} else {
return $relation;
} }
return $relation->has($operator, $count, $id);
} }
/** /**
@ -1447,13 +1444,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
*/ */
public static function hasWhere($relation, $where = []) public static function hasWhere($relation, $where = [])
{ {
$model = new static(); return (new static())->$relation()->hasWhere($where);
$relation = $model->$relation();
if ($relation instanceof HasMany) {
return $relation->hasWhere($where);
} else {
return $relation;
}
} }
/** /**
@ -1493,7 +1484,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$closure = $relation; $closure = $relation;
$relation = $key; $relation = $key;
} }
if (strpos($relation, '.')) { if (is_array($relation)) {
$subRelation = $relation;
$relation = $key;
} elseif (strpos($relation, '.')) {
list($relation, $subRelation) = explode('.', $relation, 2); list($relation, $subRelation) = explode('.', $relation, 2);
} }
$method = Loader::parseName($relation, 1, false); $method = Loader::parseName($relation, 1, false);
@ -1519,7 +1513,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$closure = $relation; $closure = $relation;
$relation = $key; $relation = $key;
} }
if (strpos($relation, '.')) { if (is_array($relation)) {
$subRelation = $relation;
$relation = $key;
} elseif (strpos($relation, '.')) {
list($relation, $subRelation) = explode('.', $relation, 2); list($relation, $subRelation) = explode('.', $relation, 2);
} }
$relation = Loader::parseName($relation, 1, false); $relation = Loader::parseName($relation, 1, false);
@ -1545,7 +1542,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
$closure = $relation; $closure = $relation;
$relation = $key; $relation = $key;
} }
if (strpos($relation, '.')) { if (is_array($relation)) {
$subRelation = $relation;
$relation = $key;
} elseif (strpos($relation, '.')) {
list($relation, $subRelation) = explode('.', $relation, 2); list($relation, $subRelation) = explode('.', $relation, 2);
} }
$relation = Loader::parseName($relation, 1, false); $relation = Loader::parseName($relation, 1, false);
@ -1569,10 +1569,16 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
if ($relation instanceof \Closure) { if ($relation instanceof \Closure) {
$closure = $relation; $closure = $relation;
$relation = $key; $relation = $key;
} elseif (is_string($key)) {
$name = $relation;
$relation = $key;
} }
$relation = Loader::parseName($relation, 1, false); $relation = Loader::parseName($relation, 1, false);
$count = $this->$relation()->relationCount($result, $closure); $count = $this->$relation()->relationCount($result, $closure);
$result->setAttr(Loader::parseName($relation) . '_count', $count); if (!isset($name)) {
$name = Loader::parseName($relation) . '_count';
}
$result->setAttr($name, $count);
} }
} }

View File

@ -341,7 +341,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
{ {
try { try {
$total = $this->total(); $total = $this->total();
} catch (Exception $e) { } catch (\DomainException $e) {
$total = null; $total = null;
} }
@ -349,7 +349,7 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J
'total' => $total, 'total' => $total,
'per_page' => $this->listRows(), 'per_page' => $this->listRows(),
'current_page' => $this->currentPage(), 'current_page' => $this->currentPage(),
'data' => $this->items->toArray() 'data' => $this->items->toArray(),
]; ];
} }

View File

@ -120,7 +120,7 @@ class Request
protected $isCheckCache; protected $isCheckCache;
/** /**
* 构函数 * 函数
* @access protected * @access protected
* @param array $options 参数 * @param array $options 参数
*/ */
@ -633,7 +633,7 @@ class Request
if (true === $name) { if (true === $name) {
// 获取包含文件上传信息的数组 // 获取包含文件上传信息的数组
$file = $this->file(); $file = $this->file();
$data = array_merge($this->param, $file); $data = is_array($file) ? array_merge($this->param, $file) : $this->param;
return $this->input($data, '', $default, $filter); return $this->input($data, '', $default, $filter);
} }
return $this->input($this->param, $name, $default, $filter); return $this->input($this->param, $name, $default, $filter);
@ -688,7 +688,7 @@ class Request
{ {
if (empty($this->post)) { if (empty($this->post)) {
$content = $this->input; $content = $this->input;
if (empty($_POST) && 'application/json' == $this->contentType()) { if (empty($_POST) && false !== strpos($this->contentType(), 'application/json')) {
$this->post = (array) json_decode($content, true); $this->post = (array) json_decode($content, true);
} else { } else {
$this->post = $_POST; $this->post = $_POST;
@ -713,7 +713,7 @@ class Request
{ {
if (is_null($this->put)) { if (is_null($this->put)) {
$content = $this->input; $content = $this->input;
if ('application/json' == $this->contentType()) { if (false !== strpos($this->contentType(), 'application/json')) {
$this->put = (array) json_decode($content, true); $this->put = (array) json_decode($content, true);
} else { } else {
parse_str($content, $this->put); parse_str($content, $this->put);
@ -1357,7 +1357,11 @@ class Request
{ {
$contentType = $this->server('CONTENT_TYPE'); $contentType = $this->server('CONTENT_TYPE');
if ($contentType) { if ($contentType) {
list($type) = explode(';', $contentType); if (strpos($contentType, ';')) {
list($type) = explode(';', $contentType);
} else {
$type = $contentType;
}
return trim($type); return trim($type);
} }
return ''; return '';
@ -1523,13 +1527,13 @@ class Request
} }
} }
// 自动缓存功能 // 自动缓存功能
$key = '__URL__'; $key = md5($this->host()) . '__URL__';
} elseif (strpos($key, '|')) { } elseif (strpos($key, '|')) {
list($key, $fun) = explode('|', $key); list($key, $fun) = explode('|', $key);
} }
// 特殊规则替换 // 特殊规则替换
if (false !== strpos($key, '__')) { if (false !== strpos($key, '__')) {
$key = str_replace(['__MODULE__', '__CONTROLLER__', '__ACTION__', '__URL__'], [$this->module, $this->controller, $this->action, md5($this->url())], $key); $key = str_replace(['__MODULE__', '__CONTROLLER__', '__ACTION__', '__URL__', ''], [$this->module, $this->controller, $this->action, md5($this->url())], $key);
} }
if (false !== strpos($key, ':')) { if (false !== strpos($key, ':')) {

View File

@ -40,7 +40,7 @@ class Response
protected $content = null; protected $content = null;
/** /**
* 构函数 * 函数
* @access public * @access public
* @param mixed $data 输出数据 * @param mixed $data 输出数据
* @param int $code * @param int $code

View File

@ -232,6 +232,7 @@ class Route
public static function rule($rule, $route = '', $type = '*', $option = [], $pattern = []) public static function rule($rule, $route = '', $type = '*', $option = [], $pattern = [])
{ {
$group = self::getGroup('name'); $group = self::getGroup('name');
if (!is_null($group)) { if (!is_null($group)) {
// 路由分组 // 路由分组
$option = array_merge(self::getGroup('option'), $option); $option = array_merge(self::getGroup('option'), $option);
@ -304,8 +305,12 @@ class Route
} }
$vars = self::parseVar($rule); $vars = self::parseVar($rule);
if (isset($name)) { if (isset($name)) {
$key = $group ? $group . ($rule ? '/' . $rule : '') : $rule; $key = $group ? $group . ($rule ? '/' . $rule : '') : $rule;
self::name($name, [$key, $vars, self::$domain]); $suffix = isset($option['ext']) ? $option['ext'] : null;
self::name($name, [$key, $vars, self::$domain, $suffix]);
}
if (isset($option['modular'])) {
$route = $option['modular'] . '/' . $route;
} }
if ($group) { if ($group) {
if ('*' != $type) { if ('*' != $type) {
@ -447,7 +452,8 @@ class Route
$vars = self::parseVar($key); $vars = self::parseVar($key);
$item[] = ['rule' => $key, 'route' => $route, 'var' => $vars, 'option' => $options, 'pattern' => $patterns]; $item[] = ['rule' => $key, 'route' => $route, 'var' => $vars, 'option' => $options, 'pattern' => $patterns];
// 设置路由标识 // 设置路由标识
self::name($route, [$name . ($key ? '/' . $key : ''), $vars, self::$domain]); $suffix = isset($options['ext']) ? $options['ext'] : null;
self::name($route, [$name . ($key ? '/' . $key : ''), $vars, self::$domain, $suffix]);
} }
self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern]; self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern];
} }
@ -827,7 +833,7 @@ class Route
// 分隔符替换 确保路由定义使用统一的分隔符 // 分隔符替换 确保路由定义使用统一的分隔符
$url = str_replace($depr, '|', $url); $url = str_replace($depr, '|', $url);
if (strpos($url, '|') && isset(self::$rules['alias'][strstr($url, '|', true)])) { if (isset(self::$rules['alias'][$url]) || isset(self::$rules['alias'][strstr($url, '|', true)])) {
// 检测路由别名 // 检测路由别名
$result = self::checkRouteAlias($request, $url, $depr); $result = self::checkRouteAlias($request, $url, $depr);
if (false !== $result) { if (false !== $result) {
@ -1126,8 +1132,8 @@ class Route
|| (isset($option['ajax']) && !$option['ajax'] && $request->isAjax()) // 非Ajax检测 || (isset($option['ajax']) && !$option['ajax'] && $request->isAjax()) // 非Ajax检测
|| (isset($option['pjax']) && $option['pjax'] && !$request->isPjax()) // Pjax检测 || (isset($option['pjax']) && $option['pjax'] && !$request->isPjax()) // Pjax检测
|| (isset($option['pjax']) && !$option['pjax'] && $request->isPjax()) // 非Pjax检测 || (isset($option['pjax']) && !$option['pjax'] && $request->isPjax()) // 非Pjax检测
|| (isset($option['ext']) && false === stripos('|' . $option['ext'] . '|', $request->ext() ? '|' . $request->ext() . '|' : '')) // 伪静态后缀检测 || (isset($option['ext']) && false === stripos('|' . $option['ext'] . '|', '|' . $request->ext() . '|')) // 伪静态后缀检测
|| (isset($option['deny_ext']) && false !== stripos('|' . $option['deny_ext'] . '|', $request->ext() ? '|' . $request->ext() . '|' : '')) || (isset($option['deny_ext']) && false !== stripos('|' . $option['deny_ext'] . '|', '|' . $request->ext() . '|'))
|| (isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain])) // 域名检测 || (isset($option['domain']) && !in_array($option['domain'], [$_SERVER['HTTP_HOST'], self::$subDomain])) // 域名检测
|| (isset($option['https']) && $option['https'] && !$request->isSsl()) // https检测 || (isset($option['https']) && $option['https'] && !$request->isSsl()) // https检测
|| (isset($option['https']) && !$option['https'] && $request->isSsl()) // https检测 || (isset($option['https']) && !$option['https'] && $request->isSsl()) // https检测
@ -1164,7 +1170,7 @@ class Route
$len1 = substr_count($url, '|'); $len1 = substr_count($url, '|');
$len2 = substr_count($rule, '/'); $len2 = substr_count($rule, '/');
// 多余参数是否合并 // 多余参数是否合并
$merge = !empty($option['merge_extra_vars']) ? true : false; $merge = !empty($option['merge_extra_vars']);
if ($merge && $len1 > $len2) { if ($merge && $len1 > $len2) {
$url = str_replace('|', $depr, $url); $url = str_replace('|', $depr, $url);
$url = implode('|', explode($depr, $url, $len2 + 1)); $url = implode('|', explode($depr, $url, $len2 + 1));
@ -1275,9 +1281,6 @@ class Route
} elseif (strpos($url, '/')) { } elseif (strpos($url, '/')) {
// [模块/控制器/操作] // [模块/控制器/操作]
$path = explode('/', $url); $path = explode('/', $url);
} elseif (false !== strpos($url, '=')) {
// 参数1=值1&参数2=值2...
parse_str($url, $var);
} else { } else {
$path = [$url]; $path = [$url];
} }

View File

@ -57,7 +57,7 @@ class Template
protected $storage; protected $storage;
/** /**
* 构函数 * 函数
* @access public * @access public
*/ */
public function __construct(array $config = []) public function __construct(array $config = [])

View File

@ -80,6 +80,9 @@ class Url
if (!empty($match[1])) { if (!empty($match[1])) {
$domain = $match[1]; $domain = $match[1];
} }
if (!is_null($match[2])) {
$suffix = $match[2];
}
} elseif (!empty($rule) && isset($name)) { } elseif (!empty($rule) && isset($name)) {
throw new \InvalidArgumentException('route name not exists:' . $name); throw new \InvalidArgumentException('route name not exists:' . $name);
} else { } else {
@ -288,18 +291,18 @@ class Url
public static function getRuleUrl($rule, &$vars = []) public static function getRuleUrl($rule, &$vars = [])
{ {
foreach ($rule as $item) { foreach ($rule as $item) {
list($url, $pattern, $domain) = $item; list($url, $pattern, $domain, $suffix) = $item;
if (empty($pattern)) { if (empty($pattern)) {
return [$url, $domain]; return [$url, $domain, $suffix];
} }
foreach ($pattern as $key => $val) { foreach ($pattern as $key => $val) {
if (isset($vars[$key])) { if (isset($vars[$key])) {
$url = str_replace(['[:' . $key . ']', '<' . $key . '?>', ':' . $key . '', '<' . $key . '>'], $vars[$key], $url); $url = str_replace(['[:' . $key . ']', '<' . $key . '?>', ':' . $key . '', '<' . $key . '>'], $vars[$key], $url);
unset($vars[$key]); unset($vars[$key]);
$result = [$url, $domain]; $result = [$url, $domain, $suffix];
} elseif (2 == $val) { } elseif (2 == $val) {
$url = str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url); $url = str_replace(['/[:' . $key . ']', '[:' . $key . ']', '<' . $key . '?>'], '', $url);
$result = [$url, $domain]; $result = [$url, $domain, $suffix];
} else { } else {
break; break;
} }

View File

@ -102,7 +102,7 @@ class Validate
protected $batch = false; protected $batch = false;
/** /**
* 构函数 * 函数
* @access public * @access public
* @param array $rules 验证规则 * @param array $rules 验证规则
* @param array $message 验证提示信息 * @param array $message 验证提示信息

View File

@ -25,7 +25,7 @@ class View
protected $replace = []; protected $replace = [];
/** /**
* 构函数 * 函数
* @access public * @access public
* @param array $engine 模板引擎参数 * @param array $engine 模板引擎参数
* @param array $replace 字符串替换参数 * @param array $replace 字符串替换参数

View File

@ -28,7 +28,7 @@ class File extends Driver
]; ];
/** /**
* 构函数 * 函数
* @param array $options * @param array $options
*/ */
public function __construct($options = []) public function __construct($options = [])
@ -225,6 +225,7 @@ class File extends Driver
foreach ($files as $path) { foreach ($files as $path) {
if (is_dir($path)) { if (is_dir($path)) {
array_map('unlink', glob($path . '/*.php')); array_map('unlink', glob($path . '/*.php'));
rmdir($path);
} else { } else {
unlink($path); unlink($path);
} }

View File

@ -26,7 +26,7 @@ class Lite extends Driver
]; ];
/** /**
* 构函数 * 函数
* @access public * @access public
* *
* @param array $options * @param array $options

View File

@ -25,7 +25,7 @@ class Memcache extends Driver
]; ];
/** /**
* 构函数 * 函数
* @param array $options 缓存参数 * @param array $options 缓存参数
* @access public * @access public
* @throws \BadFunctionCallException * @throws \BadFunctionCallException

View File

@ -27,7 +27,7 @@ class Memcached extends Driver
]; ];
/** /**
* 构函数 * 函数
* @param array $options 缓存参数 * @param array $options 缓存参数
* @access public * @access public
*/ */

View File

@ -34,7 +34,7 @@ class Redis extends Driver
]; ];
/** /**
* 构函数 * 函数
* @param array $options 缓存参数 * @param array $options 缓存参数
* @access public * @access public
*/ */

View File

@ -28,7 +28,7 @@ class Sqlite extends Driver
]; ];
/** /**
* 构函数 * 函数
* @param array $options 缓存参数 * @param array $options 缓存参数
* @throws \BadFunctionCallException * @throws \BadFunctionCallException
* @access public * @access public

View File

@ -25,7 +25,7 @@ class Wincache extends Driver
]; ];
/** /**
* 构函数 * 函数
* @param array $options 缓存参数 * @param array $options 缓存参数
* @throws \BadFunctionCallException * @throws \BadFunctionCallException
* @access public * @access public

View File

@ -25,7 +25,7 @@ class Xcache extends Driver
]; ];
/** /**
* 构函数 * 函数
* @param array $options 缓存参数 * @param array $options 缓存参数
* @access public * @access public
* @throws \BadFunctionCallException * @throws \BadFunctionCallException

View File

@ -32,7 +32,7 @@ abstract class Rest
]; ];
/** /**
* 构函数 取得模板对象实例 * 函数 取得模板对象实例
* @access public * @access public
*/ */
public function __construct() public function __construct()

View File

@ -18,7 +18,7 @@ abstract class Yar
{ {
/** /**
* 构函数 * 函数
* @access public * @access public
*/ */
public function __construct() public function __construct()

View File

@ -32,7 +32,7 @@ abstract class Builder
protected $deleteSql = 'DELETE FROM %TABLE% %USING% %JOIN% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%'; protected $deleteSql = 'DELETE FROM %TABLE% %USING% %JOIN% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%';
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Connection $connection 数据库连接对象实例 * @param Connection $connection 数据库连接对象实例
* @param Query $query 数据库查询对象实例 * @param Query $query 数据库查询对象实例
@ -379,7 +379,7 @@ abstract class Builder
} else { } else {
$zone = implode(',', $this->parseValue($value, $field)); $zone = implode(',', $this->parseValue($value, $field));
} }
$whereStr .= $key . ' ' . $exp . ' (' . $zone . ')'; $whereStr .= $key . ' ' . $exp . ' (' . (empty($zone) ? "''" : $zone) . ')';
} }
} elseif (in_array($exp, ['NOT BETWEEN', 'BETWEEN'])) { } elseif (in_array($exp, ['NOT BETWEEN', 'BETWEEN'])) {
// BETWEEN 查询 // BETWEEN 查询

View File

@ -125,7 +125,7 @@ abstract class Connection
protected $bind = []; protected $bind = [];
/** /**
* 构函数 读取数据库配置信息 * 函数 读取数据库配置信息
* @access public * @access public
* @param array $config 数据库配置数组 * @param array $config 数据库配置数组
*/ */
@ -365,8 +365,8 @@ abstract class Connection
$this->bind = $bind; $this->bind = $bind;
} }
//释放前次的查询结果 // 释放前次的查询结果
if (!empty($this->PDOStatement) && $this->PDOStatement->queryString != $sql) { if (!empty($this->PDOStatement)) {
$this->free(); $this->free();
} }

View File

@ -54,7 +54,7 @@ class Query
private static $event = []; private static $event = [];
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Connection $connection 数据库对象实例 * @param Connection $connection 数据库对象实例
* @param string $model 模型名 * @param string $model 模型名
@ -869,7 +869,7 @@ class Query
public function view($join, $field = true, $on = null, $type = 'INNER') public function view($join, $field = true, $on = null, $type = 'INNER')
{ {
$this->options['view'] = true; $this->options['view'] = true;
if (is_array($join) && is_null($field)) { if (is_array($join) && key($join) !== 0) {
foreach ($join as $key => $val) { foreach ($join as $key => $val) {
$this->view($key, $val[0], isset($val[1]) ? $val[1] : null, isset($val[2]) ? $val[2] : 'INNER'); $this->view($key, $val[0], isset($val[1]) ? $val[1] : null, isset($val[2]) ? $val[2] : 'INNER');
} }
@ -893,7 +893,7 @@ class Query
} else { } else {
$name = $alias . '.' . $key; $name = $alias . '.' . $key;
} }
$fields[] = $name . ' AS ' . $val; $fields[$name] = $val;
$this->options['map'][$val] = $name; $this->options['map'][$val] = $name;
} }
} }
@ -1895,7 +1895,7 @@ class Query
$relation = Loader::parseName($relation, 1, false); $relation = Loader::parseName($relation, 1, false);
$model = $class->$relation(); $model = $class->$relation();
if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) { if ($model instanceof OneToOne && 0 == $model->getEagerlyType()) {
$model->eagerly($this, $relation, $subRelation, $closure, $first); $model->removeOption()->eagerly($this, $relation, $subRelation, $closure, $first);
$first = false; $first = false;
} elseif ($closure) { } elseif ($closure) {
$with[$key] = $closure; $with[$key] = $closure;
@ -2065,8 +2065,10 @@ class Query
$sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null); $sequence = $sequence ?: (isset($options['sequence']) ? $options['sequence'] : null);
$lastInsId = $this->getLastInsID($sequence); $lastInsId = $this->getLastInsID($sequence);
if ($lastInsId) { if ($lastInsId) {
$pk = $this->getPk($options); $pk = $this->getPk($options);
$data[$pk] = $lastInsId; if (is_string($pk)) {
$data[$pk] = $lastInsId;
}
} }
$options['data'] = $data; $options['data'] = $data;
$this->trigger('after_insert', $options); $this->trigger('after_insert', $options);
@ -2202,11 +2204,13 @@ class Query
if (isset($key) && Cache::get($key)) { if (isset($key) && Cache::get($key)) {
// 删除缓存 // 删除缓存
Cache::rm($key); Cache::rm($key);
} elseif (!empty($options['cache']['tag'])) {
Cache::clear($options['cache']['tag']);
} }
// 执行操作 // 执行操作
$result = '' == $sql ? 0 : $this->execute($sql, $bind); $result = '' == $sql ? 0 : $this->execute($sql, $bind);
if ($result) { if ($result) {
if (isset($where[$pk])) { if (is_string($pk) && isset($where[$pk])) {
$data[$pk] = $where[$pk]; $data[$pk] = $where[$pk];
} elseif (is_string($pk) && isset($key) && strpos($key, '|')) { } elseif (is_string($pk) && isset($key) && strpos($key, '|')) {
list($a, $val) = explode('|', $key); list($a, $val) = explode('|', $key);
@ -2298,7 +2302,7 @@ class Query
} }
} }
if (isset($cache)) { if (isset($cache) && $resultSet) {
// 缓存数据集 // 缓存数据集
$this->cacheData($key, $resultSet, $cache); $this->cacheData($key, $resultSet, $cache);
} }
@ -2375,6 +2379,8 @@ class Query
} }
if (isset($data)) { if (isset($data)) {
return 'think:' . $options['table'] . '|' . $data; return 'think:' . $options['table'] . '|' . $data;
} else {
return md5(serialize($options));
} }
} }
@ -2412,8 +2418,10 @@ class Query
$cache = $options['cache']; $cache = $options['cache'];
if (true === $cache['key'] && !is_null($data) && !is_array($data)) { if (true === $cache['key'] && !is_null($data) && !is_array($data)) {
$key = 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data; $key = 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data;
} elseif (is_string($cache['key'])) {
$key = $cache['key'];
} elseif (!isset($key)) { } elseif (!isset($key)) {
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options)); $key = md5(serialize($options));
} }
$result = Cache::get($key); $result = Cache::get($key);
} }
@ -2451,7 +2459,7 @@ class Query
$result = isset($resultSet[0]) ? $resultSet[0] : null; $result = isset($resultSet[0]) ? $resultSet[0] : null;
} }
if (isset($cache)) { if (isset($cache) && $result) {
// 缓存数据 // 缓存数据
$this->cacheData($key, $result, $cache); $this->cacheData($key, $result, $cache);
} }
@ -2644,6 +2652,8 @@ class Query
if (isset($key) && Cache::get($key)) { if (isset($key) && Cache::get($key)) {
// 删除缓存 // 删除缓存
Cache::rm($key); Cache::rm($key);
} elseif (!empty($options['cache']['tag'])) {
Cache::clear($options['cache']['tag']);
} }
// 执行操作 // 执行操作
$result = $this->execute($sql, $bind); $result = $this->execute($sql, $bind);

View File

@ -36,6 +36,9 @@ class Mysql extends Builder
$key = 'json_extract(' . $field . ', \'$.' . $name . '\')'; $key = 'json_extract(' . $field . ', \'$.' . $name . '\')';
} elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) { } elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) {
list($table, $key) = explode('.', $key, 2); list($table, $key) = explode('.', $key, 2);
if ('__TABLE__' == $table) {
$table = $this->query->getTable();
}
if (isset($options['alias'][$table])) { if (isset($options['alias'][$table])) {
$table = $options['alias'][$table]; $table = $options['alias'][$table];
} }

View File

@ -55,6 +55,9 @@ class Pgsql extends Builder
$key = $field . '->>\'' . $name . '\''; $key = $field . '->>\'' . $name . '\'';
} elseif (strpos($key, '.')) { } elseif (strpos($key, '.')) {
list($table, $key) = explode('.', $key, 2); list($table, $key) = explode('.', $key, 2);
if ('__TABLE__' == $table) {
$table = $this->query->getTable();
}
if (isset($options['alias'][$table])) { if (isset($options['alias'][$table])) {
$table = $options['alias'][$table]; $table = $options['alias'][$table];
} }

View File

@ -60,6 +60,9 @@ class Sqlite extends Builder
$key = trim($key); $key = trim($key);
if (strpos($key, '.')) { if (strpos($key, '.')) {
list($table, $key) = explode('.', $key, 2); list($table, $key) = explode('.', $key, 2);
if ('__TABLE__' == $table) {
$table = $this->query->getTable();
}
if (isset($options['alias'][$table])) { if (isset($options['alias'][$table])) {
$table = $options['alias'][$table]; $table = $options['alias'][$table];
} }

View File

@ -73,6 +73,9 @@ class Sqlsrv extends Builder
$key = trim($key); $key = trim($key);
if (strpos($key, '.') && !preg_match('/[,\'\"\(\)\[\s]/', $key)) { if (strpos($key, '.') && !preg_match('/[,\'\"\(\)\[\s]/', $key)) {
list($table, $key) = explode('.', $key, 2); list($table, $key) = explode('.', $key, 2);
if ('__TABLE__' == $table) {
$table = $this->query->getTable();
}
if (isset($options['alias'][$table])) { if (isset($options['alias'][$table])) {
$table = $options['alias'][$table]; $table = $options['alias'][$table];
} }

View File

@ -43,7 +43,7 @@ class Socket
protected $allowForceClientIds = []; //配置强制推送且被授权的client_id protected $allowForceClientIds = []; //配置强制推送且被授权的client_id
/** /**
* 构函数 * 函数
* @param array $config 缓存参数 * @param array $config 缓存参数
* @access public * @access public
*/ */

View File

@ -22,7 +22,7 @@ class Merge extends Model
protected $mapFields = []; // 需要处理的模型映射字段,避免混淆 array( id => 'user.id' ) protected $mapFields = []; // 需要处理的模型映射字段,避免混淆 array( id => 'user.id' )
/** /**
* 构函数 * 函数
* @access public * @access public
* @param array|object $data 数据 * @param array|object $data 数据
*/ */

View File

@ -17,7 +17,7 @@ class Pivot extends Model
{ {
/** /**
* 构函数 * 函数
* @access public * @access public
* @param array|object $data 数据 * @param array|object $data 数据
* @param string $table 中间数据表名 * @param string $table 中间数据表名

View File

@ -17,7 +17,7 @@ use think\Model;
class BelongsTo extends OneToOne class BelongsTo extends OneToOne
{ {
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Model $parent 上级模型对象 * @param Model $parent 上级模型对象
* @param string $model 模型名 * @param string $model 模型名
@ -51,6 +51,45 @@ class BelongsTo extends OneToOne
return $this->query->where($this->localKey, $this->parent->$foreignKey)->relation($subRelation)->find(); return $this->query->where($this->localKey, $this->parent->$foreignKey)->relation($subRelation)->find();
} }
/**
* 根据关联条件查询当前模型
* @access public
* @param string $operator 比较操作符
* @param integer $count 个数
* @param string $id 关联表的统计字段
* @param string $joinType JOIN类型
* @return Query
*/
public function has($operator = '>=', $count = 1, $id = '*')
{
return $this->parent;
}
/**
* 根据关联条件查询当前模型
* @access public
* @param mixed $where 查询条件(数组或者闭包)
* @return Query
*/
public function hasWhere($where = [])
{
$table = $this->query->getTable();
$model = basename(str_replace('\\', '/', get_class($this->parent)));
$relation = basename(str_replace('\\', '/', $this->model));
if (is_array($where)) {
foreach ($where as $key => $val) {
if (false === strpos($key, '.')) {
$where[$relation . '.' . $key] = $val;
unset($where[$key]);
}
}
}
return $this->parent->db()->alias($model)
->field($model . '.*')
->join($table . ' ' . $relation, $model . '.' . $this->foreignKey . '=' . $relation . '.' . $this->localKey, $this->joinType)
->where($where);
}
/** /**
* 预载入关联查询(数据集) * 预载入关联查询(数据集)
* @access public * @access public
@ -85,10 +124,10 @@ class BelongsTo extends OneToOne
// 关联数据封装 // 关联数据封装
foreach ($resultSet as $result) { foreach ($resultSet as $result) {
// 关联模型 // 关联模型
if (!isset($data[$result->$localKey])) { if (!isset($data[$result->$foreignKey])) {
$relationModel = null; $relationModel = null;
} else { } else {
$relationModel = $data[$result->$localKey]; $relationModel = $data[$result->$foreignKey];
} }
if ($relationModel && !empty($this->bindAttr)) { if ($relationModel && !empty($this->bindAttr)) {
@ -116,10 +155,10 @@ class BelongsTo extends OneToOne
$foreignKey = $this->foreignKey; $foreignKey = $this->foreignKey;
$data = $this->eagerlyWhere($this, [$localKey => $result->$foreignKey], $localKey, $relation, $subRelation, $closure); $data = $this->eagerlyWhere($this, [$localKey => $result->$foreignKey], $localKey, $relation, $subRelation, $closure);
// 关联模型 // 关联模型
if (!isset($data[$result->$localKey])) { if (!isset($data[$result->$foreignKey])) {
$relationModel = null; $relationModel = null;
} else { } else {
$relationModel = $data[$result->$localKey]; $relationModel = $data[$result->$foreignKey];
} }
if ($relationModel && !empty($this->bindAttr)) { if ($relationModel && !empty($this->bindAttr)) {
// 绑定关联属性 // 绑定关联属性

View File

@ -24,7 +24,7 @@ class BelongsToMany extends Relation
protected $middle; protected $middle;
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Model $parent 上级模型对象 * @param Model $parent 上级模型对象
* @param string $model 模型名 * @param string $model 模型名
@ -76,6 +76,31 @@ class BelongsToMany extends Relation
return $result; return $result;
} }
/**
* 根据关联条件查询当前模型
* @access public
* @param string $operator 比较操作符
* @param integer $count 个数
* @param string $id 关联表的统计字段
* @param string $joinType JOIN类型
* @return Query
*/
public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER')
{
return $this->parent;
}
/**
* 根据关联条件查询当前模型
* @access public
* @param mixed $where 查询条件(数组或者闭包)
* @return Query
*/
public function hasWhere($where = [])
{
throw new Exception('relation not support: hasWhere');
}
/** /**
* 预载入关联查询(数据集) * 预载入关联查询(数据集)
* @access public * @access public

View File

@ -20,7 +20,7 @@ use think\model\Relation;
class HasMany extends Relation class HasMany extends Relation
{ {
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Model $parent 上级模型对象 * @param Model $parent 上级模型对象
* @param string $model 模型名 * @param string $model 模型名

View File

@ -13,6 +13,7 @@ namespace think\model\relation;
use think\Db; use think\Db;
use think\db\Query; use think\db\Query;
use think\Exception;
use think\Loader; use think\Loader;
use think\Model; use think\Model;
use think\model\Relation; use think\model\Relation;
@ -25,7 +26,7 @@ class HasManyThrough extends Relation
protected $through; protected $through;
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Model $parent 上级模型对象 * @param Model $parent 上级模型对象
* @param string $model 模型名 * @param string $model 模型名
@ -54,11 +55,36 @@ class HasManyThrough extends Relation
public function getRelation($subRelation = '', $closure = null) public function getRelation($subRelation = '', $closure = null)
{ {
if ($closure) { if ($closure) {
call_user_func_array($closure, [& $this->query]); call_user_func_array($closure, [ & $this->query]);
} }
return $this->relation($subRelation)->select(); return $this->relation($subRelation)->select();
} }
/**
* 根据关联条件查询当前模型
* @access public
* @param string $operator 比较操作符
* @param integer $count 个数
* @param string $id 关联表的统计字段
* @param string $joinType JOIN类型
* @return Query
*/
public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER')
{
return $this->parent;
}
/**
* 根据关联条件查询当前模型
* @access public
* @param mixed $where 查询条件(数组或者闭包)
* @return Query
*/
public function hasWhere($where = [])
{
throw new Exception('relation not support: hasWhere');
}
/** /**
* 预载入关联查询 * 预载入关联查询
* @access public * @access public

View File

@ -18,7 +18,7 @@ use think\Model;
class HasOne extends OneToOne class HasOne extends OneToOne
{ {
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Model $parent 上级模型对象 * @param Model $parent 上级模型对象
* @param string $model 模型名 * @param string $model 模型名
@ -47,12 +47,28 @@ class HasOne extends OneToOne
// 执行关联定义方法 // 执行关联定义方法
$localKey = $this->localKey; $localKey = $this->localKey;
if ($closure) { if ($closure) {
call_user_func_array($closure, [& $this->query]); call_user_func_array($closure, [ & $this->query]);
} }
// 判断关联类型执行查询 // 判断关联类型执行查询
return $this->query->where($this->foreignKey, $this->parent->$localKey)->relation($subRelation)->find(); return $this->query->where($this->foreignKey, $this->parent->$localKey)->relation($subRelation)->find();
} }
/**
* 根据关联条件查询当前模型
* @access public
* @return Query
*/
public function has()
{
$table = $this->query->getTable();
$localKey = $this->localKey;
$foreignKey = $this->foreignKey;
return $this->parent->db()->alias('a')
->whereExists(function ($query) use ($table, $localKey, $foreignKey) {
$query->table([$table => 'b'])->field('b.' . $foreignKey)->whereExp('a.' . $localKey, '=b.' . $foreignKey);
});
}
/** /**
* 根据关联条件查询当前模型 * 根据关联条件查询当前模型
* @access public * @access public

View File

@ -13,6 +13,7 @@ namespace think\model\relation;
use think\Db; use think\Db;
use think\db\Query; use think\db\Query;
use think\Exception;
use think\Loader; use think\Loader;
use think\Model; use think\Model;
use think\model\Relation; use think\model\Relation;
@ -26,7 +27,7 @@ class MorphMany extends Relation
protected $type; protected $type;
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Model $parent 上级模型对象 * @param Model $parent 上级模型对象
* @param string $model 模型名 * @param string $model 模型名
@ -53,11 +54,36 @@ class MorphMany extends Relation
public function getRelation($subRelation = '', $closure = null) public function getRelation($subRelation = '', $closure = null)
{ {
if ($closure) { if ($closure) {
call_user_func_array($closure, [& $this->query]); call_user_func_array($closure, [ & $this->query]);
} }
return $this->relation($subRelation)->select(); return $this->relation($subRelation)->select();
} }
/**
* 根据关联条件查询当前模型
* @access public
* @param string $operator 比较操作符
* @param integer $count 个数
* @param string $id 关联表的统计字段
* @param string $joinType JOIN类型
* @return Query
*/
public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER')
{
throw new Exception('relation not support: has');
}
/**
* 根据关联条件查询当前模型
* @access public
* @param mixed $where 查询条件(数组或者闭包)
* @return Query
*/
public function hasWhere($where = [])
{
throw new Exception('relation not support: hasWhere');
}
/** /**
* 预载入关联查询 * 预载入关联查询
* @access public * @access public
@ -113,7 +139,7 @@ class MorphMany extends Relation
if (isset($result->$pk)) { if (isset($result->$pk)) {
$data = $this->eagerlyMorphToMany([ $data = $this->eagerlyMorphToMany([
$this->morphKey => $result->$pk, $this->morphKey => $result->$pk,
$this->morphType => $this->type $this->morphType => $this->type,
], $relation, $subRelation, $closure); ], $relation, $subRelation, $closure);
$result->setAttr(Loader::parseName($relation), $this->resultSetBuild($data[$result->$pk])); $result->setAttr(Loader::parseName($relation), $this->resultSetBuild($data[$result->$pk]));
} }
@ -132,7 +158,7 @@ class MorphMany extends Relation
$count = 0; $count = 0;
if (isset($result->$pk)) { if (isset($result->$pk)) {
if ($closure) { if ($closure) {
call_user_func_array($closure, [& $this->query]); call_user_func_array($closure, [ & $this->query]);
} }
$count = $this->query->where([$this->morphKey => $result->$pk, $this->morphType => $this->type])->count(); $count = $this->query->where([$this->morphKey => $result->$pk, $this->morphType => $this->type])->count();
} }
@ -148,15 +174,15 @@ class MorphMany extends Relation
public function getRelationCountQuery($closure) public function getRelationCountQuery($closure)
{ {
if ($closure) { if ($closure) {
call_user_func_array($closure, [& $this->query]); call_user_func_array($closure, [ & $this->query]);
} }
return $this->query->where([ return $this->query->where([
$this->morphKey => [ $this->morphKey => [
'exp', 'exp',
'=' . $this->parent->getTable() . '.' . $this->parent->getPk() '=' . $this->parent->getTable() . '.' . $this->parent->getPk(),
], ],
$this->morphType => $this->type $this->morphType => $this->type,
])->fetchSql()->count(); ])->fetchSql()->count();
} }
@ -173,7 +199,7 @@ class MorphMany extends Relation
{ {
// 预载入关联查询 支持嵌套预载入 // 预载入关联查询 支持嵌套预载入
if ($closure) { if ($closure) {
call_user_func_array($closure, [& $this]); call_user_func_array($closure, [ & $this]);
} }
$list = $this->query->where($where)->with($subRelation)->select(); $list = $this->query->where($where)->with($subRelation)->select();
$morphKey = $this->morphKey; $morphKey = $this->morphKey;

View File

@ -25,7 +25,7 @@ class MorphTo extends Relation
protected $alias; protected $alias;
/** /**
* 构函数 * 函数
* @access public * @access public
* @param Model $parent 上级模型对象 * @param Model $parent 上级模型对象
* @param string $morphType 多态字段名 * @param string $morphType 多态字段名
@ -57,6 +57,31 @@ class MorphTo extends Relation
return (new $model)->relation($subRelation)->find($pk); return (new $model)->relation($subRelation)->find($pk);
} }
/**
* 根据关联条件查询当前模型
* @access public
* @param string $operator 比较操作符
* @param integer $count 个数
* @param string $id 关联表的统计字段
* @param string $joinType JOIN类型
* @return Query
*/
public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER')
{
return $this->parent;
}
/**
* 根据关联条件查询当前模型
* @access public
* @param mixed $where 查询条件(数组或者闭包)
* @return Query
*/
public function hasWhere($where = [])
{
throw new Exception('relation not support: hasWhere');
}
/** /**
* 解析模型的完整命名空间 * 解析模型的完整命名空间
* @access public * @access public
@ -89,6 +114,16 @@ class MorphTo extends Relation
return $this; return $this;
} }
/**
* 移除关联查询参数
* @access public
* @return $this
*/
public function removeOption()
{
return $this;
}
/** /**
* 预载入关联查询 * 预载入关联查询
* @access public * @access public

View File

@ -67,6 +67,7 @@ abstract class OneToOne extends Relation
$field = true; $field = true;
} }
$query->field($field, false, $table, $alias); $query->field($field, false, $table, $alias);
$field = null;
} }
// 预载入封装 // 预载入封装
@ -82,7 +83,7 @@ abstract class OneToOne extends Relation
if ($closure) { if ($closure) {
// 执行闭包查询 // 执行闭包查询
call_user_func_array($closure, [& $query]); call_user_func_array($closure, [ & $query]);
// 使用withField指定获取关联的字段 // 使用withField指定获取关联的字段
// $query->where(['id'=>1])->withField('id,name'); // $query->where(['id'=>1])->withField('id,name');
if ($query->getOptions('with_field')) { if ($query->getOptions('with_field')) {
@ -91,10 +92,8 @@ abstract class OneToOne extends Relation
} }
} elseif (isset($this->option['field'])) { } elseif (isset($this->option['field'])) {
$field = $this->option['field']; $field = $this->option['field'];
} else {
$field = true;
} }
$query->field($field, false, $joinTable, $joinAlias, $relation . '__'); $query->field(isset($field) ? $field : true, false, $joinTable, $joinAlias, $relation . '__');
} }
/** /**
@ -195,7 +194,6 @@ abstract class OneToOne extends Relation
*/ */
public function getEagerlyType() public function getEagerlyType()
{ {
$this->removeOption();
return $this->eagerlyType; return $this->eagerlyType;
} }
@ -290,7 +288,7 @@ abstract class OneToOne extends Relation
{ {
// 预载入关联查询 支持嵌套预载入 // 预载入关联查询 支持嵌套预载入
if ($closure) { if ($closure) {
call_user_func_array($closure, [& $model]); call_user_func_array($closure, [ & $model]);
if ($field = $model->getOptions('with_field')) { if ($field = $model->getOptions('with_field')) {
$model->field($field)->removeOption('with_field'); $model->field($field)->removeOption('with_field');
} }

View File

@ -68,7 +68,7 @@ class TagLib
protected $comparison = [' nheq ' => ' !== ', ' heq ' => ' === ', ' neq ' => ' != ', ' eq ' => ' == ', ' egt ' => ' >= ', ' gt ' => ' > ', ' elt ' => ' <= ', ' lt ' => ' < ']; protected $comparison = [' nheq ' => ' !== ', ' heq ' => ' === ', ' neq ' => ' != ', ' eq ' => ' == ', ' egt ' => ' >= ', ' gt ' => ' > ', ' elt ' => ' <= ', ' lt ' => ' < '];
/** /**
* 构函数 * 函数
* @access public * @access public
* @param \stdClass $template 模板引擎对象 * @param \stdClass $template 模板引擎对象
*/ */

View File

@ -142,7 +142,7 @@ trait SoftDelete
{ {
$field = isset($this->deleteTime) ? $this->deleteTime : 'delete_time'; $field = isset($this->deleteTime) ? $this->deleteTime : 'delete_time';
if (!strpos($field, '.')) { if (!strpos($field, '.')) {
$field = $this->db(false)->getTable() . '.' . $field; $field = '__TABLE__.' . $field;
} }
if (!$read && strpos($field, '.')) { if (!$read && strpos($field, '.')) {
$array = explode('.', $field); $array = explode('.', $field);

View File

@ -79,15 +79,17 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>系统发生错误</title> <title><?php echo lang('System Error'); ?></title>
<meta name="robots" content="noindex,nofollow" /> <meta name="robots" content="noindex,nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<style> <style>
/* Base */ /* Base */
body { body {
color: #333; color: #333;
font: 16px Verdana, "Helvetica Neue", helvetica, Arial, 'Microsoft YaHei', sans-serif; font: 14px Verdana, "Helvetica Neue", helvetica, Arial, 'Microsoft YaHei', sans-serif;
margin: 0; margin: 0;
padding: 0 20px 20px; padding: 0 20px 20px;
word-break: break-word;
} }
h1{ h1{
margin: 10px 0 0; margin: 10px 0 0;
@ -103,6 +105,11 @@
font-size: 18px; font-size: 18px;
border-bottom: 1px solid #eee; border-bottom: 1px solid #eee;
} }
h3.subheading {
color: #4288ce;
margin: 6px 0 0;
font-weight: 400;
}
h3{ h3{
margin: 12px; margin: 12px;
font-size: 16px; font-size: 16px;
@ -143,7 +150,27 @@
padding: 0; padding: 0;
margin: 0; margin: 0;
} }
/* Layout */
.col-md-3 {
width: 25%;
}
.col-md-9 {
width: 75%;
}
[class^="col-md-"] {
float: left;
}
.clearfix {
clear:both;
}
@media only screen
and (min-device-width : 375px)
and (max-device-width : 667px) {
.col-md-3,
.col-md-9 {
width: 100%;
}
}
/* Exception Info */ /* Exception Info */
.exception { .exception {
margin-top: 20px; margin-top: 20px;
@ -378,16 +405,19 @@
<div class="exception-var"> <div class="exception-var">
<h2>Environment Variables</h2> <h2>Environment Variables</h2>
<?php foreach ((array) $tables as $label => $value) { ?> <?php foreach ((array) $tables as $label => $value) { ?>
<table> <div>
<?php if(empty($value)){ ?> <?php if(empty($value)){ ?>
<caption><?php echo $label; ?><small>empty</small></caption> <div class="clearfix">
<div class="col-md-3"><strong><?php echo $label; ?></strong></div>
<div class="col-md-9"><small>empty</small></div>
</div>
<?php } else { ?> <?php } else { ?>
<caption><?php echo $label; ?></caption> <h3 class="subheading"><?php echo $label; ?></h3>
<tbody> <div>
<?php foreach ((array) $value as $key => $val) { ?> <?php foreach ((array) $value as $key => $val) { ?>
<tr> <div class="clearfix">
<td><?php echo htmlentities($key); ?></td> <div class="col-md-3"><strong><?php echo htmlentities($key); ?></strong></div>
<td> <div class="col-md-9"><small>
<?php <?php
if(is_array($val) || is_object($val)){ if(is_array($val) || is_object($val)){
echo htmlentities(json_encode($val, JSON_PRETTY_PRINT)); echo htmlentities(json_encode($val, JSON_PRETTY_PRINT));
@ -399,12 +429,12 @@
echo 'Resource'; echo 'Resource';
} }
?> ?>
</td> </small></div>
</tr> </div>
<?php } ?> <?php } ?>
</tbody> </div>
<?php } ?> <?php } ?>
</table> </div>
<?php } ?> <?php } ?>
</div> </div>
<?php } ?> <?php } ?>

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit26cb3a20d8134d0aa7a7901478c9dcc2::getLoader(); return ComposerAutoloaderInitb4a7bd279920664bf19a780615ee880b::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit26cb3a20d8134d0aa7a7901478c9dcc2 class ComposerAutoloaderInitb4a7bd279920664bf19a780615ee880b
{ {
private static $loader; private static $loader;
@ -19,15 +19,15 @@ class ComposerAutoloaderInit26cb3a20d8134d0aa7a7901478c9dcc2
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInit26cb3a20d8134d0aa7a7901478c9dcc2', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInitb4a7bd279920664bf19a780615ee880b', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit26cb3a20d8134d0aa7a7901478c9dcc2', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInitb4a7bd279920664bf19a780615ee880b', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION'); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION');
if ($useStaticLoader) { if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php'; require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit26cb3a20d8134d0aa7a7901478c9dcc2::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInitb4a7bd279920664bf19a780615ee880b::getInitializer($loader));
} else { } else {
$map = require __DIR__ . '/autoload_namespaces.php'; $map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) { foreach ($map as $namespace => $path) {
@ -48,19 +48,19 @@ class ComposerAutoloaderInit26cb3a20d8134d0aa7a7901478c9dcc2
$loader->register(true); $loader->register(true);
if ($useStaticLoader) { if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit26cb3a20d8134d0aa7a7901478c9dcc2::$files; $includeFiles = Composer\Autoload\ComposerStaticInitb4a7bd279920664bf19a780615ee880b::$files;
} else { } else {
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
} }
foreach ($includeFiles as $fileIdentifier => $file) { foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire26cb3a20d8134d0aa7a7901478c9dcc2($fileIdentifier, $file); composerRequireb4a7bd279920664bf19a780615ee880b($fileIdentifier, $file);
} }
return $loader; return $loader;
} }
} }
function composerRequire26cb3a20d8134d0aa7a7901478c9dcc2($fileIdentifier, $file) function composerRequireb4a7bd279920664bf19a780615ee880b($fileIdentifier, $file)
{ {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file; require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit26cb3a20d8134d0aa7a7901478c9dcc2 class ComposerStaticInitb4a7bd279920664bf19a780615ee880b
{ {
public static $files = array ( public static $files = array (
'9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php', '9b552a3cc426e3287cc811caefa3cf53' => __DIR__ . '/..' . '/topthink/think-helper/src/helper.php',
@ -273,9 +273,9 @@ class ComposerStaticInit26cb3a20d8134d0aa7a7901478c9dcc2
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit26cb3a20d8134d0aa7a7901478c9dcc2::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInitb4a7bd279920664bf19a780615ee880b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit26cb3a20d8134d0aa7a7901478c9dcc2::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInitb4a7bd279920664bf19a780615ee880b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit26cb3a20d8134d0aa7a7901478c9dcc2::$classMap; $loader->classMap = ComposerStaticInitb4a7bd279920664bf19a780615ee880b::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

View File

@ -10,7 +10,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-installer/4c6e1ebecd1afce3f4ccc47e147d61bbe1bf641d.zip", "url": "https://files.phpcomposer.com/files/top-think/think-installer/4c6e1ebecd1afce3f4ccc47e147d61bbe1bf641d.zip",
"reference": "4c6e1ebecd1afce3f4ccc47e147d61bbe1bf641d", "reference": "4c6e1ebecd1afce3f4ccc47e147d61bbe1bf641d",
"shasum": "" "shasum": ""
}, },
@ -53,7 +53,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/ivanlanin/pclzip/19dd1de9d3f5fc4d7d70175b4c344dee329f45fd.zip", "url": "https://files.phpcomposer.com/files/ivanlanin/pclzip/19dd1de9d3f5fc4d7d70175b4c344dee329f45fd.zip",
"reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd", "reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd",
"shasum": "" "shasum": ""
}, },
@ -92,7 +92,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/zoujingli/wechat-php-sdk/12759d48867aab14e6b66be81a5b5afe223a0476.zip", "url": "https://files.phpcomposer.com/files/zoujingli/wechat-php-sdk/12759d48867aab14e6b66be81a5b5afe223a0476.zip",
"reference": "12759d48867aab14e6b66be81a5b5afe223a0476", "reference": "12759d48867aab14e6b66be81a5b5afe223a0476",
"shasum": "" "shasum": ""
}, },
@ -128,7 +128,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/qiniu/php-sdk/b91653485e36b4797d7a302cc86c49695e47a642.zip", "url": "https://files.phpcomposer.com/files/qiniu/php-sdk/b91653485e36b4797d7a302cc86c49695e47a642.zip",
"reference": "b91653485e36b4797d7a302cc86c49695e47a642", "reference": "b91653485e36b4797d7a302cc86c49695e47a642",
"shasum": "" "shasum": ""
}, },
@ -172,17 +172,17 @@
}, },
{ {
"name": "topthink/framework", "name": "topthink/framework",
"version": "v5.0.6", "version": "v5.0.7",
"version_normalized": "5.0.6.0", "version_normalized": "5.0.7.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/framework.git", "url": "https://github.com/top-think/framework.git",
"reference": "a3a37e6cfad132d5b02ffff8f23a4abc565f7928" "reference": "bcf64f19f4fadbff6c8503891689ff7e6f2fe9a3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/framework/a3a37e6cfad132d5b02ffff8f23a4abc565f7928.zip", "url": "https://files.phpcomposer.com/files/top-think/framework/bcf64f19f4fadbff6c8503891689ff7e6f2fe9a3.zip",
"reference": "a3a37e6cfad132d5b02ffff8f23a4abc565f7928", "reference": "bcf64f19f4fadbff6c8503891689ff7e6f2fe9a3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -197,7 +197,7 @@
"phpunit/phpunit": "4.8.*", "phpunit/phpunit": "4.8.*",
"sebastian/phpcpd": "2.*" "sebastian/phpcpd": "2.*"
}, },
"time": "2017-02-07 09:39:59", "time": "2017-02-25 02:51:57",
"type": "think-framework", "type": "think-framework",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
@ -234,7 +234,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-captcha/0c55455df26a1626a60d0dc35d2d89002b741d44.zip", "url": "https://files.phpcomposer.com/files/top-think/think-captcha/0c55455df26a1626a60d0dc35d2d89002b741d44.zip",
"reference": "0c55455df26a1626a60d0dc35d2d89002b741d44", "reference": "0c55455df26a1626a60d0dc35d2d89002b741d44",
"shasum": "" "shasum": ""
}, },
@ -263,20 +263,20 @@
}, },
{ {
"name": "topthink/think-mongo", "name": "topthink/think-mongo",
"version": "v1.5", "version": "v1.6",
"version_normalized": "1.5.0.0", "version_normalized": "1.6.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/think-mongo.git", "url": "https://github.com/top-think/think-mongo.git",
"reference": "2dd7ecae965cd3a6e5cc99f3db7c63353dae4cf3" "reference": "1c6d29f58bd7caa8da088c167b4e65ddac621588"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-mongo/2dd7ecae965cd3a6e5cc99f3db7c63353dae4cf3.zip", "url": "https://files.phpcomposer.com/files/top-think/think-mongo/1c6d29f58bd7caa8da088c167b4e65ddac621588.zip",
"reference": "2dd7ecae965cd3a6e5cc99f3db7c63353dae4cf3", "reference": "1c6d29f58bd7caa8da088c167b4e65ddac621588",
"shasum": "" "shasum": ""
}, },
"time": "2017-02-06 06:05:55", "time": "2017-02-13 07:17:51",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
@ -308,7 +308,7 @@
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-helper/ed64408cdc4cdbd390365ba0906d208b987af520.zip", "url": "https://files.phpcomposer.com/files/top-think/think-helper/ed64408cdc4cdbd390365ba0906d208b987af520.zip",
"reference": "ed64408cdc4cdbd390365ba0906d208b987af520", "reference": "ed64408cdc4cdbd390365ba0906d208b987af520",
"shasum": "" "shasum": ""
}, },
@ -337,24 +337,24 @@
}, },
{ {
"name": "topthink/think-queue", "name": "topthink/think-queue",
"version": "v1.1.2", "version": "v1.1.3",
"version_normalized": "1.1.2.0", "version_normalized": "1.1.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/top-think/think-queue.git", "url": "https://github.com/top-think/think-queue.git",
"reference": "503c5b809585ca60cba9485a233aa8be4b22c990" "reference": "07480c36381344bef9db9c9bbe3de28005a839d3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://packagist.phpcomposer.com/files/top-think/think-queue/503c5b809585ca60cba9485a233aa8be4b22c990.zip", "url": "https://files.phpcomposer.com/files/top-think/think-queue/07480c36381344bef9db9c9bbe3de28005a839d3.zip",
"reference": "503c5b809585ca60cba9485a233aa8be4b22c990", "reference": "07480c36381344bef9db9c9bbe3de28005a839d3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"topthink/think-helper": ">=1.0.4", "topthink/think-helper": ">=1.0.4",
"topthink/think-installer": ">=1.0.10" "topthink/think-installer": ">=1.0.10"
}, },
"time": "2016-12-01 04:29:39", "time": "2017-02-28 08:07:37",
"type": "think-extend", "type": "think-extend",
"extra": { "extra": {
"think-config": { "think-config": {

View File

@ -28,7 +28,7 @@ class Builder
// 最后插入ID // 最后插入ID
protected $insertId = []; protected $insertId = [];
// 查询表达式 // 查询表达式
protected $exp = ['<>' => 'ne', 'neq' => 'ne', '=' => 'eq', '>' => 'gt', '>=' => 'gte', '<' => 'lt', '<=' => 'lte', 'in' => 'in', 'not in' => 'nin', 'nin' => 'nin', 'mod' => 'mod', 'exists' => 'exists', 'null' => 'null', 'notnull' => 'not null', 'not null' => 'not null', 'regex' => 'regex', 'type' => 'type', 'all' => 'all', '> time' => '> time', '< time' => '< time', 'between' => 'between', 'not between' => 'not between', 'between time' => 'between time', 'not between time' => 'not between time', 'notbetween time' => 'not between time', 'like' => 'like', 'near' => 'near']; protected $exp = ['<>' => 'ne', 'neq' => 'ne', '=' => 'eq', '>' => 'gt', '>=' => 'gte', '<' => 'lt', '<=' => 'lte', 'in' => 'in', 'not in' => 'nin', 'nin' => 'nin', 'mod' => 'mod', 'exists' => 'exists', 'null' => 'null', 'notnull' => 'not null', 'not null' => 'not null', 'regex' => 'regex', 'type' => 'type', 'all' => 'all', '> time' => '> time', '< time' => '< time', 'between' => 'between', 'not between' => 'not between', 'between time' => 'between time', 'not between time' => 'not between time', 'notbetween time' => 'not between time', 'like' => 'like', 'near' => 'near', 'size' => 'size'];
/** /**
* 架构函数 * 架构函数
@ -50,8 +50,8 @@ class Builder
*/ */
protected function parseKey($key) protected function parseKey($key)
{ {
if (strpos($key, '.')) { if (0 === strpos($key, '__TABLE__.')) {
list($collection, $key) = explode('.', $key); list($collection, $key) = explode('.', $key, 2);
} }
if ('id' == $key && $this->connection->getConfig('pk_convert_id')) { if ('id' == $key && $this->connection->getConfig('pk_convert_id')) {
$key = '_id'; $key = '_id';
@ -68,7 +68,7 @@ class Builder
*/ */
protected function parseValue($value, $field = '') protected function parseValue($value, $field = '')
{ {
if ('_id' == $field && !($value instanceof ObjectID)) { if ('_id' == $field && 'ObjectID' == $this->connection->getConfig('pk_type') && is_string($value)) {
return new ObjectID($value); return new ObjectID($value);
} }
return $value; return $value;
@ -268,6 +268,9 @@ class Builder
} elseif ('near' == $exp) { } elseif ('near' == $exp) {
// 经纬度查询 // 经纬度查询
$query[$key] = ['$near' => $this->parseValue($value, $key)]; $query[$key] = ['$near' => $this->parseValue($value, $key)];
} elseif ('size' == $exp) {
// 元素长度查询
$query[$key] = ['$size' => intval($value)];
} else { } else {
// 普通查询 // 普通查询
$query[$key] = $this->parseValue($value, $key); $query[$key] = $this->parseValue($value, $key);
@ -426,6 +429,36 @@ class Builder
return $command; return $command;
} }
/**
* 聚合查询命令
* @access public
* @param array $options 参数
* @param array $extra 指令和字段
* @return Command
*/
public function aggregate($options, $extra)
{
list($fun, $field) = $extra;
$pipeline = [
['$match' => (object) $this->parseWhere($options['where'])],
['$group' => ['_id' => null, 'aggregate' => ['$' . $fun => '$' . $field]]],
];
$cmd = [
'aggregate' => $options['table'],
'allowDiskUse' => true,
'pipeline' => $pipeline,
];
foreach (['explain', 'collation', 'bypassDocumentValidation', 'readConcern'] as $option) {
if (isset($options[$option])) {
$cmd[$option] = $options[$option];
}
}
$command = new Command($cmd);
$this->log('aggregate', $cmd);
return $command;
}
/** /**
* 生成distinct命令 * 生成distinct命令
* @access public * @access public

View File

@ -61,51 +61,55 @@ class Connection
// 数据库连接参数配置 // 数据库连接参数配置
protected $config = [ protected $config = [
// 数据库类型 // 数据库类型
'type' => '', 'type' => '',
// 服务器地址 // 服务器地址
'hostname' => '', 'hostname' => '',
// 数据库名 // 数据库名
'database' => '', 'database' => '',
// 用户名 // 用户名
'username' => '', 'username' => '',
// 密码 // 密码
'password' => '', 'password' => '',
// 端口 // 端口
'hostport' => '', 'hostport' => '',
// 连接dsn // 连接dsn
'dsn' => '', 'dsn' => '',
// 数据库连接参数 // 数据库连接参数
'params' => [], 'params' => [],
// 数据库编码默认采用utf8 // 数据库编码默认采用utf8
'charset' => 'utf8', 'charset' => 'utf8',
// 主键名 // 主键名
'pk' => '_id', 'pk' => '_id',
// 主键类型
'pk_type' => 'ObjectID',
// 数据库表前缀 // 数据库表前缀
'prefix' => '', 'prefix' => '',
// 数据库调试模式 // 数据库调试模式
'debug' => false, 'debug' => false,
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0, 'deploy' => 0,
// 数据库读写是否分离 主从式有效 // 数据库读写是否分离 主从式有效
'rw_separate' => false, 'rw_separate' => false,
// 读写分离后 主服务器数量 // 读写分离后 主服务器数量
'master_num' => 1, 'master_num' => 1,
// 指定从服务器序号 // 指定从服务器序号
'slave_no' => '', 'slave_no' => '',
// 是否严格检查字段是否存在 // 是否严格检查字段是否存在
'fields_strict' => true, 'fields_strict' => true,
// 数据集返回类型 // 数据集返回类型
'resultset_type' => 'array', 'resultset_type' => 'array',
// 自动写入时间戳字段 // 自动写入时间戳字段
'auto_timestamp' => false, 'auto_timestamp' => false,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 是否需要进行SQL性能分析 // 是否需要进行SQL性能分析
'sql_explain' => false, 'sql_explain' => false,
// 是否_id转换为id // 是否_id转换为id
'pk_convert_id' => false, 'pk_convert_id' => false,
// typeMap // typeMap
'type_map' => ['root' => 'array', 'document' => 'array'], 'type_map' => ['root' => 'array', 'document' => 'array'],
// Query对象 // Query对象
'query' => '\\think\\mongo\\Query', 'query' => '\\think\\mongo\\Query',
]; ];
/** /**
@ -292,7 +296,7 @@ class Connection
$this->debug(true); $this->debug(true);
$dbName = $dbName ?: $this->dbName; $dbName = $dbName ?: $this->dbName;
if ($this->config['debug'] && !empty($this->queryStr)) { if ($this->config['debug'] && !empty($this->queryStr)) {
$this->queryStr = 'db.' . $dbName . '.' . $this->queryStr; $this->queryStr = 'db.' . $this->queryStr;
} }
$this->cursor = $this->mongo->executeCommand($dbName, $command, $readPreference); $this->cursor = $this->mongo->executeCommand($dbName, $command, $readPreference);
$this->debug(false); $this->debug(false);
@ -399,6 +403,9 @@ class Connection
}); });
} }
switch (strtolower($type)) { switch (strtolower($type)) {
case 'aggregate':
$this->queryStr = 'runCommand(' . ($data ? json_encode($data) : '') . ');';
break;
case 'find': case 'find':
$this->queryStr = $type . '(' . ($data ? json_encode($data) : '') . ')'; $this->queryStr = $type . '(' . ($data ? json_encode($data) : '') . ')';
if (isset($options['sort'])) { if (isset($options['sort'])) {

View File

@ -491,6 +491,63 @@ class Query
return $result[0]['n']; return $result[0]['n'];
} }
/**
* 聚合查询
* @access public
* @param string $aggregate 聚合指令
* @param string $field 字段名
* @return mixed
*/
public function aggregate($aggregate, $field)
{
$result = $this->cmd('aggregate', [$aggregate, $field]);
return isset($result[0]['result'][0]['aggregate']) ? $result[0]['result'][0]['aggregate'] : 0;
}
/**
* MAX查询
* @access public
* @param string $field 字段名
* @return float
*/
public function max($field)
{
return $this->aggregate('max', $field);
}
/**
* MIN查询
* @access public
* @param string $field 字段名
* @return mixed
*/
public function min($field)
{
return $this->aggregate('min', $field);
}
/**
* SUM查询
* @access public
* @param string $field 字段名
* @return float
*/
public function sum($field)
{
return $this->aggregate('sum', $field);
}
/**
* AVG查询
* @access public
* @param string $field 字段名
* @return float
*/
public function avg($field)
{
return $this->aggregate('avg', $field);
}
/** /**
* 设置记录的某个字段值 * 设置记录的某个字段值
* 支持使用数据库字段和方法 * 支持使用数据库字段和方法
@ -595,6 +652,55 @@ class Query
} }
} }
/**
* 设置数据
* @access public
* @param mixed $field 字段名或者数据
* @param mixed $value 字段值
* @return $this
*/
public function data($field, $value = null)
{
if (is_array($field)) {
$this->options['data'] = isset($this->options['data']) ? array_merge($this->options['data'], $field) : $field;
} else {
$this->options['data'][$field] = $value;
}
return $this;
}
/**
* 字段值增长
* @access public
* @param string|array $field 字段名
* @param integer $step 增长值
* @return $this
*/
public function inc($field, $step = 1)
{
$fields = is_string($field) ? explode(',', $field) : $field;
foreach ($fields as $field) {
$this->data($field, ['$inc', $step]);
}
return $this;
}
/**
* 字段值减少
* @access public
* @param string|array $field 字段名
* @param integer $step 减少值
* @return $this
*/
public function dec($field, $step = 1)
{
$fields = is_string($field) ? explode(',', $field) : $field;
foreach ($fields as $field) {
$this->data($field, ['$inc', -1 * $step]);
}
return $this;
}
/** /**
* 指定AND查询条件 * 指定AND查询条件
* @access public * @access public
@ -906,6 +1012,17 @@ class Query
return $this; return $this;
} }
/**
* 指定当前操作的collection
* @access public
* @param string $collection
* @return $this
*/
public function collection($collection)
{
return $this->table($collection);
}
/** /**
* 查询缓存 * 查询缓存
* @access public * @access public
@ -1082,6 +1199,18 @@ class Query
return $this; return $this;
} }
/**
* collation
* @access public
* @param array $collation
* @return $this
*/
public function collation($collation)
{
$this->options['collation'] = $collation;
return $this;
}
/** /**
* 设置返回字段 * 设置返回字段
* @access public * @access public

View File

@ -46,4 +46,4 @@ class Queue
{ {
return call_user_func_array([self::buildConnector(), $name], $arguments); return call_user_func_array([self::buildConnector(), $name], $arguments);
} }
} }

View File

@ -33,4 +33,4 @@ if (!function_exists('queue')) {
\think\Queue::push($job, $data, $queue); \think\Queue::push($job, $data, $queue);
} }
} }
} }

View File

@ -11,4 +11,4 @@
return [ return [
'connector' => 'Sync' 'connector' => 'Sync'
]; ];

View File

@ -25,12 +25,12 @@ class CallQueuedHandler
} }
} }
public function failed(array $data, $e) public function failed(array $data)
{ {
$command = unserialize($data['command']); $command = unserialize($data['command']);
if (method_exists($command, 'failed')) { if (method_exists($command, 'failed')) {
$command->failed($e); $command->failed();
} }
} }
} }

View File

@ -17,9 +17,9 @@ abstract class Connector
{ {
protected $options = []; protected $options = [];
abstract function push($job, $data = '', $queue = null); abstract public function push($job, $data = '', $queue = null);
abstract function later($delay, $job, $data = '', $queue = null); abstract public function later($delay, $job, $data = '', $queue = null);
abstract public function pop($queue = null); abstract public function pop($queue = null);
@ -66,4 +66,4 @@ abstract class Connector
return $payload; return $payload;
} }
} }

View File

@ -210,4 +210,4 @@ abstract class Job
{ {
return $this->queue; return $this->queue;
} }
} }

View File

@ -11,7 +11,6 @@
namespace think\queue; namespace think\queue;
use Closure; use Closure;
use think\Process; use think\Process;
@ -79,7 +78,6 @@ class Listener
$this->handleWorkerOutput($type, $line); $this->handleWorkerOutput($type, $line);
}); });
if ($this->memoryExceeded($memory)) { if ($this->memoryExceeded($memory)) {
$this->stop(); $this->stop();
} }
@ -163,4 +161,4 @@ class Listener
{ {
$this->maxTries = $tries; $this->maxTries = $tries;
} }
} }

View File

@ -43,4 +43,4 @@ trait Queueable
return $this; return $this;
} }
} }

View File

@ -14,4 +14,4 @@ namespace think\queue;
interface ShouldQueue interface ShouldQueue
{ {
} }

View File

@ -92,9 +92,13 @@ class Worker
*/ */
protected function logFailedJob(Job $job) protected function logFailedJob(Job $job)
{ {
if (Hook::listen('queue.failed', $job, null, true)) { if (!$job->isDeleted()) {
$job->delete(); try {
$job->failed(); $job->delete();
$job->failed();
} finally {
Hook::listen('queue.failed', $job);
}
} }
return ['job' => $job, 'failed' => true]; return ['job' => $job, 'failed' => true];
@ -110,4 +114,4 @@ class Worker
sleep($seconds); sleep($seconds);
} }
} }

View File

@ -11,7 +11,6 @@
namespace think\queue\command; namespace think\queue\command;
use think\console\Command; use think\console\Command;
use think\console\Input; use think\console\Input;
use think\console\input\Option; use think\console\input\Option;
@ -58,4 +57,4 @@ class Listen extends Command
$this->listener->listen($queue, $delay, $memory, $timeout); $this->listener->listen($queue, $delay, $memory, $timeout);
} }
} }

View File

@ -11,7 +11,6 @@
namespace think\queue\command; namespace think\queue\command;
use think\Cache; use think\Cache;
use think\console\Command; use think\console\Command;
use think\console\Input; use think\console\Input;
@ -29,4 +28,4 @@ class Restart extends Command
Cache::set('think:queue:restart', time()); Cache::set('think:queue:restart', time());
$output->writeln("<info>Broadcasting queue restart signal.</info>"); $output->writeln("<info>Broadcasting queue restart signal.</info>");
} }
} }

View File

@ -43,4 +43,4 @@ class Subscribe extends Command
$output->write('<info>Queue subscriber added:</info> <comment>' . $input->getArgument('url') . '</comment>'); $output->write('<info>Queue subscriber added:</info> <comment>' . $input->getArgument('url') . '</comment>');
} }
} }

View File

@ -199,4 +199,4 @@ class Work extends Command
die; die;
} }
} }

View File

@ -116,7 +116,7 @@ class Database extends Connector
->order('id', 'asc') ->order('id', 'asc')
->find(); ->find();
return $job ? (object)$job : null; return $job ? (object) $job : null;
} }
/** /**
@ -168,4 +168,4 @@ class Database extends Connector
{ {
return $queue ?: $this->options['default']; return $queue ?: $this->options['default'];
} }
} }

View File

@ -54,4 +54,4 @@ class Sync extends Connector
return new SyncJob($payload); return new SyncJob($payload);
} }
} }

View File

@ -170,7 +170,7 @@ class Topthink extends Connector
} }
} }
$this->reportHttpError($this->last_status, "Service unavailable"); $this->reportHttpError($this->last_status, "Service unavailable");
return null; return;
} }
protected static function jsonDecode($response) protected static function jsonDecode($response)
@ -210,7 +210,6 @@ class Topthink extends Connector
]; ];
} }
public function __destruct() public function __destruct()
{ {
if ($this->curl != null) { if ($this->curl != null) {
@ -223,4 +222,4 @@ class Topthink extends Connector
{ {
throw new \RuntimeException('pop queues not support for this type'); throw new \RuntimeException('pop queues not support for this type');
} }
} }

View File

@ -74,7 +74,7 @@ class Database extends Job
*/ */
public function attempts() public function attempts()
{ {
return (int)$this->job->attempts; return (int) $this->job->attempts;
} }
/** /**
@ -85,4 +85,4 @@ class Database extends Job
{ {
return $this->job->payload; return $this->job->payload;
} }
} }

View File

@ -11,14 +11,12 @@
namespace think\queue\job; namespace think\queue\job;
use think\queue\Job; use think\queue\Job;
use think\queue\connector\Redis as RedisQueue; use think\queue\connector\Redis as RedisQueue;
class Redis extends Job class Redis extends Job
{ {
/** /**
* The redis queue instance. * The redis queue instance.
* @var RedisQueue * @var RedisQueue
@ -65,7 +63,6 @@ class Redis extends Job
return $this->job; return $this->job;
} }
/** /**
* 删除任务 * 删除任务
* *
@ -92,4 +89,4 @@ class Redis extends Job
$this->redis->release($this->queue, $this->job, $delay, $this->attempts() + 1); $this->redis->release($this->queue, $this->job, $delay, $this->attempts() + 1);
} }
} }

View File

@ -11,7 +11,6 @@
namespace think\queue\job; namespace think\queue\job;
use think\queue\Job; use think\queue\Job;
class Sync extends Job class Sync extends Job
@ -54,4 +53,4 @@ class Sync extends Job
{ {
return $this->payload; return $this->payload;
} }
} }

View File

@ -11,7 +11,6 @@
namespace think\queue\job; namespace think\queue\job;
use think\queue\Job; use think\queue\Job;
use think\queue\connector\Topthink as TopthinkQueue; use think\queue\connector\Topthink as TopthinkQueue;
@ -55,7 +54,7 @@ class Topthink extends Job
*/ */
public function attempts() public function attempts()
{ {
return (int)$this->job->attempts; return (int) $this->job->attempts;
} }
public function delete() public function delete()
@ -83,4 +82,4 @@ class Topthink extends Job
return $this->job->payload; return $this->job->payload;
} }
} }