mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42: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) {
|
||||
return $data;
|
||||
} elseif (!is_null($data)) {
|
||||
} else {
|
||||
// 默认自动识别响应输出类型
|
||||
$isAjax = $request->isAjax();
|
||||
$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;
|
||||
}else{
|
||||
$item[$key] = new File($val['tmp_name'], $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
} elseif (isset($array[$name])) {
|
||||
|
||||
@@ -130,17 +130,18 @@ abstract class Builder
|
||||
/**
|
||||
* value分析
|
||||
* @access protected
|
||||
* @param mixed $value
|
||||
* @param mixed $value
|
||||
* @param string $field
|
||||
* @return string|array
|
||||
*/
|
||||
protected function parseValue($value)
|
||||
protected function parseValue($value, $field = '')
|
||||
{
|
||||
if (is_string($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') {
|
||||
$value = $value[1];
|
||||
} elseif (is_array($value)) {
|
||||
$value = array_map([$this, 'parseValue'], $value);
|
||||
$value = array_map([$this, 'parseValue'], $value, $field);
|
||||
} elseif (is_bool($value)) {
|
||||
$value = $value ? '1' : '0';
|
||||
} elseif (is_null($value)) {
|
||||
@@ -311,7 +312,7 @@ abstract class Builder
|
||||
$whereStr = '';
|
||||
if (in_array($exp, ['=', '<>', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE'])) {
|
||||
// 比较运算 及 模糊匹配
|
||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value);
|
||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseValue($value, $field);
|
||||
} elseif ('EXP' == $exp) {
|
||||
// 表达式查询
|
||||
$whereStr .= '( ' . $key . ' ' . $value . ' )';
|
||||
@@ -324,13 +325,13 @@ abstract class Builder
|
||||
$whereStr .= $key . ' ' . $exp . ' ' . $this->parseClosure($value);
|
||||
} else {
|
||||
$value = is_array($value) ? $value : explode(',', $value);
|
||||
$zone = implode(',', $this->parseValue($value));
|
||||
$zone = implode(',', $this->parseValue($value, $field));
|
||||
$whereStr .= $key . ' ' . $exp . ' (' . $zone . ')';
|
||||
}
|
||||
} elseif (in_array($exp, ['NOT BETWEEN', 'BETWEEN'])) {
|
||||
// BETWEEN 查询
|
||||
$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'])) {
|
||||
// EXISTS 查询
|
||||
if ($value instanceof \Closure) {
|
||||
@@ -614,7 +615,7 @@ abstract class Builder
|
||||
}
|
||||
unset($data[$key]);
|
||||
} elseif (is_scalar($val)) {
|
||||
$data[$key] = $this->parseValue($val);
|
||||
$data[$key] = $this->parseValue($val, $key);
|
||||
} else {
|
||||
// 过滤掉非标量数据
|
||||
unset($data[$key]);
|
||||
|
||||
@@ -480,17 +480,12 @@ abstract class Connection
|
||||
|
||||
if (!empty($class)) {
|
||||
// 返回指定数据集对象类
|
||||
return new $class($result);
|
||||
}
|
||||
switch ($this->resultSetType) {
|
||||
case 'collection':
|
||||
// 返回数据集Collection对象
|
||||
$result = new Collection($result);
|
||||
break;
|
||||
case 'array':
|
||||
default:
|
||||
// 返回二维数组
|
||||
$result = new $class($result);
|
||||
} elseif ('collection' == $this->resultSetType){
|
||||
// 返回数据集Collection对象
|
||||
$result = new Collection($result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user