编辑器更新,此版本还有bug,暂不要更新使用
内核更新
This commit is contained in:
@@ -83,7 +83,9 @@ class Lang
|
||||
// 记录加载信息
|
||||
App::$debug && Log::record('[ LANG ] ' . $_file, 'info');
|
||||
$_lang = include $_file;
|
||||
$lang = array_change_key_case($_lang) + $lang;
|
||||
if (is_array($_lang)) {
|
||||
$lang = array_change_key_case($_lang) + $lang;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($lang)) {
|
||||
|
||||
@@ -680,15 +680,13 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
$where = $this->updateWhere;
|
||||
}
|
||||
|
||||
if (!empty($where)) {
|
||||
$pk = $this->getPk();
|
||||
if (is_string($pk) && isset($data[$pk])) {
|
||||
if (!isset($where[$pk])) {
|
||||
unset($where);
|
||||
$where[$pk] = $data[$pk];
|
||||
}
|
||||
unset($data[$pk]);
|
||||
$pk = $this->getPk();
|
||||
if (is_string($pk) && isset($data[$pk])) {
|
||||
if (!isset($where[$pk])) {
|
||||
unset($where);
|
||||
$where[$pk] = $data[$pk];
|
||||
}
|
||||
unset($data[$pk]);
|
||||
}
|
||||
|
||||
$result = $this->db()->where($where)->update($data);
|
||||
@@ -1146,8 +1144,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType'])
|
||||
->group('b.' . $info['foreignKey'])
|
||||
->having('count(' . $id . ')' . $operator . $count);
|
||||
case Relation::HAS_MANY_THROUGH:
|
||||
// TODO
|
||||
case Relation::HAS_MANY_THROUGH: // TODO
|
||||
default:
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1178,8 +1177,9 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
->field('a.*')
|
||||
->join($table . ' b', 'a.' . $info['localKey'] . '=b.' . $info['foreignKey'], $info['joinType'])
|
||||
->where($where);
|
||||
case Relation::HAS_MANY_THROUGH:
|
||||
// TODO
|
||||
case Relation::HAS_MANY_THROUGH: // TODO
|
||||
default:
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -305,7 +305,8 @@ class Route
|
||||
}
|
||||
$vars = self::parseVar($rule);
|
||||
if (isset($name)) {
|
||||
self::name($name, [$rule, $vars, self::$domain]);
|
||||
$key = $group ? $group . '/' . $rule : $rule;
|
||||
self::name($name, [$key, $vars, self::$domain]);
|
||||
}
|
||||
if ($group) {
|
||||
if ('*' != $type) {
|
||||
@@ -425,7 +426,7 @@ class Route
|
||||
$vars = self::parseVar($key);
|
||||
$item[] = ['rule' => $key, 'route' => $route, 'var' => $vars, 'option' => $options, 'pattern' => $patterns];
|
||||
// 设置路由标识
|
||||
self::name($route, [$key, $vars, self::$domain]);
|
||||
self::name($route, [$name . '/' . $key, $vars, self::$domain]);
|
||||
}
|
||||
self::$rules['*'][$name] = ['rule' => $item, 'route' => '', 'var' => [], 'option' => $option, 'pattern' => $pattern];
|
||||
}
|
||||
@@ -798,11 +799,9 @@ class Route
|
||||
public static function check($request, $url, $depr = '/', $checkDomain = false)
|
||||
{
|
||||
// 分隔符替换 确保路由定义使用统一的分隔符
|
||||
if ('/' != $depr) {
|
||||
$url = str_replace($depr, '/', $url);
|
||||
}
|
||||
$url = str_replace($depr, '|', $url);
|
||||
|
||||
if (strpos($url, '/') && isset(self::$rules['alias'][strstr($url, '/', true)])) {
|
||||
if (strpos($url, '|') && isset(self::$rules['alias'][strstr($url, '|', true)])) {
|
||||
// 检测路由别名
|
||||
$result = self::checkRouteAlias($request, $url, $depr);
|
||||
if (false !== $result) {
|
||||
@@ -821,8 +820,8 @@ class Route
|
||||
if (false !== $return) {
|
||||
return $return;
|
||||
}
|
||||
if ('/' != $url) {
|
||||
$url = rtrim($url, '/');
|
||||
if ('|' != $url) {
|
||||
$url = rtrim($url, '|');
|
||||
}
|
||||
if (isset($rules[$url])) {
|
||||
// 静态路由规则检测
|
||||
@@ -830,7 +829,7 @@ class Route
|
||||
if (true === $rule) {
|
||||
$rule = self::getRouteExpress($url);
|
||||
}
|
||||
if (!empty($rule['route']) && self::checkOption($rule['option'], $url, $request)) {
|
||||
if (!empty($rule['route']) && self::checkOption($rule['option'], $request)) {
|
||||
return self::parseRule($url, $rule['route'], $url, $rule['option']);
|
||||
}
|
||||
}
|
||||
@@ -874,7 +873,7 @@ class Route
|
||||
$pattern = $item['pattern'];
|
||||
|
||||
// 检查参数有效性
|
||||
if (!self::checkOption($option, $url, $request)) {
|
||||
if (!self::checkOption($option, $request)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -891,7 +890,7 @@ class Route
|
||||
} else {
|
||||
$str = $key;
|
||||
}
|
||||
if (is_string($str) && $str && 0 !== strpos($url, $str)) {
|
||||
if (is_string($str) && $str && 0 !== strpos(str_replace('|', '/', $url), $str)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -912,7 +911,7 @@ class Route
|
||||
if (isset($options['bind_model']) && isset($option['bind_model'])) {
|
||||
$option['bind_model'] = array_merge($options['bind_model'], $option['bind_model']);
|
||||
}
|
||||
$result = self::checkRule($rule, $route, $url, $pattern, $option);
|
||||
$result = self::checkRule($rule, $route, $url, $pattern, $option, $depr);
|
||||
if (false !== $result) {
|
||||
return $result;
|
||||
}
|
||||
@@ -938,27 +937,32 @@ class Route
|
||||
*/
|
||||
private static function checkRouteAlias($request, $url, $depr)
|
||||
{
|
||||
$array = explode('/', $url, 2);
|
||||
$item = self::$rules['alias'][$array[0]];
|
||||
$array = explode('|', $url);
|
||||
$alias = array_shift($array);
|
||||
$item = self::$rules['alias'][$alias];
|
||||
|
||||
if (is_array($item)) {
|
||||
list($rule, $option) = $item;
|
||||
if (isset($option['method'][$array[0]])) {
|
||||
$option['method'] = $option['method'][$array[0]];
|
||||
}
|
||||
} else {
|
||||
$rule = $item;
|
||||
}
|
||||
$bind = implode('|', $array);
|
||||
// 参数有效性检查
|
||||
if (isset($option) && !self::checkOption($option, $url, $request)) {
|
||||
if (isset($option) && !self::checkOption($option, $request)) {
|
||||
// 路由不匹配
|
||||
return false;
|
||||
} elseif (0 === strpos($rule, '\\')) {
|
||||
// 路由到类
|
||||
return self::bindToClass($array[1], substr($rule, 1), $depr);
|
||||
return self::bindToClass($bind, substr($rule, 1), $depr);
|
||||
} elseif (0 === strpos($url, '@')) {
|
||||
// 路由到控制器类
|
||||
return self::bindToController($array[1], substr($rule, 1), $depr);
|
||||
return self::bindToController($bind, substr($rule, 1), $depr);
|
||||
} else {
|
||||
// 路由到模块/控制器
|
||||
return self::bindToModule($array[1], $rule, $depr);
|
||||
return self::bindToModule($bind, $rule, $depr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1000,7 +1004,8 @@ class Route
|
||||
*/
|
||||
public static function bindToClass($url, $class, $depr = '/')
|
||||
{
|
||||
$array = explode($depr, $url, 2);
|
||||
$url = str_replace($depr, '|', $url);
|
||||
$array = explode('|', $url, 2);
|
||||
$action = !empty($array[0]) ? $array[0] : Config::get('default_action');
|
||||
if (!empty($array[1])) {
|
||||
self::parseUrlParams($array[1]);
|
||||
@@ -1018,7 +1023,8 @@ class Route
|
||||
*/
|
||||
public static function bindToNamespace($url, $namespace, $depr = '/')
|
||||
{
|
||||
$array = explode($depr, $url, 3);
|
||||
$url = str_replace($depr, '|', $url);
|
||||
$array = explode('|', $url, 3);
|
||||
$class = !empty($array[0]) ? $array[0] : Config::get('default_controller');
|
||||
$method = !empty($array[1]) ? $array[1] : Config::get('default_action');
|
||||
if (!empty($array[2])) {
|
||||
@@ -1037,7 +1043,8 @@ class Route
|
||||
*/
|
||||
public static function bindToController($url, $controller, $depr = '/')
|
||||
{
|
||||
$array = explode($depr, $url, 2);
|
||||
$url = str_replace($depr, '|', $url);
|
||||
$array = explode('|', $url, 2);
|
||||
$action = !empty($array[0]) ? $array[0] : Config::get('default_action');
|
||||
if (!empty($array[1])) {
|
||||
self::parseUrlParams($array[1]);
|
||||
@@ -1055,7 +1062,8 @@ class Route
|
||||
*/
|
||||
public static function bindToModule($url, $controller, $depr = '/')
|
||||
{
|
||||
$array = explode($depr, $url, 2);
|
||||
$url = str_replace($depr, '|', $url);
|
||||
$array = explode('|', $url, 2);
|
||||
$action = !empty($array[0]) ? $array[0] : Config::get('default_action');
|
||||
if (!empty($array[1])) {
|
||||
self::parseUrlParams($array[1]);
|
||||
@@ -1067,19 +1075,18 @@ class Route
|
||||
* 路由参数有效性检查
|
||||
* @access private
|
||||
* @param array $option 路由参数
|
||||
* @param string $url URL地址
|
||||
* @param Request $request Request对象
|
||||
* @return bool
|
||||
*/
|
||||
private static function checkOption($option, $url, $request)
|
||||
private static function checkOption($option, $request)
|
||||
{
|
||||
// 请求类型检测
|
||||
if ((isset($option['method']) && false === stripos($option['method'], $request->method()))
|
||||
if ((isset($option['method']) && is_string($option['method']) && false === stripos($option['method'], $request->method()))
|
||||
|| (isset($option['ext']) && false === stripos($option['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])) // 域名检测
|
||||
|| (!empty($option['https']) && !$request->isSsl()) // https检测
|
||||
|| (!empty($option['before_behavior']) && false === Hook::exec($option['before_behavior'], '', $url)) // 行为检测
|
||||
|| (!empty($option['before_behavior']) && false === Hook::exec($option['before_behavior'])) // 行为检测
|
||||
|| (!empty($option['callback']) && is_callable($option['callback']) && false === call_user_func($option['callback'])) // 自定义检测
|
||||
) {
|
||||
return false;
|
||||
@@ -1095,24 +1102,28 @@ class Route
|
||||
* @param string $url URL地址
|
||||
* @param array $pattern 变量规则
|
||||
* @param array $option 路由参数
|
||||
* @param string $depr URL分隔符(全局)
|
||||
* @return array|false
|
||||
*/
|
||||
private static function checkRule($rule, $route, $url, $pattern, $option)
|
||||
private static function checkRule($rule, $route, $url, $pattern, $option, $depr)
|
||||
{
|
||||
// 检查完整规则定义
|
||||
if (isset($pattern['__url__']) && !preg_match('/^' . $pattern['__url__'] . '/', $url)) {
|
||||
if (isset($pattern['__url__']) && !preg_match('/^' . $pattern['__url__'] . '/', str_replace('|', $depr, $url))) {
|
||||
return false;
|
||||
}
|
||||
// 检测是否设置了参数分隔符
|
||||
if ($depr = Config::get('url_params_depr')) {
|
||||
$url = str_replace($depr, '/', $url);
|
||||
$rule = str_replace($depr, '/', $rule);
|
||||
// 检查路由的参数分隔符
|
||||
if (isset($option['param_depr'])) {
|
||||
$url = str_replace(['|', $option['param_depr']], [$depr, '|'], $url);
|
||||
}
|
||||
|
||||
$len1 = substr_count($url, '/');
|
||||
$len1 = substr_count($url, '|');
|
||||
$len2 = substr_count($rule, '/');
|
||||
// 多余参数是否合并
|
||||
$merge = !empty($option['merge_extra_vars']) ? true : false;
|
||||
if ($merge && $len1 > $len2) {
|
||||
$url = str_replace('|', $depr, $url);
|
||||
$url = implode('|', explode($depr, $url, $len2 + 1));
|
||||
}
|
||||
|
||||
if ($len1 >= $len2 || strpos($rule, '[')) {
|
||||
if (!empty($option['complete_match'])) {
|
||||
@@ -1140,12 +1151,13 @@ class Route
|
||||
*/
|
||||
public static function parseUrl($url, $depr = '/', $autoSearch = false)
|
||||
{
|
||||
|
||||
if (isset(self::$bind['module'])) {
|
||||
// 如果有模块/控制器绑定
|
||||
$url = self::$bind['module'] . '/' . ltrim($url, '/');
|
||||
}
|
||||
|
||||
list($path, $var) = self::parseUrlPath($url, $depr);
|
||||
$url = str_replace($depr, '|', $url);
|
||||
list($path, $var) = self::parseUrlPath($url);
|
||||
$route = [null, null, null];
|
||||
if (isset($path)) {
|
||||
// 解析模块
|
||||
@@ -1171,7 +1183,7 @@ class Route
|
||||
// 解析操作
|
||||
$action = !empty($path) ? array_shift($path) : null;
|
||||
// 解析额外参数
|
||||
self::parseUrlParams(empty($path) ? '' : implode('/', $path));
|
||||
self::parseUrlParams(empty($path) ? '' : implode('|', $path));
|
||||
// 封装路由
|
||||
$route = [$module, $controller, $action];
|
||||
if (isset(self::$rules['name'][implode($depr, $route)])) {
|
||||
@@ -1185,15 +1197,12 @@ class Route
|
||||
* 解析URL的pathinfo参数和变量
|
||||
* @access private
|
||||
* @param string $url URL地址
|
||||
* @param string $depr URL分隔符
|
||||
* @return array
|
||||
*/
|
||||
private static function parseUrlPath($url, $depr = '/')
|
||||
private static function parseUrlPath($url)
|
||||
{
|
||||
// 分隔符替换 确保路由定义使用统一的分隔符
|
||||
if ('/' != $depr) {
|
||||
$url = str_replace($depr, '/', $url);
|
||||
}
|
||||
$url = str_replace('|', '/', $url);
|
||||
$url = trim($url, '/');
|
||||
$var = [];
|
||||
if (false !== strpos($url, '?')) {
|
||||
@@ -1219,13 +1228,12 @@ class Route
|
||||
* @param string $url URL地址
|
||||
* @param string $rule 路由规则
|
||||
* @param array $pattern 变量规则
|
||||
* @param bool $merge 合并额外变量
|
||||
* @return array|false
|
||||
*/
|
||||
private static function match($url, $rule, $pattern, $merge)
|
||||
private static function match($url, $rule, $pattern)
|
||||
{
|
||||
$m2 = explode('/', $rule);
|
||||
$m1 = $merge ? explode('/', $url, count($m2)) : explode('/', $url);
|
||||
$m1 = explode('|', $url);
|
||||
|
||||
$var = [];
|
||||
foreach ($m2 as $key => $val) {
|
||||
@@ -1290,17 +1298,16 @@ class Route
|
||||
* @param string $pathinfo URL地址
|
||||
* @param array $option 路由参数
|
||||
* @param array $matches 匹配的变量
|
||||
* @param bool $merge 合并额外变量
|
||||
* @return array
|
||||
*/
|
||||
private static function parseRule($rule, $route, $pathinfo, $option = [], $matches = [], $merge = false)
|
||||
private static function parseRule($rule, $route, $pathinfo, $option = [], $matches = [])
|
||||
{
|
||||
$request = Request::instance();
|
||||
// 解析路由规则
|
||||
if ($rule) {
|
||||
$rule = explode('/', $rule);
|
||||
// 获取URL地址中的参数
|
||||
$paths = $merge ? explode('/', $pathinfo, count($rule)) : explode('/', $pathinfo);
|
||||
$paths = explode('|', $pathinfo);
|
||||
foreach ($rule as $item) {
|
||||
$fun = '';
|
||||
if (0 === strpos($item, '[:')) {
|
||||
@@ -1315,7 +1322,7 @@ class Route
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$paths = explode('/', $pathinfo);
|
||||
$paths = explode('|', $pathinfo);
|
||||
}
|
||||
|
||||
// 获取路由地址规则
|
||||
@@ -1372,7 +1379,7 @@ class Route
|
||||
}
|
||||
|
||||
// 解析额外参数
|
||||
self::parseUrlParams(empty($paths) ? '' : implode('/', $paths), $matches);
|
||||
self::parseUrlParams(empty($paths) ? '' : implode('|', $paths), $matches);
|
||||
// 记录匹配的路由信息
|
||||
$request->routeInfo(['rule' => $rule, 'route' => $route, 'option' => $option, 'var' => $matches]);
|
||||
|
||||
@@ -1432,12 +1439,11 @@ class Route
|
||||
* 解析URL地址为 模块/控制器/操作
|
||||
* @access private
|
||||
* @param string $url URL地址
|
||||
* @param string $depr URL分隔符
|
||||
* @return array
|
||||
*/
|
||||
private static function parseModule($url, $depr = '/')
|
||||
private static function parseModule($url)
|
||||
{
|
||||
list($path, $var) = self::parseUrlPath($url, $depr);
|
||||
list($path, $var) = self::parseUrlPath($url);
|
||||
$action = array_pop($path);
|
||||
$controller = !empty($path) ? array_pop($path) : null;
|
||||
$module = Config::get('app_multi_module') && !empty($path) ? array_pop($path) : null;
|
||||
@@ -1463,9 +1469,9 @@ class Route
|
||||
{
|
||||
if ($url) {
|
||||
if (Config::get('url_param_type')) {
|
||||
$var += explode('/', $url);
|
||||
$var += explode('|', $url);
|
||||
} else {
|
||||
preg_replace_callback('/(\w+)\/([^\/]+)/', function ($match) use (&$var) {
|
||||
preg_replace_callback('/(\w+)\|([^\|]+)/', function ($match) use (&$var) {
|
||||
$var[$match[1]] = strip_tags($match[2]);
|
||||
}, $url);
|
||||
}
|
||||
|
||||
@@ -959,78 +959,66 @@ class Template
|
||||
* @param array $vars 变量数组
|
||||
* @return string
|
||||
*/
|
||||
public function parseThinkVar(&$vars)
|
||||
public function parseThinkVar($vars)
|
||||
{
|
||||
$vars[0] = strtoupper(trim($vars[0]));
|
||||
$parseStr = '';
|
||||
if (count($vars) >= 2) {
|
||||
$vars[1] = trim($vars[1]);
|
||||
switch ($vars[0]) {
|
||||
$type = strtoupper(trim(array_shift($vars)));
|
||||
$param = implode('.', $vars);
|
||||
if ($vars) {
|
||||
switch ($type) {
|
||||
case 'SERVER':
|
||||
$parseStr = '$_SERVER[\'' . strtoupper($vars[1]) . '\']';
|
||||
$parseStr = '\\think\\Request::instance()->server(\'' . $param . '\')';
|
||||
break;
|
||||
case 'GET':
|
||||
$parseStr = '$_GET[\'' . $vars[1] . '\']';
|
||||
$parseStr = '\\think\\Request::instance()->get(\'' . $param . '\')';
|
||||
break;
|
||||
case 'POST':
|
||||
$parseStr = '$_POST[\'' . $vars[1] . '\']';
|
||||
$parseStr = '\\think\\Request::instance()->post(\'' . $param . '\')';
|
||||
break;
|
||||
case 'COOKIE':
|
||||
if (isset($vars[2])) {
|
||||
$parseStr = '\\think\\Cookie::get(\'' . $vars[1] . '.' . $vars[2] . '\')';
|
||||
} else {
|
||||
$parseStr = '\\think\\Cookie::get(\'' . $vars[1] . '\')';
|
||||
}
|
||||
$parseStr = '\\think\\Cookie::get(\'' . $param . '\')';
|
||||
break;
|
||||
case 'SESSION':
|
||||
if (isset($vars[2])) {
|
||||
$parseStr = '\\think\\Session::get(\'' . $vars[1] . '.' . $vars[2] . '\')';
|
||||
} else {
|
||||
$parseStr = '\\think\\Session::get(\'' . $vars[1] . '\')';
|
||||
}
|
||||
$parseStr = '\\think\\Session::get(\'' . $param . '\')';
|
||||
break;
|
||||
case 'ENV':
|
||||
$parseStr = '$_ENV[\'' . strtoupper($vars[1]) . '\']';
|
||||
$parseStr = '\\think\\Request::instance()->env(\'' . $param . '\')';
|
||||
break;
|
||||
case 'REQUEST':
|
||||
$parseStr = '$_REQUEST[\'' . $vars[1] . '\']';
|
||||
$parseStr = '\\think\\Request::instance()->request(\'' . $param . '\')';
|
||||
break;
|
||||
case 'CONST':
|
||||
$parseStr = strtoupper($vars[1]);
|
||||
$parseStr = strtoupper($param);
|
||||
break;
|
||||
case 'LANG':
|
||||
$parseStr = '\\think\\Lang::get(\'' . $vars[1] . '\')';
|
||||
$parseStr = '\\think\\Lang::get(\'' . $param . '\')';
|
||||
break;
|
||||
case 'CONFIG':
|
||||
if (isset($vars[2])) {
|
||||
$vars[1] .= '.' . $vars[2];
|
||||
}
|
||||
$parseStr = '\\think\\Config::get(\'' . $vars[1] . '\')';
|
||||
$parseStr = '\\think\\Config::get(\'' . $param . '\')';
|
||||
break;
|
||||
default:
|
||||
$parseStr = '\'\'';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (count($vars) == 1) {
|
||||
switch ($vars[0]) {
|
||||
case 'NOW':
|
||||
$parseStr = "date('Y-m-d g:i a',time())";
|
||||
break;
|
||||
case 'VERSION':
|
||||
$parseStr = 'THINK_VERSION';
|
||||
break;
|
||||
case 'LDELIM':
|
||||
$parseStr = '\'' . ltrim($this->config['tpl_begin'], '\\') . '\'';
|
||||
break;
|
||||
case 'RDELIM':
|
||||
$parseStr = '\'' . ltrim($this->config['tpl_end'], '\\') . '\'';
|
||||
break;
|
||||
default:
|
||||
if (defined($vars[0])) {
|
||||
$parseStr = $vars[0];
|
||||
}
|
||||
}
|
||||
switch ($type) {
|
||||
case 'NOW':
|
||||
$parseStr = "date('Y-m-d g:i a',time())";
|
||||
break;
|
||||
case 'VERSION':
|
||||
$parseStr = 'THINK_VERSION';
|
||||
break;
|
||||
case 'LDELIM':
|
||||
$parseStr = '\'' . ltrim($this->config['tpl_begin'], '\\') . '\'';
|
||||
break;
|
||||
case 'RDELIM':
|
||||
$parseStr = '\'' . ltrim($this->config['tpl_end'], '\\') . '\'';
|
||||
break;
|
||||
default:
|
||||
if (defined($type)) {
|
||||
$parseStr = $type;
|
||||
} else {
|
||||
$parseStr = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $parseStr;
|
||||
|
||||
@@ -77,6 +77,8 @@ class Url
|
||||
if (!empty($rule) && $match = self::getRuleUrl($rule, $vars)) {
|
||||
// 匹配路由命名标识
|
||||
$url = $match[0];
|
||||
// 替换可选分隔符
|
||||
$url = preg_replace(['/\((\W)\?\)$/', '/\((\W)\?\)/'], ['', '\1'], $url);
|
||||
if (!empty($match[1])) {
|
||||
$domain = $match[1];
|
||||
}
|
||||
|
||||
@@ -180,12 +180,17 @@ abstract class Builder
|
||||
protected function parseTable($tables, $options = [])
|
||||
{
|
||||
$item = [];
|
||||
foreach ((array) $tables as $table) {
|
||||
$table = $this->parseSqlTable($table);
|
||||
if (isset($options['alias'][$table])) {
|
||||
$item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]);
|
||||
foreach ((array) $tables as $key => $table) {
|
||||
if (!is_numeric($key)) {
|
||||
$key = $this->parseSqlTable($key);
|
||||
$item[] = $this->parseKey($key) . ' ' . $this->parseKey($table);
|
||||
} else {
|
||||
$item[] = $this->parseKey($table);
|
||||
$table = $this->parseSqlTable($table);
|
||||
if (isset($options['alias'][$table])) {
|
||||
$item[] = $this->parseKey($table) . ' ' . $this->parseKey($options['alias'][$table]);
|
||||
} else {
|
||||
$item[] = $this->parseKey($table);
|
||||
}
|
||||
}
|
||||
}
|
||||
return implode(',', $item);
|
||||
@@ -437,8 +442,12 @@ abstract class Builder
|
||||
list($table, $type, $on) = $item;
|
||||
$condition = [];
|
||||
foreach ((array) $on as $val) {
|
||||
list($val1, $val2) = explode('=', $val, 2);
|
||||
$condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options);
|
||||
if (strpos($val, '=')) {
|
||||
list($val1, $val2) = explode('=', $val, 2);
|
||||
$condition[] = $this->parseKey($val1, $options) . '=' . $this->parseKey($val2, $options);
|
||||
} else {
|
||||
$condition[] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
$table = $this->parseTable($table, $options);
|
||||
|
||||
@@ -377,7 +377,7 @@ class Query
|
||||
*/
|
||||
public function value($field, $default = null)
|
||||
{
|
||||
$result = null;
|
||||
$result = false;
|
||||
if (!empty($this->options['cache'])) {
|
||||
// 判断查询缓存
|
||||
$cache = $this->options['cache'];
|
||||
@@ -387,7 +387,7 @@ class Query
|
||||
$key = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
|
||||
$result = Cache::get($key);
|
||||
}
|
||||
if (!$result) {
|
||||
if (false === $result) {
|
||||
if (isset($this->options['field'])) {
|
||||
unset($this->options['field']);
|
||||
}
|
||||
@@ -409,7 +409,7 @@ class Query
|
||||
// 清空查询条件
|
||||
$this->options = [];
|
||||
}
|
||||
return !is_null($result) ? $result : $default;
|
||||
return false !== $result ? $result : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,7 +431,7 @@ class Query
|
||||
$guid = is_string($cache['key']) ? $cache['key'] : md5($field . serialize($this->options));
|
||||
$result = Cache::get($guid);
|
||||
}
|
||||
if (!$result) {
|
||||
if (false === $result) {
|
||||
if (isset($this->options['field'])) {
|
||||
unset($this->options['field']);
|
||||
}
|
||||
@@ -663,37 +663,21 @@ class Query
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$prefix = $this->prefix;
|
||||
// 传入的表名为数组
|
||||
if (is_array($join)) {
|
||||
if (0 !== $key = key($join)) {
|
||||
// 设置了键名则键名为表名,键值作为表的别名
|
||||
$table = $key;
|
||||
$alias = array_shift($join);
|
||||
$this->alias([$table => $alias]);
|
||||
$table = [$key => array_shift($join)];
|
||||
$this->alias($table);
|
||||
} else {
|
||||
$table = array_shift($join);
|
||||
}
|
||||
if (count($join)) {
|
||||
// 有设置第二个元素则把第二元素作为表前缀
|
||||
$table = (string) current($join) . $table;
|
||||
} elseif (false === strpos($table, '.')) {
|
||||
// 加上默认的表前缀
|
||||
$table = $prefix . $table;
|
||||
}
|
||||
} else {
|
||||
$join = trim($join);
|
||||
if (0 === strpos($join, '__')) {
|
||||
$table = $this->parseSqlTable($join);
|
||||
} elseif (false === strpos($join, '(') && false === strpos($join, '.') && !empty($prefix) && 0 !== strpos($join, $prefix)) {
|
||||
// 传入的表名中不带有'('并且不以默认的表前缀开头时加上默认的表前缀
|
||||
$table = $prefix . $join;
|
||||
} else {
|
||||
$table = $join;
|
||||
}
|
||||
if (strpos($table, ' ')) {
|
||||
$table = trim($join);
|
||||
if (strpos($table, ' ') && !strpos($table, ')')) {
|
||||
list($table, $alias) = explode(' ', $table);
|
||||
$this->alias([$table => $alias]);
|
||||
$table = [$table => $alias];
|
||||
$this->alias($table);
|
||||
}
|
||||
}
|
||||
$this->options['join'][] = [$table, strtoupper($type), $condition];
|
||||
@@ -1044,7 +1028,8 @@ class Query
|
||||
}
|
||||
} elseif (strpos($table, ' ')) {
|
||||
list($table, $alias) = explode(' ', $table);
|
||||
$this->alias([$table => $alias]);
|
||||
$table = [$table => $alias];
|
||||
$this->alias($table);
|
||||
}
|
||||
} else {
|
||||
$tables = $table;
|
||||
@@ -1054,7 +1039,7 @@ class Query
|
||||
$table[] = $val;
|
||||
} else {
|
||||
$this->alias([$key => $val]);
|
||||
$table[] = $key;
|
||||
$table[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1187,7 +1172,11 @@ class Query
|
||||
$this->options['alias'][$key] = $val;
|
||||
}
|
||||
} else {
|
||||
$table = isset($this->options['table']) ? $this->options['table'] : $this->getTable();
|
||||
if (isset($this->options['table'])) {
|
||||
$table = is_array($this->options['table']) ? key($this->options['table']) : $this->options['table'];
|
||||
} else {
|
||||
$table = $this->getTable();
|
||||
}
|
||||
|
||||
$this->options['alias'][$table] = $alias;
|
||||
}
|
||||
@@ -1365,7 +1354,7 @@ class Query
|
||||
/**
|
||||
* 获取数据表信息
|
||||
* @access public
|
||||
* @param string $tableName 数据表名 留空自动获取
|
||||
* @param mixed $tableName 数据表名 留空自动获取
|
||||
* @param string $fetch 获取信息类型 包括 fields type bind pk
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -1575,7 +1564,7 @@ class Query
|
||||
$name = Loader::parseName(basename(str_replace('\\', '/', $currentModel)));
|
||||
$table = $this->getTable();
|
||||
$alias = isset($info['alias'][$name]) ? $info['alias'][$name] : $name;
|
||||
$this->table($table)->alias($alias);
|
||||
$this->table([$table => $alias]);
|
||||
if (isset($this->options['field'])) {
|
||||
$field = $this->options['field'];
|
||||
unset($this->options['field']);
|
||||
@@ -1587,7 +1576,7 @@ class Query
|
||||
// 预载入封装
|
||||
$joinTable = $model->getTable();
|
||||
$joinName = Loader::parseName(basename(str_replace('\\', '/', $info['model'])));
|
||||
$joinAlias = isset($info['alias'][$joinName]) ? $info['alias'][$joinName] : $joinName;
|
||||
$joinAlias = isset($info['alias'][$joinName]) ? $info['alias'][$joinName] : $relation;
|
||||
$this->via($joinAlias);
|
||||
|
||||
if (Relation::HAS_ONE == $info['type']) {
|
||||
@@ -1670,8 +1659,9 @@ class Query
|
||||
{
|
||||
$pk = $this->getPk($options);
|
||||
// 获取当前数据表
|
||||
if (!empty($options['alias'][$options['table']])) {
|
||||
$alias = $options['alias'][$options['table']];
|
||||
$table = is_array($options['table']) ? key($options['table']) : $options['table'];
|
||||
if (!empty($options['alias'][$table])) {
|
||||
$alias = $options['alias'][$table];
|
||||
}
|
||||
if (is_string($pk)) {
|
||||
$key = isset($alias) ? $alias . '.' . $pk : $pk;
|
||||
@@ -1983,7 +1973,7 @@ class Query
|
||||
// 判断查询缓存
|
||||
$cache = $options['cache'];
|
||||
if (true === $cache['key'] && !is_null($data) && !is_array($data)) {
|
||||
$key = 'think:' . $options['table'] . '|' . $data;
|
||||
$key = 'think:' . (is_array($options['table']) ? key($options['table']) : $options['table']) . '|' . $data;
|
||||
} else {
|
||||
$key = is_string($cache['key']) ? $cache['key'] : md5(serialize($options));
|
||||
}
|
||||
@@ -2053,7 +2043,8 @@ class Query
|
||||
if (!empty($this->model)) {
|
||||
throw new ModelNotFoundException('model data Not Found:' . $this->model, $this->model, $options);
|
||||
} else {
|
||||
throw new DataNotFoundException('table data not Found:' . $options['table'], $options['table'], $options);
|
||||
$table = is_array($options['table']) ? key($options['table']) : $options['table'];
|
||||
throw new DataNotFoundException('table data not Found:' . $table, $table, $options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2095,8 +2086,13 @@ class Query
|
||||
*/
|
||||
public function chunk($count, $callback, $column = null)
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
$column = $column ?: $this->getPk(isset($options['table']) ? $options['table'] : '');
|
||||
$options = $this->getOptions();
|
||||
if (isset($options['table'])) {
|
||||
$table = is_array($options['table']) ? key($options['table']) : $options['table'];
|
||||
} else {
|
||||
$table = '';
|
||||
}
|
||||
$column = $column ?: $this->getPk($table);
|
||||
$bind = $this->bind;
|
||||
$resultSet = $this->limit($count)->order($column, 'asc')->select();
|
||||
|
||||
|
||||
@@ -27,22 +27,23 @@ class Sqlsrv extends Builder
|
||||
* order分析
|
||||
* @access protected
|
||||
* @param mixed $order
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
protected function parseOrder($order)
|
||||
protected function parseOrder($order, $options = [])
|
||||
{
|
||||
if (is_array($order)) {
|
||||
$array = [];
|
||||
foreach ($order as $key => $val) {
|
||||
if (is_numeric($key)) {
|
||||
if (false === strpos($val, '(')) {
|
||||
$array[] = $this->parseKey($val);
|
||||
$array[] = $this->parseKey($val, $options);
|
||||
} elseif ('[rand]' == $val) {
|
||||
$array[] = $this->parseRand();
|
||||
}
|
||||
} else {
|
||||
$sort = in_array(strtolower(trim($val)), ['asc', 'desc']) ? ' ' . $val : '';
|
||||
$array[] = $this->parseKey($key) . ' ' . $sort;
|
||||
$array[] = $this->parseKey($key, $options) . ' ' . $sort;
|
||||
}
|
||||
}
|
||||
$order = implode(',', $array);
|
||||
|
||||
Reference in New Issue
Block a user