mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
改进Connection类的getResult方法 改进App类的run方法返回值 Builder类的parseValue方法增加field参数
This commit is contained in:
@@ -113,11 +113,11 @@ class App
|
|||||||
// 输出数据到客户端
|
// 输出数据到客户端
|
||||||
if ($data instanceof Response) {
|
if ($data instanceof Response) {
|
||||||
return $data;
|
return $data;
|
||||||
} elseif (!is_null($data)) {
|
} else {
|
||||||
// 默认自动识别响应输出类型
|
// 默认自动识别响应输出类型
|
||||||
$isAjax = $request->isAjax();
|
$isAjax = $request->isAjax();
|
||||||
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
$type = $isAjax ? Config::get('default_ajax_return') : Config::get('default_return_type');
|
||||||
return Response::create($data, $type);
|
return Response::create( is_null($data) ? '' : $data, $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -245,7 +245,7 @@ class Input
|
|||||||
$item[$key] = $val;
|
$item[$key] = $val;
|
||||||
}else{
|
}else{
|
||||||
$item[$key] = new File($val['tmp_name'], $val);
|
$item[$key] = new File($val['tmp_name'], $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $item;
|
return $item;
|
||||||
} elseif (isset($array[$name])) {
|
} elseif (isset($array[$name])) {
|
||||||
|
|||||||
@@ -130,17 +130,18 @@ abstract class Builder
|
|||||||
/**
|
/**
|
||||||
* value分析
|
* value分析
|
||||||
* @access protected
|
* @access protected
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
* @param string $field
|
||||||
* @return string|array
|
* @return string|array
|
||||||
*/
|
*/
|
||||||
protected function parseValue($value)
|
protected function parseValue($value, $field = '')
|
||||||
{
|
{
|
||||||
if (is_string($value)) {
|
if (is_string($value)) {
|
||||||
$value = strpos($value, ':') === 0 && $this->query->isBind(substr($value, 1)) ? $value : $this->connection->quote($value);
|
$value = strpos($value, ':') === 0 && $this->query->isBind(substr($value, 1)) ? $value : $this->connection->quote($value);
|
||||||
} elseif (is_array($value) && is_string($value[0]) && strtolower($value[0]) == 'exp') {
|
} elseif (is_array($value) && is_string($value[0]) && strtolower($value[0]) == 'exp') {
|
||||||
$value = $value[1];
|
$value = $value[1];
|
||||||
} elseif (is_array($value)) {
|
} elseif (is_array($value)) {
|
||||||
$value = array_map([$this, 'parseValue'], $value);
|
$value = array_map([$this, 'parseValue'], $value, $field);
|
||||||
} elseif (is_bool($value)) {
|
} elseif (is_bool($value)) {
|
||||||
$value = $value ? '1' : '0';
|
$value = $value ? '1' : '0';
|
||||||
} elseif (is_null($value)) {
|
} elseif (is_null($value)) {
|
||||||
@@ -311,7 +312,7 @@ abstract class Builder
|
|||||||
$whereStr = '';
|
$whereStr = '';
|
||||||
if (in_array($exp, ['=', '<>', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE'])) {
|
if (in_array($exp, ['=', '<>', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE'])) {
|
||||||
// 比较运算 及 模糊匹配
|
// 比较运算 及 模糊匹配
|
||||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value);
|
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value, $field);
|
||||||
} elseif ('EXP' == $exp) {
|
} elseif ('EXP' == $exp) {
|
||||||
// 表达式查询
|
// 表达式查询
|
||||||
$whereStr .= '( ' . $key . ' ' . $value . ' )';
|
$whereStr .= '( ' . $key . ' ' . $value . ' )';
|
||||||
@@ -324,13 +325,13 @@ abstract class Builder
|
|||||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value);
|
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value);
|
||||||
} else {
|
} else {
|
||||||
$value = is_array($value) ? $value : explode(',', $value);
|
$value = is_array($value) ? $value : explode(',', $value);
|
||||||
$zone = implode(',', $this->parseValue($value));
|
$zone = implode(',', $this->parseValue($value, $field));
|
||||||
$whereStr .= $key . ' ' . $exp . ' (' . $zone . ')';
|
$whereStr .= $key . ' ' . $exp . ' (' . $zone . ')';
|
||||||
}
|
}
|
||||||
} elseif (in_array($exp, ['NOT BETWEEN', 'BETWEEN'])) {
|
} elseif (in_array($exp, ['NOT BETWEEN', 'BETWEEN'])) {
|
||||||
// BETWEEN 查询
|
// BETWEEN 查询
|
||||||
$data = is_array($value) ? $value : explode(',', $value);
|
$data = is_array($value) ? $value : explode(',', $value);
|
||||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($data[0]) . ' AND ' . $this->parseValue($data[1]);
|
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($data[0], $field) . ' AND ' . $this->parseValue($data[1], $field);
|
||||||
} elseif (in_array($exp, ['NOT EXISTS', 'EXISTS'])) {
|
} elseif (in_array($exp, ['NOT EXISTS', 'EXISTS'])) {
|
||||||
// EXISTS 查询
|
// EXISTS 查询
|
||||||
if ($value instanceof \Closure) {
|
if ($value instanceof \Closure) {
|
||||||
@@ -614,7 +615,7 @@ abstract class Builder
|
|||||||
}
|
}
|
||||||
unset($data[$key]);
|
unset($data[$key]);
|
||||||
} elseif (is_scalar($val)) {
|
} elseif (is_scalar($val)) {
|
||||||
$data[$key] = $this->parseValue($val);
|
$data[$key] = $this->parseValue($val, $key);
|
||||||
} else {
|
} else {
|
||||||
// 过滤掉非标量数据
|
// 过滤掉非标量数据
|
||||||
unset($data[$key]);
|
unset($data[$key]);
|
||||||
|
|||||||
@@ -480,17 +480,12 @@ abstract class Connection
|
|||||||
|
|
||||||
if (!empty($class)) {
|
if (!empty($class)) {
|
||||||
// 返回指定数据集对象类
|
// 返回指定数据集对象类
|
||||||
return new $class($result);
|
$result = new $class($result);
|
||||||
}
|
} elseif ('collection' == $this->resultSetType){
|
||||||
switch ($this->resultSetType) {
|
// 返回数据集Collection对象
|
||||||
case 'collection':
|
$result = new Collection($result);
|
||||||
// 返回数据集Collection对象
|
|
||||||
$result = new Collection($result);
|
|
||||||
break;
|
|
||||||
case 'array':
|
|
||||||
default:
|
|
||||||
// 返回二维数组
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user