From cabf5c4fdf8fd0ec920c7fb063a57fd7c3a38861 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 15 Jun 2016 15:45:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BConnection=E7=B1=BB=E7=9A=84g?= =?UTF-8?q?etResult=E6=96=B9=E6=B3=95=20=E6=94=B9=E8=BF=9BApp=E7=B1=BB?= =?UTF-8?q?=E7=9A=84run=E6=96=B9=E6=B3=95=E8=BF=94=E5=9B=9E=E5=80=BC=20Bui?= =?UTF-8?q?lder=E7=B1=BB=E7=9A=84parseValue=E6=96=B9=E6=B3=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0field=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/App.php | 4 ++-- library/think/Input.php | 2 +- library/think/db/Builder.php | 15 ++++++++------- library/think/db/Connection.php | 15 +++++---------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/library/think/App.php b/library/think/App.php index 0c710b51..ea833258 100644 --- a/library/think/App.php +++ b/library/think/App.php @@ -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); } } diff --git a/library/think/Input.php b/library/think/Input.php index 21953722..5a5a9291 100644 --- a/library/think/Input.php +++ b/library/think/Input.php @@ -245,7 +245,7 @@ class Input $item[$key] = $val; }else{ $item[$key] = new File($val['tmp_name'], $val); - } + } } return $item; } elseif (isset($array[$name])) { diff --git a/library/think/db/Builder.php b/library/think/db/Builder.php index 18a4e8bf..ab7d226c 100644 --- a/library/think/db/Builder.php +++ b/library/think/db/Builder.php @@ -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]); diff --git a/library/think/db/Connection.php b/library/think/db/Connection.php index f9ea922c..7884442a 100644 --- a/library/think/db/Connection.php +++ b/library/think/db/Connection.php @@ -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; }