mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-24 02:13:59 +08:00
modified TP版本升级
This commit is contained in:
parent
62e16b52dc
commit
40eab59c39
@ -9,7 +9,7 @@
|
|||||||
// | Author: liu21st <liu21st@gmail.com>
|
// | Author: liu21st <liu21st@gmail.com>
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
define('THINK_VERSION', '5.0.14');
|
define('THINK_VERSION', '5.0.15');
|
||||||
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');
|
||||||
|
@ -192,7 +192,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
$con = Db::connect($connection);
|
$con = Db::connect($connection);
|
||||||
// 设置当前模型 确保查询返回模型对象
|
// 设置当前模型 确保查询返回模型对象
|
||||||
$queryClass = $this->query ?: $con->getConfig('query');
|
$queryClass = $this->query ?: $con->getConfig('query');
|
||||||
$query = new $queryClass($con, $this->class);
|
$query = new $queryClass($con, $this);
|
||||||
|
|
||||||
// 设置当前数据表和模型名
|
// 设置当前数据表和模型名
|
||||||
if (!empty($this->table)) {
|
if (!empty($this->table)) {
|
||||||
@ -208,6 +208,19 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建新的模型实例
|
||||||
|
* @access public
|
||||||
|
* @param array|object $data 数据
|
||||||
|
* @param bool $isUpdate 是否为更新
|
||||||
|
* @param mixed $where 更新条件
|
||||||
|
* @return Model
|
||||||
|
*/
|
||||||
|
public function newInstance($data = [], $isUpdate = false, $where = null)
|
||||||
|
{
|
||||||
|
return (new static($data))->isUpdate($isUpdate, $where);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前模型的查询对象
|
* 获取当前模型的查询对象
|
||||||
* @access public
|
* @access public
|
||||||
@ -599,7 +612,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
|||||||
*/
|
*/
|
||||||
protected function getRelationData(Relation $modelRelation)
|
protected function getRelationData(Relation $modelRelation)
|
||||||
{
|
{
|
||||||
if ($this->parent && get_class($this->parent) == $modelRelation->getModel()) {
|
if ($this->parent && !$modelRelation->isSelfRelation() && get_class($modelRelation->getModel()) == get_class($this->parent)) {
|
||||||
$value = $this->parent;
|
$value = $this->parent;
|
||||||
} else {
|
} else {
|
||||||
// 首先获取关联数据
|
// 首先获取关联数据
|
||||||
|
@ -692,10 +692,10 @@ class Request
|
|||||||
{
|
{
|
||||||
if (empty($this->post)) {
|
if (empty($this->post)) {
|
||||||
$content = $this->input;
|
$content = $this->input;
|
||||||
if(false !== strpos($this->contentType(), 'multipart/form-data')) {
|
if (empty($_POST) && false !== strpos($this->contentType(), 'application/json')) {
|
||||||
$this->post = $_POST;
|
|
||||||
} else {
|
|
||||||
$this->post = (array) json_decode($content, true);
|
$this->post = (array) json_decode($content, true);
|
||||||
|
} else {
|
||||||
|
$this->post = $_POST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (is_array($name)) {
|
if (is_array($name)) {
|
||||||
|
@ -222,7 +222,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 注册路由规则
|
* 注册路由规则
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param string $type 请求类型
|
* @param string $type 请求类型
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
@ -270,7 +270,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 设置路由规则
|
* 设置路由规则
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param string $type 请求类型
|
* @param string $type 请求类型
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
@ -487,7 +487,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 注册路由
|
* 注册路由
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
* @param array $pattern 变量规则
|
* @param array $pattern 变量规则
|
||||||
@ -501,7 +501,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 注册GET路由
|
* 注册GET路由
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
* @param array $pattern 变量规则
|
* @param array $pattern 变量规则
|
||||||
@ -515,7 +515,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 注册POST路由
|
* 注册POST路由
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
* @param array $pattern 变量规则
|
* @param array $pattern 变量规则
|
||||||
@ -529,7 +529,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 注册PUT路由
|
* 注册PUT路由
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
* @param array $pattern 变量规则
|
* @param array $pattern 变量规则
|
||||||
@ -543,7 +543,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 注册DELETE路由
|
* 注册DELETE路由
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
* @param array $pattern 变量规则
|
* @param array $pattern 变量规则
|
||||||
@ -557,7 +557,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 注册PATCH路由
|
* 注册PATCH路由
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
* @param array $pattern 变量规则
|
* @param array $pattern 变量规则
|
||||||
@ -571,7 +571,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* 注册资源路由
|
* 注册资源路由
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $rule 路由规则
|
* @param string|array $rule 路由规则
|
||||||
* @param string $route 路由地址
|
* @param string $route 路由地址
|
||||||
* @param array $option 路由参数
|
* @param array $option 路由参数
|
||||||
* @param array $pattern 变量规则
|
* @param array $pattern 变量规则
|
||||||
@ -667,7 +667,7 @@ class Route
|
|||||||
/**
|
/**
|
||||||
* rest方法定义和修改
|
* rest方法定义和修改
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $name 方法名称
|
* @param string|array $name 方法名称
|
||||||
* @param array|bool $resource 资源
|
* @param array|bool $resource 资源
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
@ -66,6 +66,8 @@ class Template
|
|||||||
{
|
{
|
||||||
$this->config['cache_path'] = TEMP_PATH;
|
$this->config['cache_path'] = TEMP_PATH;
|
||||||
$this->config = array_merge($this->config, $config);
|
$this->config = array_merge($this->config, $config);
|
||||||
|
$this->config['taglib_begin_origin'] = $this->config['taglib_begin'];
|
||||||
|
$this->config['taglib_end_origin'] = $this->config['taglib_end'];
|
||||||
$this->config['taglib_begin'] = $this->stripPreg($this->config['taglib_begin']);
|
$this->config['taglib_begin'] = $this->stripPreg($this->config['taglib_begin']);
|
||||||
$this->config['taglib_end'] = $this->stripPreg($this->config['taglib_end']);
|
$this->config['taglib_end'] = $this->stripPreg($this->config['taglib_end']);
|
||||||
$this->config['tpl_begin'] = $this->stripPreg($this->config['tpl_begin']);
|
$this->config['tpl_begin'] = $this->stripPreg($this->config['tpl_begin']);
|
||||||
|
@ -210,17 +210,21 @@ class Url
|
|||||||
}
|
}
|
||||||
$module = $module ? $module . '/' : '';
|
$module = $module ? $module . '/' : '';
|
||||||
|
|
||||||
$controller = Loader::parseName($request->controller());
|
$controller = $request->controller();
|
||||||
if ('' == $url) {
|
if ('' == $url) {
|
||||||
// 空字符串输出当前的 模块/控制器/操作
|
// 空字符串输出当前的 模块/控制器/操作
|
||||||
$url = $module . $controller . '/' . $request->action();
|
$action = $request->action();
|
||||||
} else {
|
} else {
|
||||||
$path = explode('/', $url);
|
$path = explode('/', $url);
|
||||||
$action = Config::get('url_convert') ? strtolower(array_pop($path)) : array_pop($path);
|
$action = array_pop($path);
|
||||||
$controller = empty($path) ? $controller : (Config::get('url_convert') ? Loader::parseName(array_pop($path)) : array_pop($path));
|
$controller = empty($path) ? $controller : array_pop($path);
|
||||||
$module = empty($path) ? $module : array_pop($path) . '/';
|
$module = empty($path) ? $module : array_pop($path) . '/';
|
||||||
$url = $module . $controller . '/' . $action;
|
|
||||||
}
|
}
|
||||||
|
if (Config::get('url_convert')) {
|
||||||
|
$action = strtolower($action);
|
||||||
|
$controller = Loader::parseName($controller);
|
||||||
|
}
|
||||||
|
$url = $module . $controller . '/' . $action;
|
||||||
}
|
}
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ class View
|
|||||||
try {
|
try {
|
||||||
$method = $renderContent ? 'display' : 'fetch';
|
$method = $renderContent ? 'display' : 'fetch';
|
||||||
// 允许用户自定义模板的字符串替换
|
// 允许用户自定义模板的字符串替换
|
||||||
$replace = array_merge($this->replace, $replace, $this->engine->config('tpl_replace_string'));
|
$replace = array_merge($this->replace, $replace, (array) $this->engine->config('tpl_replace_string'));
|
||||||
$this->engine->config('tpl_replace_string', $replace);
|
$this->engine->config('tpl_replace_string', $replace);
|
||||||
$this->engine->$method($template, $vars, $config);
|
$this->engine->$method($template, $vars, $config);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
22
thinkphp/library/think/cache/driver/File.php
vendored
22
thinkphp/library/think/cache/driver/File.php
vendored
@ -27,6 +27,8 @@ class File extends Driver
|
|||||||
'data_compress' => false,
|
'data_compress' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $expire;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造函数
|
* 构造函数
|
||||||
* @param array $options
|
* @param array $options
|
||||||
@ -62,9 +64,10 @@ class File extends Driver
|
|||||||
* 取得变量的存储文件名
|
* 取得变量的存储文件名
|
||||||
* @access protected
|
* @access protected
|
||||||
* @param string $name 缓存变量名
|
* @param string $name 缓存变量名
|
||||||
|
* @param bool $auto 是否自动创建目录
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getCacheKey($name)
|
protected function getCacheKey($name, $auto = false)
|
||||||
{
|
{
|
||||||
$name = md5($name);
|
$name = md5($name);
|
||||||
if ($this->options['cache_subdir']) {
|
if ($this->options['cache_subdir']) {
|
||||||
@ -76,7 +79,8 @@ class File extends Driver
|
|||||||
}
|
}
|
||||||
$filename = $this->options['path'] . $name . '.php';
|
$filename = $this->options['path'] . $name . '.php';
|
||||||
$dir = dirname($filename);
|
$dir = dirname($filename);
|
||||||
if (!is_dir($dir)) {
|
|
||||||
|
if ($auto && !is_dir($dir)) {
|
||||||
mkdir($dir, 0755, true);
|
mkdir($dir, 0755, true);
|
||||||
}
|
}
|
||||||
return $filename;
|
return $filename;
|
||||||
@ -107,11 +111,13 @@ class File extends Driver
|
|||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
$content = file_get_contents($filename);
|
$content = file_get_contents($filename);
|
||||||
|
$this->expire = null;
|
||||||
if (false !== $content) {
|
if (false !== $content) {
|
||||||
$expire = (int) substr($content, 8, 12);
|
$expire = (int) substr($content, 8, 12);
|
||||||
if (0 != $expire && time() > filemtime($filename) + $expire) {
|
if (0 != $expire && time() > filemtime($filename) + $expire) {
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
$this->expire = $expire;
|
||||||
$content = substr($content, 32);
|
$content = substr($content, 32);
|
||||||
if ($this->options['data_compress'] && function_exists('gzcompress')) {
|
if ($this->options['data_compress'] && function_exists('gzcompress')) {
|
||||||
//启用数据压缩
|
//启用数据压缩
|
||||||
@ -140,7 +146,7 @@ class File extends Driver
|
|||||||
if ($expire instanceof \DateTime) {
|
if ($expire instanceof \DateTime) {
|
||||||
$expire = $expire->getTimestamp() - time();
|
$expire = $expire->getTimestamp() - time();
|
||||||
}
|
}
|
||||||
$filename = $this->getCacheKey($name);
|
$filename = $this->getCacheKey($name, true);
|
||||||
if ($this->tag && !is_file($filename)) {
|
if ($this->tag && !is_file($filename)) {
|
||||||
$first = true;
|
$first = true;
|
||||||
}
|
}
|
||||||
@ -171,10 +177,13 @@ class File extends Driver
|
|||||||
{
|
{
|
||||||
if ($this->has($name)) {
|
if ($this->has($name)) {
|
||||||
$value = $this->get($name) + $step;
|
$value = $this->get($name) + $step;
|
||||||
|
$expire = $this->expire;
|
||||||
} else {
|
} else {
|
||||||
$value = $step;
|
$value = $step;
|
||||||
|
$expire = 0;
|
||||||
}
|
}
|
||||||
return $this->set($name, $value, 0) ? $value : false;
|
|
||||||
|
return $this->set($name, $value, $expire) ? $value : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,10 +197,13 @@ class File extends Driver
|
|||||||
{
|
{
|
||||||
if ($this->has($name)) {
|
if ($this->has($name)) {
|
||||||
$value = $this->get($name) - $step;
|
$value = $this->get($name) - $step;
|
||||||
|
$expire = $this->expire;
|
||||||
} else {
|
} else {
|
||||||
$value = -$step;
|
$value = -$step;
|
||||||
|
$expire = 0;
|
||||||
}
|
}
|
||||||
return $this->set($name, $value, 0) ? $value : false;
|
|
||||||
|
return $this->set($name, $value, $expire) ? $value : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +30,7 @@ class Config extends Command
|
|||||||
|
|
||||||
protected function execute(Input $input, Output $output)
|
protected function execute(Input $input, Output $output)
|
||||||
{
|
{
|
||||||
if ($input->hasArgument('module')) {
|
if ($input->getArgument('module')) {
|
||||||
$module = $input->getArgument('module') . DS;
|
$module = $input->getArgument('module') . DS;
|
||||||
} else {
|
} else {
|
||||||
$module = '';
|
$module = '';
|
||||||
|
@ -44,7 +44,8 @@ class Schema extends Command
|
|||||||
if ($input->hasOption('module')) {
|
if ($input->hasOption('module')) {
|
||||||
$module = $input->getOption('module');
|
$module = $input->getOption('module');
|
||||||
// 读取模型
|
// 读取模型
|
||||||
$list = scandir(APP_PATH . $module . DS . 'model');
|
$path = APP_PATH . $module . DS . 'model';
|
||||||
|
$list = is_dir($path) ? scandir($path) : [];
|
||||||
$app = App::$namespace;
|
$app = App::$namespace;
|
||||||
foreach ($list as $file) {
|
foreach ($list as $file) {
|
||||||
if (0 === strpos($file, '.')) {
|
if (0 === strpos($file, '.')) {
|
||||||
@ -66,7 +67,8 @@ class Schema extends Command
|
|||||||
$tables = Db::connect($config)->getTables($dbName);
|
$tables = Db::connect($config)->getTables($dbName);
|
||||||
} elseif (!\think\Config::get('app_multi_module')) {
|
} elseif (!\think\Config::get('app_multi_module')) {
|
||||||
$app = App::$namespace;
|
$app = App::$namespace;
|
||||||
$list = scandir(APP_PATH . 'model');
|
$path = APP_PATH . 'model';
|
||||||
|
$list = is_dir($path) ? scandir($path) : [];
|
||||||
foreach ($list as $file) {
|
foreach ($list as $file) {
|
||||||
if (0 === strpos($file, '.')) {
|
if (0 === strpos($file, '.')) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -26,7 +26,7 @@ abstract class Builder
|
|||||||
protected $exp = ['eq' => '=', 'neq' => '<>', 'gt' => '>', 'egt' => '>=', 'lt' => '<', 'elt' => '<=', 'notlike' => 'NOT LIKE', 'not like' => 'NOT LIKE', 'like' => 'LIKE', 'in' => 'IN', 'exp' => 'EXP', 'notin' => 'NOT IN', 'not in' => 'NOT IN', 'between' => 'BETWEEN', 'not between' => 'NOT BETWEEN', 'notbetween' => 'NOT BETWEEN', 'exists' => 'EXISTS', 'notexists' => 'NOT EXISTS', 'not exists' => 'NOT EXISTS', 'null' => 'NULL', 'notnull' => 'NOT NULL', 'not null' => 'NOT NULL', '> time' => '> TIME', '< time' => '< TIME', '>= time' => '>= TIME', '<= time' => '<= TIME', 'between time' => 'BETWEEN TIME', 'not between time' => 'NOT BETWEEN TIME', 'notbetween time' => 'NOT BETWEEN TIME'];
|
protected $exp = ['eq' => '=', 'neq' => '<>', 'gt' => '>', 'egt' => '>=', 'lt' => '<', 'elt' => '<=', 'notlike' => 'NOT LIKE', 'not like' => 'NOT LIKE', 'like' => 'LIKE', 'in' => 'IN', 'exp' => 'EXP', 'notin' => 'NOT IN', 'not in' => 'NOT IN', 'between' => 'BETWEEN', 'not between' => 'NOT BETWEEN', 'notbetween' => 'NOT BETWEEN', 'exists' => 'EXISTS', 'notexists' => 'NOT EXISTS', 'not exists' => 'NOT EXISTS', 'null' => 'NULL', 'notnull' => 'NOT NULL', 'not null' => 'NOT NULL', '> time' => '> TIME', '< time' => '< TIME', '>= time' => '>= TIME', '<= time' => '<= TIME', 'between time' => 'BETWEEN TIME', 'not between time' => 'NOT BETWEEN TIME', 'notbetween time' => 'NOT BETWEEN TIME'];
|
||||||
|
|
||||||
// SQL表达式
|
// SQL表达式
|
||||||
protected $selectSql = 'SELECT%DISTINCT% %FIELD% FROM %TABLE%%FORCE%%UNION%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%%LIMIT%%LOCK%%COMMENT%';
|
protected $selectSql = 'SELECT%DISTINCT% %FIELD% FROM %TABLE%%FORCE%%JOIN%%WHERE%%GROUP%%HAVING%%UNION%%ORDER%%LIMIT%%LOCK%%COMMENT%';
|
||||||
protected $insertSql = '%INSERT% INTO %TABLE% (%FIELD%) VALUES (%DATA%) %COMMENT%';
|
protected $insertSql = '%INSERT% INTO %TABLE% (%FIELD%) VALUES (%DATA%) %COMMENT%';
|
||||||
protected $insertAllSql = '%INSERT% INTO %TABLE% (%FIELD%) %DATA% %COMMENT%';
|
protected $insertAllSql = '%INSERT% INTO %TABLE% (%FIELD%) %DATA% %COMMENT%';
|
||||||
protected $updateSql = 'UPDATE %TABLE% SET %SET% %JOIN% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%';
|
protected $updateSql = 'UPDATE %TABLE% SET %SET% %JOIN% %WHERE% %ORDER%%LIMIT% %LOCK%%COMMENT%';
|
||||||
@ -207,9 +207,6 @@ abstract class Builder
|
|||||||
$item = [];
|
$item = [];
|
||||||
foreach ((array) $tables as $key => $table) {
|
foreach ((array) $tables as $key => $table) {
|
||||||
if (!is_numeric($key)) {
|
if (!is_numeric($key)) {
|
||||||
if (strpos($key, '@think')) {
|
|
||||||
$key = strstr($key, '@think', true);
|
|
||||||
}
|
|
||||||
$key = $this->parseSqlTable($key);
|
$key = $this->parseSqlTable($key);
|
||||||
$item[] = $this->parseKey($key) . ' ' . (isset($options['alias'][$table]) ? $this->parseKey($options['alias'][$table]) : $this->parseKey($table));
|
$item[] = $this->parseKey($key) . ' ' . (isset($options['alias'][$table]) ? $this->parseKey($options['alias'][$table]) : $this->parseKey($table));
|
||||||
} else {
|
} else {
|
||||||
|
@ -58,9 +58,9 @@ class Query
|
|||||||
* 构造函数
|
* 构造函数
|
||||||
* @access public
|
* @access public
|
||||||
* @param Connection $connection 数据库对象实例
|
* @param Connection $connection 数据库对象实例
|
||||||
* @param string $model 模型名
|
* @param Model $model 模型对象
|
||||||
*/
|
*/
|
||||||
public function __construct(Connection $connection = null, $model = '')
|
public function __construct(Connection $connection = null, $model = null)
|
||||||
{
|
{
|
||||||
$this->connection = $connection ?: Db::connect([], true);
|
$this->connection = $connection ?: Db::connect([], true);
|
||||||
$this->prefix = $this->connection->getConfig('prefix');
|
$this->prefix = $this->connection->getConfig('prefix');
|
||||||
@ -133,7 +133,7 @@ class Query
|
|||||||
/**
|
/**
|
||||||
* 获取当前的模型对象名
|
* 获取当前的模型对象名
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return Model|null
|
||||||
*/
|
*/
|
||||||
public function getModel()
|
public function getModel()
|
||||||
{
|
{
|
||||||
@ -707,8 +707,7 @@ class Query
|
|||||||
{
|
{
|
||||||
// 传入的表名为数组
|
// 传入的表名为数组
|
||||||
if (is_array($join)) {
|
if (is_array($join)) {
|
||||||
$table = key($join);
|
$table = $join;
|
||||||
$alias = current($join);
|
|
||||||
} else {
|
} else {
|
||||||
$join = trim($join);
|
$join = trim($join);
|
||||||
if (false !== strpos($join, '(')) {
|
if (false !== strpos($join, '(')) {
|
||||||
@ -729,16 +728,9 @@ class Query
|
|||||||
$table = $this->getTable($table);
|
$table = $this->getTable($table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (isset($alias) && $table != $alias) {
|
if (isset($alias) && $table != $alias) {
|
||||||
if (isset($this->options['alias'][$table])) {
|
|
||||||
$table = $table . '@think' . uniqid();
|
|
||||||
} elseif ($this->gettable() == $table) {
|
|
||||||
$table = $table . '@think' . uniqid();
|
|
||||||
}
|
|
||||||
|
|
||||||
$table = [$table => $alias];
|
$table = [$table => $alias];
|
||||||
$this->alias($table);
|
}
|
||||||
}
|
}
|
||||||
return $table;
|
return $table;
|
||||||
}
|
}
|
||||||
@ -1911,10 +1903,9 @@ class Query
|
|||||||
}
|
}
|
||||||
|
|
||||||
$first = true;
|
$first = true;
|
||||||
$currentModel = $this->model;
|
|
||||||
|
|
||||||
/** @var Model $class */
|
/** @var Model $class */
|
||||||
$class = new $currentModel;
|
$class = $this->model;
|
||||||
foreach ($with as $key => $relation) {
|
foreach ($with as $key => $relation) {
|
||||||
$subRelation = '';
|
$subRelation = '';
|
||||||
$closure = false;
|
$closure = false;
|
||||||
@ -1973,7 +1964,7 @@ class Query
|
|||||||
$relation = $key;
|
$relation = $key;
|
||||||
}
|
}
|
||||||
$relation = Loader::parseName($relation, 1, false);
|
$relation = Loader::parseName($relation, 1, false);
|
||||||
$count = '(' . (new $this->model)->$relation()->getRelationCountQuery($closure) . ')';
|
$count = '(' . $this->model->$relation()->getRelationCountQuery($closure) . ')';
|
||||||
$this->field([$count => Loader::parseName($relation) . '_count']);
|
$this->field([$count => Loader::parseName($relation) . '_count']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2365,11 +2356,10 @@ class Query
|
|||||||
// 数据列表读取后的处理
|
// 数据列表读取后的处理
|
||||||
if (!empty($this->model)) {
|
if (!empty($this->model)) {
|
||||||
// 生成模型对象
|
// 生成模型对象
|
||||||
$modelName = $this->model;
|
|
||||||
if (count($resultSet) > 0) {
|
if (count($resultSet) > 0) {
|
||||||
foreach ($resultSet as $key => $result) {
|
foreach ($resultSet as $key => $result) {
|
||||||
/** @var Model $model */
|
/** @var Model $model */
|
||||||
$model = new $modelName($result);
|
$model = $this->model->newInstance($result);
|
||||||
$model->isUpdate(true);
|
$model->isUpdate(true);
|
||||||
|
|
||||||
// 关联查询
|
// 关联查询
|
||||||
@ -2389,7 +2379,7 @@ class Query
|
|||||||
// 模型数据集转换
|
// 模型数据集转换
|
||||||
$resultSet = $model->toCollection($resultSet);
|
$resultSet = $model->toCollection($resultSet);
|
||||||
} else {
|
} else {
|
||||||
$resultSet = (new $modelName)->toCollection($resultSet);
|
$resultSet = $this->model->toCollection($resultSet);
|
||||||
}
|
}
|
||||||
} elseif ('collection' == $this->connection->getConfig('resultset_type')) {
|
} elseif ('collection' == $this->connection->getConfig('resultset_type')) {
|
||||||
// 返回Collection对象
|
// 返回Collection对象
|
||||||
@ -2515,7 +2505,7 @@ class Query
|
|||||||
$result = isset($resultSet[0]) ? $resultSet[0] : null;
|
$result = isset($resultSet[0]) ? $resultSet[0] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($cache) && false !== $result) {
|
if (isset($cache) && $result) {
|
||||||
// 缓存数据
|
// 缓存数据
|
||||||
$this->cacheData($key, $result, $cache);
|
$this->cacheData($key, $result, $cache);
|
||||||
}
|
}
|
||||||
@ -2525,8 +2515,7 @@ class Query
|
|||||||
if (!empty($result)) {
|
if (!empty($result)) {
|
||||||
if (!empty($this->model)) {
|
if (!empty($this->model)) {
|
||||||
// 返回模型对象
|
// 返回模型对象
|
||||||
$model = $this->model;
|
$result = $this->model->newInstance($result);
|
||||||
$result = new $model($result);
|
|
||||||
$result->isUpdate(true, isset($options['where']['AND']) ? $options['where']['AND'] : null);
|
$result->isUpdate(true, isset($options['where']['AND']) ? $options['where']['AND'] : null);
|
||||||
// 关联查询
|
// 关联查询
|
||||||
if (!empty($options['relation'])) {
|
if (!empty($options['relation'])) {
|
||||||
@ -2557,7 +2546,8 @@ class Query
|
|||||||
protected function throwNotFound($options = [])
|
protected function throwNotFound($options = [])
|
||||||
{
|
{
|
||||||
if (!empty($this->model)) {
|
if (!empty($this->model)) {
|
||||||
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
|
$class = get_class($this->model);
|
||||||
|
throw new ModelNotFoundException('model data Not Found:' . $class, $class, $options);
|
||||||
} else {
|
} else {
|
||||||
$table = is_array($options['table']) ? key($options['table']) : $options['table'];
|
$table = is_array($options['table']) ? key($options['table']) : $options['table'];
|
||||||
throw new DataNotFoundException('table data not Found:' . $table, $table, $options);
|
throw new DataNotFoundException('table data not Found:' . $table, $table, $options);
|
||||||
@ -2605,7 +2595,9 @@ class Query
|
|||||||
public function chunk($count, $callback, $column = null, $order = 'asc')
|
public function chunk($count, $callback, $column = null, $order = 'asc')
|
||||||
{
|
{
|
||||||
$options = $this->getOptions();
|
$options = $this->getOptions();
|
||||||
|
if (empty($options['table'])) {
|
||||||
|
$options['table'] = $this->getTable();
|
||||||
|
}
|
||||||
$column = $column ?: $this->getPk($options);
|
$column = $column ?: $this->getPk($options);
|
||||||
|
|
||||||
if (isset($options['order'])) {
|
if (isset($options['order'])) {
|
||||||
@ -2628,7 +2620,7 @@ class Query
|
|||||||
}
|
}
|
||||||
$resultSet = $query->order($column, $order)->select();
|
$resultSet = $query->order($column, $order)->select();
|
||||||
|
|
||||||
while (!empty($resultSet)) {
|
while (count($resultSet) > 0) {
|
||||||
if ($resultSet instanceof Collection) {
|
if ($resultSet instanceof Collection) {
|
||||||
$resultSet = $resultSet->all();
|
$resultSet = $resultSet->all();
|
||||||
}
|
}
|
||||||
@ -2649,8 +2641,8 @@ class Query
|
|||||||
}
|
}
|
||||||
|
|
||||||
$resultSet = $query->bind($bind)->order($column, $order)->select();
|
$resultSet = $query->bind($bind)->order($column, $order)->select();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,10 @@ class File
|
|||||||
{
|
{
|
||||||
//检测日志文件大小,超过配置大小则备份日志文件重新生成
|
//检测日志文件大小,超过配置大小则备份日志文件重新生成
|
||||||
if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) {
|
if (is_file($destination) && floor($this->config['file_size']) <= filesize($destination)) {
|
||||||
|
try {
|
||||||
rename($destination, dirname($destination) . DS . time() . '-' . basename($destination));
|
rename($destination, dirname($destination) . DS . time() . '-' . basename($destination));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
$this->writed[$destination] = false;
|
$this->writed[$destination] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ abstract class Relation
|
|||||||
protected $localKey;
|
protected $localKey;
|
||||||
// 基础查询
|
// 基础查询
|
||||||
protected $baseQuery;
|
protected $baseQuery;
|
||||||
|
// 是否为自关联
|
||||||
|
protected $selfRelation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取关联的所属模型
|
* 获取关联的所属模型
|
||||||
@ -49,11 +51,11 @@ abstract class Relation
|
|||||||
/**
|
/**
|
||||||
* 获取当前的关联模型类
|
* 获取当前的关联模型类
|
||||||
* @access public
|
* @access public
|
||||||
* @return string
|
* @return Model
|
||||||
*/
|
*/
|
||||||
public function getModel()
|
public function getModel()
|
||||||
{
|
{
|
||||||
return $this->model;
|
return $this->query->getModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,6 +68,28 @@ abstract class Relation
|
|||||||
return $this->query;
|
return $this->query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前关联为自关联
|
||||||
|
* @access public
|
||||||
|
* @param bool $self 是否自关联
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function selfRelation($self = true)
|
||||||
|
{
|
||||||
|
$this->selfRelation = $self;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前关联是否为自关联
|
||||||
|
* @access public
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isSelfRelation()
|
||||||
|
{
|
||||||
|
return $this->selfRelation;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 封装关联数据集
|
* 封装关联数据集
|
||||||
* @access public
|
* @access public
|
||||||
|
@ -43,6 +43,18 @@ class MorphTo extends Relation
|
|||||||
$this->relation = $relation;
|
$this->relation = $relation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前的关联模型类的实例
|
||||||
|
* @access public
|
||||||
|
* @return Model
|
||||||
|
*/
|
||||||
|
public function getModel()
|
||||||
|
{
|
||||||
|
$morphType = $this->morphType;
|
||||||
|
$model = $this->parseModel($this->parent->$morphType);
|
||||||
|
return (new $model);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 延迟获取关联数据
|
* 延迟获取关联数据
|
||||||
* @param string $subRelation 子关联名
|
* @param string $subRelation 子关联名
|
||||||
|
@ -57,18 +57,18 @@ abstract class OneToOne extends Relation
|
|||||||
*/
|
*/
|
||||||
public function eagerly(Query $query, $relation, $subRelation, $closure, $first)
|
public function eagerly(Query $query, $relation, $subRelation, $closure, $first)
|
||||||
{
|
{
|
||||||
$name = Loader::parseName(basename(str_replace('\\', '/', $query->getModel())));
|
$name = Loader::parseName(basename(str_replace('\\', '/', get_class($query->getModel()))));
|
||||||
$alias = $name;
|
|
||||||
if ($first) {
|
if ($first) {
|
||||||
$table = $query->getTable();
|
$table = $query->getTable();
|
||||||
$query->table([$table => $alias]);
|
$query->table([$table => $name]);
|
||||||
if ($query->getOptions('field')) {
|
if ($query->getOptions('field')) {
|
||||||
$field = $query->getOptions('field');
|
$field = $query->getOptions('field');
|
||||||
$query->removeOption('field');
|
$query->removeOption('field');
|
||||||
} else {
|
} else {
|
||||||
$field = true;
|
$field = true;
|
||||||
}
|
}
|
||||||
$query->field($field, false, $table, $alias);
|
$query->field($field, false, $table, $name);
|
||||||
$field = null;
|
$field = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,9 +78,9 @@ abstract class OneToOne extends Relation
|
|||||||
$query->via($joinAlias);
|
$query->via($joinAlias);
|
||||||
|
|
||||||
if ($this instanceof BelongsTo) {
|
if ($this instanceof BelongsTo) {
|
||||||
$query->join([$joinTable => $joinAlias], $alias . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey, $this->joinType);
|
$query->join([$joinTable => $joinAlias], $name . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey, $this->joinType);
|
||||||
} else {
|
} else {
|
||||||
$query->join([$joinTable => $joinAlias], $alias . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey, $this->joinType);
|
$query->join([$joinTable => $joinAlias], $name . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey, $this->joinType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($closure) {
|
if ($closure) {
|
||||||
|
@ -264,8 +264,8 @@ class TagLib
|
|||||||
if (!empty($this->tags[$name]['expression'])) {
|
if (!empty($this->tags[$name]['expression'])) {
|
||||||
static $_taglibs;
|
static $_taglibs;
|
||||||
if (!isset($_taglibs[$name])) {
|
if (!isset($_taglibs[$name])) {
|
||||||
$_taglibs[$name][0] = strlen(ltrim($this->tpl->config('taglib_begin'), '\\') . $name);
|
$_taglibs[$name][0] = strlen($this->tpl->config('taglib_begin_origin') . $name);
|
||||||
$_taglibs[$name][1] = strlen(ltrim($this->tpl->config('taglib_end'), '\\'));
|
$_taglibs[$name][1] = strlen($this->tpl->config('taglib_end_origin'));
|
||||||
}
|
}
|
||||||
$result['expression'] = substr($str, $_taglibs[$name][0], -$_taglibs[$name][1]);
|
$result['expression'] = substr($str, $_taglibs[$name][0], -$_taglibs[$name][1]);
|
||||||
// 清除自闭合标签尾部/
|
// 清除自闭合标签尾部/
|
||||||
|
@ -278,7 +278,7 @@ class Cx extends Taglib
|
|||||||
*/
|
*/
|
||||||
public function tagCase($tag, $content)
|
public function tagCase($tag, $content)
|
||||||
{
|
{
|
||||||
$value = !empty($tag['expression']) ? $tag['expression'] : $tag['value'];
|
$value = isset($tag['expression']) ? $tag['expression'] : $tag['value'];
|
||||||
$flag = substr($value, 0, 1);
|
$flag = substr($value, 0, 1);
|
||||||
if ('$' == $flag || ':' == $flag) {
|
if ('$' == $flag || ':' == $flag) {
|
||||||
$value = $this->autoBuildVar($value);
|
$value = $this->autoBuildVar($value);
|
||||||
|
@ -19,7 +19,10 @@ trait SoftDelete
|
|||||||
{
|
{
|
||||||
$field = $this->getDeleteTimeField();
|
$field = $this->getDeleteTimeField();
|
||||||
|
|
||||||
return !empty($this->data[$field]);
|
if ($field && !empty($this->data[$field])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,7 +45,11 @@ trait SoftDelete
|
|||||||
$model = new static();
|
$model = new static();
|
||||||
$field = $model->getDeleteTimeField(true);
|
$field = $model->getDeleteTimeField(true);
|
||||||
|
|
||||||
|
if ($field) {
|
||||||
return $model->getQuery()->useSoftDelete($field, ['not null', '']);
|
return $model->getQuery()->useSoftDelete($field, ['not null', '']);
|
||||||
|
} else {
|
||||||
|
return $model->getQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -58,7 +65,7 @@ trait SoftDelete
|
|||||||
}
|
}
|
||||||
|
|
||||||
$name = $this->getDeleteTimeField();
|
$name = $this->getDeleteTimeField();
|
||||||
if (!$force) {
|
if ($name && !$force) {
|
||||||
// 软删除
|
// 软删除
|
||||||
$this->data[$name] = $this->autoWriteTimestamp($name);
|
$this->data[$name] = $this->autoWriteTimestamp($name);
|
||||||
$result = $this->isUpdate()->save();
|
$result = $this->isUpdate()->save();
|
||||||
@ -139,11 +146,15 @@ trait SoftDelete
|
|||||||
|
|
||||||
$name = $this->getDeleteTimeField();
|
$name = $this->getDeleteTimeField();
|
||||||
|
|
||||||
|
if ($name) {
|
||||||
// 恢复删除
|
// 恢复删除
|
||||||
return $this->getQuery()
|
return $this->getQuery()
|
||||||
->useSoftDelete($name, ['not null', ''])
|
->useSoftDelete($name, ['not null', ''])
|
||||||
->where($where)
|
->where($where)
|
||||||
->update([$name => null]);
|
->update([$name => null]);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,7 +165,8 @@ trait SoftDelete
|
|||||||
*/
|
*/
|
||||||
protected function base($query)
|
protected function base($query)
|
||||||
{
|
{
|
||||||
return $query->useSoftDelete($this->getDeleteTimeField(true));
|
$field = $this->getDeleteTimeField(true);
|
||||||
|
return $field ? $query->useSoftDelete($field) : $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,6 +181,10 @@ trait SoftDelete
|
|||||||
$this->deleteTime :
|
$this->deleteTime :
|
||||||
'delete_time';
|
'delete_time';
|
||||||
|
|
||||||
|
if (false === $field) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!strpos($field, '.')) {
|
if (!strpos($field, '.')) {
|
||||||
$field = '__TABLE__.' . $field;
|
$field = '__TABLE__.' . $field;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user